From: Alvaro Herrera <alvherre@commandprompt.com>
To: Michal Taborsky - Internet Mall <michal.taborsky@mall.cz>
Cc: pgsql-performance@postgresql.org
Subject: Re: 3-table query optimization
Date: Thu, 10 Aug 2006 11:50:17 -0400
Message-ID: <20060810155017.GI23053@alvh.no-ip.org> (raw)
In-Reply-To: <44DAE09B.20009@mall.cz>
References: <44D9EBEB.9010704@mall.cz>
<20367.1155136139@sss.pgh.pa.us>
<44DAE09B.20009@mall.cz>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: alvherre@commandprompt.com, michal.taborsky@mall.cz
Subject: Re: 3-table query optimization
In-Reply-To: <20060810155017.GI23053@alvh.no-ip.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox