From: Bruno Wolff III <bruno@wolff.to>
To: Jeremiah Elliott <jelliott@artcobell.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: slow query - where not in
Date: Fri, 28 Mar 2003 09:59:33 -0600
Message-ID: <20030328155933.GA10761@wolff.to> (raw)
In-Reply-To: <200303280938.50382.jelliott@artcobell.com>
References: <200303280938.50382.jelliott@artcobell.com>
On Fri, Mar 28, 2003 at 09:38:50 -0600,
Jeremiah Elliott <jelliott@artcobell.com> wrote:
> here is the query that is killing me:
>
> select shoporder from sodetailtabletrans where shoporder not in(select
> shoporder from soheadertable)
This will probably work better in 7.4.
For now there are several ways to rewrite this query.
If there are no null values for shoporder in soheadertable or
sodetailtabletrans you can use not exists instead of not in:
select shoporder from sodetailtabletrans where shoporder not exists(select
shoporder from soheadertable)
You can use set difference to calculate the result:
select shoporder from sodetailtabletrans except all select
shoporder from soheadertable
If there are no null values for shoporder in one of sodetailtabletrans
or soheadertable you can user an outer join with a restriction that limits
the rows of interest to those that don't match:
select sodetailtabletrans.shoporder from sodetailtabletrans left join
soheadertable using (shoporder) where soheadertable.shoporder is null
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: bruno@wolff.to, jelliott@artcobell.com
Subject: Re: slow query - where not in
In-Reply-To: <20030328155933.GA10761@wolff.to>
References: <200303280938.50382.jelliott@artcobell.com> <20030328155933.GA10761@wolff.to>
* 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