pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Stark <gsstark@mit.edu>
To: jelliott@artcobell.com
Cc: pgsql-performance@postgresql.org
Subject: Re: slow query - where not in
Date: 28 Mar 2003 11:20:29 -0500
Message-ID: <87u1dn31ki.fsf@stark.dyndns.tv> (raw)
In-Reply-To: <200303280938.50382.jelliott@artcobell.com>
References: <200303280938.50382.jelliott@artcobell.com>

Jeremiah Elliott <jelliott@artcobell.com> writes:

> here is the query that is killing me:
> 
> select shoporder from sodetailtabletrans where shoporder not in(select 
> shoporder from soheadertable)
> 
> This is just an example query. Any time I use 'where not in(' it takes several 
> hours to return a resultset. The postgres version is 7.2.3 although I have 
> tried it on my test server which has 7.3 on it and it runs just as slow. The 
> server is a fast server 2GHz with a gig of ram.  I have tried several 
> differant index setups but nothing seems to help.

This should be improved with 7.4, however there are some other things you can
try now.

try

SELECT shoporder 
  FROM sodetailtabletrans 
 WHERE NOT EXISTS (
       SELECT 1
         FROM soheadertable
        WHERE shoporder = sodetailtabletrans.shoporder
       )

or else try something like

         SELECT a.shoporder
           FROM sodetailtabletrans as a
LEFT OUTER JOIN soheadertable as b ON (a.shoporder = b.shoporder)
          WHERE b.shoporder IS NULL


--
greg




view thread (6+ messages)  latest in thread

Message-ID: <87u1dn31ki.fsf@stark.dyndns.tv>
Permalink:  ../87u1dn31ki.fsf@stark.dyndns.tv/
Also on:    postgresql.org/message-id/87u1dn31ki.fsf@stark.dyndns.tv

 · 

reply

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: gsstark@mit.edu, jelliott@artcobell.com
  Subject: Re: slow query - where not in
  In-Reply-To: <87u1dn31ki.fsf@stark.dyndns.tv>
  References: <200303280938.50382.jelliott@artcobell.com> <87u1dn31ki.fsf@stark.dyndns.tv>

* 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