Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If the first condition is FALSE then the second condition is checked in SQL Server?

In a where clause, if the first condition is FALSE, then the second condition is checked in SQL Server?

For example

select * 
from users
where (condition 1) AND (condition 2)

If condition 1 is False, will condition 2 be checked?

like image 848
Morteza Jangjoo Avatar asked Mar 15 '20 08:03

Morteza Jangjoo


1 Answers

It is non-deterministic. You cannot rely on order of evaluation.

SQL Server query optimizer is responsible for parsing T-SQL query and creating execution plan based on table sizes, indexes, etc. So same T-SQL statement against same database schema might be executed differently depending on database content, configuration, etc.

Query optimizer prioritizes speed of execution and is able to parallelise execution of a single T-SQL statement. It is highly unlikely that execution of filter clauses ends up being executed one after another.

like image 100
Nenad Avatar answered Oct 03 '22 01:10

Nenad