Re: IN vs EXIIST

From: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: IN vs EXIIST
Date: 2002-09-19 07:49:11
Message-ID: 3D898177.2070001@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bill Gribble wrote:

>I just did this today for a query and got a 200x speedup when
>converting from IN to EXISTS. It's dependent on your specific query
>exactly how to do the conversion, but generally it's just a question
of >moving a field from the "outside" to the "inside" of the subselect.

If it's not asking too much could you recommend how I could fix this
query? It's a bit more complicated than yours and I can't seem to get
the syntax right.

select distinct invoice_id from invoice_li where received='true'
AND shipped='false' AND cancelled='false'
AND
(invoice_id not in
(
select distinct invoice_id from invoice_li where received='false'
AND cancelled='false'
)
OR ship_now='true'
)

Sorry for the formatting ...

Jc

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jean-Christian Imbeault 2002-09-19 07:58:47 datetime(): Where is it in the docs?
Previous Message Wim 2002-09-19 05:57:31 Re: [GENERAL] Still big problems with pg_dump!