Faster not in

From: grant(dot)johnson(at)twcable(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: Faster not in
Date: 2002-09-12 16:44:29
Message-ID: 3D80C46D.4080008@aol.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Browse pgsql-general by date

  From Date Subject
Next Message Tim Perdue 2002-09-12 17:44:26 Latitude / Longitude
Previous Message Roderick A. Anderson 2002-09-12 15:45:02 Re: max | last INET in table