I have run these two queries that look like they do the same thing, but give different results:
SELECT COUNT(stage1) AS total
FROM progress_status
WHERE stage1 = 3
AND stage2 != 3 AND stage3 !=3 AND stage4 !=3 AND stage5 !=3;
# total = 90
SELECT COUNT(stage1) AS total
FROM progress_status
WHERE stage1 = 3
AND (stage2,stage3,stage4,stage5) != (3,3,3,3)
# total = 314
Either you are getting different performance because the system is under a different sort of load, you are getting different performance because of data volume changes, or you are getting different performance because you are getting different query plans.
The view is a query stored in the data dictionary, on which the user can query just like they do on tables. It does not use the physical memory, only the query is stored in the data dictionary. It is computed dynamically, whenever the user performs any query on it.
Comparing the Results of the Two Queries The solution to this is very simple. Run both queries using a UNION to combine the results! The UNION operator returns unique records. If the two results sets are identical the row count will remain the same as the original query.
Query performance also depends on data volume and transaction concurrency. Executing the same query on a table with millions of records requires more time that performing the same operation on the same table with only thousands of records.
The second one is doing:
AND (stage2 != 3 OR stage3 !=3 OR stage4 !=3 OR stage5 !=3);
It's normal:
OR
in your WHERE
clause.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With