dbTalk Databases Forums  

IN vs EXISTS - which is better?

comp.databases.sybase comp.databases.sybase


Discuss IN vs EXISTS - which is better? in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Saul Margolis
 
Posts: n/a

Default IN vs EXISTS - which is better? - 11-18-2003 , 09:56 AM






My DBA has advised me that it is better to use the EXISTS statement
than the IN statement. He says that it uses less server resources or
is better handled by the optimiser.

Does anybody know if this is true?

Reply With Quote
  #2  
Old   
Daniel Morgan
 
Posts: n/a

Default Re: IN vs EXISTS - which is better? - 11-18-2003 , 12:31 PM






Saul Margolis wrote:

Quote:
My DBA has advised me that it is better to use the EXISTS statement
than the IN statement. He says that it uses less server resources or
is better handled by the optimiser.

Does anybody know if this is true?
Your DBA is quoting mythology as fact. As with everything in an RDBMS
.... it depends.

While one might say it is usually true ... it is not at all a
situation where one can say that it is always true.

Unless performance and scalability are not an issue it is always
best to write something both ways and test.
--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
http://www.outreach.washington.edu/e...oa/aoa_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)



Reply With Quote
  #3  
Old   
--CELKO--
 
Posts: n/a

Default Re: IN vs EXISTS - which is better? - 11-20-2003 , 08:33 PM



Quote:
Does anybody know if this is true?
It depends. Older versions of DB2 used to use indexes for EXISTS()
predicates and they were quite a bit faster than the IN() predicate
that mateiralized a temp table on the fly. Since a myth was born.
These days, a good optimizer will find the best way regardless of the
predicate. I'd say use the one which is easier to read, unless you
find a real difference by testing both.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.