Re: 3-table query optimization - Mailing list pgsql-performance

From Alvaro Herrera
Subject Re: 3-table query optimization
Date
Msg-id 20060810155017.GI23053@alvh.no-ip.org
Whole thread Raw
In response to Re: 3-table query optimization  (Michal Taborsky - Internet Mall <michal.taborsky@mall.cz>)
List pgsql-performance
Michal Taborsky - Internet Mall wrote:
> Tom Lane napsal(a):
> >Michal Taborsky - Internet Mall <michal.taborsky@mall.cz> writes:
> >>SELECT product.product_id
> >>   FROM action
> >>   JOIN product ON (product.product_id=action.product_id)
> >>  WHERE action.shop_group_id=1
> >>    AND EXISTS (SELECT 1
> >>          FROM catalog.product_program
> >>          WHERE product_id=product.product_id
> >>            AND product_program.program_id =1104322
> >>    )
> >
> >Try converting the EXISTS subquery to an IN.
>
> The performance is roughly the same.

That's strange -- IN is usually much more amenable to better plans than
EXISTS.  Please post an EXPLAIN ANALYZE of the queries to see what's
going on.  It may be that the query is bound to be "slow" for some
cases (depending on the program_id I guess?)

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

pgsql-performance by date:

Previous
From: "Steve Poe"
Date:
Subject: Re: Postgresql Performance on an HP DL385 and
Next
From: "Jim Nasby"
Date:
Subject: Re: [BUGS] BUG #2567: High IOWAIT