Re: improve 'where not exists' query.. - Mailing list pgsql-general

From Noel Whelan
Subject Re: improve 'where not exists' query..
Date
Msg-id 1eb3081c0510261058y52b46798h953f9de6ac4a5330@mail.gmail.com
Whole thread Raw
In response to Re: improve 'where not exists' query..  (Bruno Wolff III <bruno@wolff.to>)
Responses Re: improve 'where not exists' query..  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-general
I've done an explain analyze - nothing looks wrong to me. I'm thinking it's not exactly an issue with the query itself; it's just an inefficient thing I want to do (essentially, for each id in the one table, identify whether or not one exists in the other table).
 
Current installation is 7.3.4; but I'll look into NOT IN in case that would be an improvement. Thanks,
 
- Noel

 
On 10/26/05, Bruno Wolff III <bruno@wolff.to> wrote:
On Tue, Oct 25, 2005 at 15:46:52 -0500,
Noel Whelan <noel.whelan@gmail.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?

pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: improve 'where not exists' query..
Next
From: Larry Rosenman
Date:
Subject: Re: querying PostgreSQL version?