Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Short Circuit?

Status
Not open for further replies.

jararaca

Programmer
Jun 1, 2005
159
US
When you use an OR, will SQL Server evaluate the left part before it determines it is necessary to evaluate the right part? You know what I mean? For example:

a = 1 or b = 2

If a = 1, it's not necessary to evaluate the b = 2 part. Is SQL Server smart enough to figure this kind of thing out?

Thanks.
 
in case of OR condition...both the parts are evaluated....even if a=1 not true...b=2 will be checked..if that is true the whole condition becomes true...

-DNG
 
Imagine the following clause:

WHERE <expression1> OR <expression2>

If server takes table/clustered scan then yes, it will not evaluate ex2 if exp1 returns true. But what if server can optimize exp1 and exp2 separately and then UNION both results (internally)? Then Boolean short-circuit would become an "obstacle" in exec plan.

------
[small]select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')[/small]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top