I have this SQL query:
SELECT * FROM [table] WHERE 2=3;
Obviously, the query will return 0 rows, but my question is as follows. Does the SQL Server engine evaluate the where condition before executing the selection?
In other words, does SQL Server detect the where condition is impossible and return 0 rows automatically?
If you examine the execution plan for a simple query using such a predicate you will see that SQL Server uses a Constant Scan to determine that zero results will return. No indexes or tables are even touched.
SELECT * FROM [Production].[Product];
SELECT * FROM [Production].[Product] WHERE 1=0;

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