all groups > sql server programming > august 2004 >
You're in the

sql server programming

group:

compare EXISTS with ANY


compare EXISTS with ANY Victor Feng
8/27/2004 10:21:03 PM
sql server programming: Which one should be used for the sake of speed if I have choice between
EXISTS and ANY? Why, if possible?

Thanks
Re: compare EXISTS with ANY Steve Kass
8/28/2004 2:52:33 AM
Victor,

My guess is that EXISTS will be faster, if there's any difference. I
know the optimizer is very good with EXISTS, and because ANY is not
widely-used, they might have done less work optimizing it. You could at
least generate the estimated execution plan for each (Ctrl-L in query
analyzer) and see how the query plans compare.

Steve Kass
Drew University

[quoted text, click to view]
Re: compare EXISTS with ANY Joe Celko
8/28/2004 8:45:34 AM
[quoted text, click to view]

EXISTS() is not the same as ANY in all situations. You can use any theta
(comparison) operator with ANY.

However, the EXISTS predicate can use PK-FK references, indexes and
other tricks to optimize the search for any match.

--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button