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 08:43:40
Message-ID: 3D898E3C.3000009@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Henshall, Stuart - WCP wrote:
>
> select distinct invoice_id from invoice_li where received='true'
> AND shipped='false' AND cancelled='false'
> AND
> (NOT EXISTS
> (
> select * from invoice_li AS sq_inv_li where received='false'
> AND cancelled='false' AND invoice_li.invoice_id=sq_inv_li.invoice_id
> )
> OR ship_now='true'
> )
>
> Should work (but is untested).

I'll test it and let you know. Tanks!

> As a side note there doesn't seem a point to having distinct on the
> subquery in its original form either, so this could be removed to reduce
> overhead.

Really? I though that reducing the number of results in the sub-select
would make the query more efficient since the outer query would have
less items to check.

I.e. it would be faster to check if something is in (1,2,3) than if it
is in (1,2,2,2,2,2,2,2,2,2,3). No?

Let me check that new optimized query!

Jc

Browse pgsql-general by date

  From Date Subject
Next Message frbn 2002-09-19 08:56:06 Re: Database uptime?
Previous Message Jean-Christian Imbeault 2002-09-19 08:09:10 Adding to a date/time?