Unix Technical Forum

IN vs EXISTS - which is better?

This is a discussion on IN vs EXISTS - which is better? within the Sybase forums, part of the Database Server Software category; --> My DBA has advised me that it is better to use the EXISTS statement than the IN statement. He ...


Go Back   Unix Technical Forum > Database Server Software > Sybase

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 04:05 PM
Saul Margolis
 
Posts: n/a
Default IN vs EXISTS - which is better?

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 04:05 PM
Daniel Morgan
 
Posts: n/a
Default Re: IN vs EXISTS - which is better?

Saul Margolis wrote:

> 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)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 04:06 PM
--CELKO--
 
Posts: n/a
Default Re: IN vs EXISTS - which is better?

>> 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:52 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com