Re: improve 'where not exists' query..

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Noel Whelan <noel(dot)whelan(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: improve 'where not exists' query..
Date: 2005-10-26 17:54:58
Message-ID: 20051026175458.GB11447@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Oct 25, 2005 at 15:46:52 -0500,
Noel Whelan <noel(dot)whelan(at)gmail(dot)com> wrote:
> I'm wondering if there's an ideal way to improve the efficiency of this
> query:
>
> SELECT i.id <http://i.id> FROM items i
> WHERE (NOT (EXISTS (SELECT c.id <http://c.id>
> FROM contacts c WHERE (c.id <http://c.id> = i.id <http://i.id>))));
>
> It takes a while to execute, clearly. Thank you,

On recent versions of postgres, NOT IN is potentially faster.

Have you looked at EXPLAIN ANALYZE output to see if anything looks amiss?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Noel Whelan 2005-10-26 17:58:26 Re: improve 'where not exists' query..
Previous Message Wes Williams 2005-10-26 17:43:39 Re: Why database is corrupted after re-booting