IN or EXISTS?? faster one - Mailing list pgsql-general

From Prachi Jain
Subject IN or EXISTS?? faster one
Date
Msg-id 20021219130947.8489.qmail@webmail28.rediffmail.com
Whole thread Raw
Responses Re: IN or EXISTS?? faster one
Re: IN or EXISTS?? faster one
List pgsql-general
Hello All,

I am using too many subqueries in my queries. I have read some
FAQs that using EXISTS is faster than IN. Is that correct?? I
tried to get the total runtime using EXPLAIN ANALYZE, but i got
total runtime for the query with IN but not for the query with
EXISTS.

query with IN:

EXPLAIN ANALYZE Select * from bom where depot_id in ( SELECT
depot_id from depot where company_name ='SOME' );

query with EXISTS:
EXPLAIN ANALYZE  Select * from bom WHERE EXISTS ( SELECT depot_id
 from depot where company_name ='SOME' and depot.depot_id =
bom.depot_id );

I read the same for using with select count(*)...is too slow. How
to replace for that??

Moreover, what are the other things one should take care of
regarding reducing the time taken by the queries??

Thanks in advance.
Regards
Prachi



pgsql-general by date:

Previous
From: Lee Kindness
Date:
Subject: trouble caused by change in 7.3 handling of '' in integer context
Next
From: S Dawalt
Date:
Subject: Re: trouble caused by change in 7.3 handling of '' in