SQL Server: multiple sentences
Suppose I have a T-SQL command with several WHERE
conditions like this:
SELECT *
FROM TableName
WHERE Column1 NOT LIKE '%exclude%'
AND Column2 > 10
Will the query exclude the row as soon as it Column1
fails, or will it continue to check the next condition for Column2
?
I ask because I want to see if it would be more efficient to change my conditions to check if Column2 > 10
first before I get a more time consuming condition working.
Edit: if it matters, Column1
is of type bigint
and Column2
is of typentext
source to share
Sql will develop a query plan based on the available indexes and statistics. Sql does not necessarily have the expression "short-circuit" per se, because it is a procedural language, but ultimately the query plan will evaluate the short-circuit.
Expression substitution should not affect performance.
source to share