SQL Server performance tip -


possible duplicate:
is sql clause short-circuit evaluated?

i have following question regarding query:

select * sometable  1=1 or (select count(*) table2 > 0) 

if first condition true (1=1), sql server still inner select? or stop when first condition true (like c)

it stops when (1=1) true. can check using ctrl-m ctrl-e

consider query

select * master..spt_values 1=1 or (select count(*) master..sysobjects) > 0 

the execution plan shows scan in master..spt_values , no activity in sysobjects.

contrary c, not stop when leftmost condition true, instead query optimizer works out independently of order presented least cost evaluate. in case of constants 1 vs 1 winner clear.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -