Re: negative queries puzzle

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "Jinn Koriech" <lists(at)idealint(dot)co(dot)uk>, "PostgreSQL Mailing List" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: negative queries puzzle
Date: 2002-08-01 01:51:02
Message-ID: GNELIHDDFBOCMGBFGEFOEEHFCDAA.chriskl@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> but then to get the entirely new items out i use a sub query which takes
> for ever
>
> SELECT DISTINCT * FROM v_postcode_new WHERE postcode NOT IN ( SELECT
> postcode FROM v_postcode_old ) ORDER BY postcode ASC;

NOT IN is known to be very, very slow in Postgres. Use NOT EXISTS instead:

SELECT DISTINCT * FROM v_postcode_new vpn WHERE NOT EXISTS (SELECT TRUE FROM
v_postcode_old vpo WHERE vpo.postcode=vpn.postcode) ORDER BY postcode ASC;

Chris

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ludwig Lim 2002-08-01 01:51:35 Re: negative queries puzzle
Previous Message Stephan Szabo 2002-08-01 00:23:22 Re: FW: Case Statement