From: | Ludwig Lim <lud_nowhere_man(at)yahoo(dot)com> |
---|---|
To: | Jinn Koriech <lists(at)idealint(dot)co(dot)uk> |
Cc: | PostgreSQL Mailing List <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: negative queries puzzle |
Date: | 2002-08-01 01:51:35 |
Message-ID: | 20020801015135.6908.qmail@web40011.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
--- Jinn Koriech <lists(at)idealint(dot)co(dot)uk> wrote:
> hi all,
> 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;
>
> does anyone know of a quicker way to accomplish
> this?
Try using the "NOT EXIST" clause instead of the "NOT
IN". The "EXIST" clause utilizes the index while the
"IN" does not utilizes index (i.e. uses sequential
scan therefore it is much slower).
SELECT DISTINCT *
FROM v_postcode_new
WHERE NOT EXIST( SELECT postcode
FROM v_postcode_old
WHERE v_postcode_new.postcode =
v_postcode_old.postcode)
ORDER BY postcode ASC;
ludwig.
__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com
From | Date | Subject | |
---|---|---|---|
Next Message | Christopher Kings-Lynne | 2002-08-01 06:46:47 | Re: License |
Previous Message | Christopher Kings-Lynne | 2002-08-01 01:51:02 | Re: negative queries puzzle |