all groups > sql server programming > june 2006 >
You're in the

sql server programming

group:

WHERE clause optimization



Re: WHERE clause optimization Maxi
6/9/2006 5:27:07 PM
sql server programming: Hi, compare the Stimated planned into Query Analizer.
Using OR clausule is generaly most slowly in query :(

--

--------------------------
Salu2
Maxi [MVP SQL SERVER]
www.sqlgurus.org


"Sericinus hunter" <serhunt@flash.net> escribió en el mensaje
news:8Akig.145584$F_3.126501@newssvr29.news.prodigy.net...
[quoted text, click to view]

WHERE clause optimization Sericinus hunter
6/9/2006 8:09:40 PM
Consider the following WHERE clause:

...WHERE (Col = 1) OR (Col IN (SELECT OtherCol FROM OtherTable))

Would it be different performance-wise from the following:

...WHERE Col IN (SELECT 1 UNION SELECT OtherCol FROM OtherTable)


Re: WHERE clause optimization Erland Sommarskog
6/9/2006 10:32:25 PM
Sericinus hunter (serhunt@flash.net) writes:
[quoted text, click to view]

There is a chance that SQL Server will avoid the subquery if Col is 1,
if you use the former. In any case, being obscure is rarely a good
idea.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Re: WHERE clause optimization Sericinus hunter
6/10/2006 3:35:00 PM
[quoted text, click to view]

Thank you, Erland, that's what I originally thought too: engine
may not even get to the subquery at all.
AddThis Social Bookmark Button