Faster not in - Mailing list pgsql-general

From grant.johnson@twcable.com
Subject Faster not in
Date
Msg-id 3D80C46D.4080008@aol.com
Whole thread Raw
List pgsql-general
I know that the not in query is VERY slow.  The suggestion I have seen
here is to do a not exists with a sub select.  There is a faster, easier
way.  Do a left join and look for a null in the field on the table where
you want no match.

select a,b frrom c where b not in (select b from d);
select a,b from c where not exists (select b from d where c.b=d.b);
select a,b from c left join d on c.d=d.b where d.b is null;

This last one is faster, and more portable.


pgsql-general by date:

Previous
From: "David D. Kilzer"
Date:
Subject: [SCRIPT] pgrefchk -- checks referential integrity of foreign keys on tables
Next
From: "Ross J. Reedstrom"
Date:
Subject: Re: [HACKERS] MySQL wins award - makes amusing statement