Re: The most efficient way to put this?

From: "Marc Polatschek" <Marc(dot)Polatschek(at)computec(dot)de>
To: "Arsalan Zaidi" <azaidi(at)directi(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: The most efficient way to put this?
Date: 2002-03-05 11:23:25
Message-ID: 2266D0630E43BB4290742247C89105758DCAD1@dozer.computec.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hm, you can try to make a statement with UNION and GROUP by. i dont know
if it is faster...

-----Ursprüngliche Nachricht-----
Von: Arsalan Zaidi [mailto:azaidi(at)directi(dot)com]
Gesendet: Dienstag, 5. März 2002 11:12
An: pgsql-general(at)postgresql(dot)org
Betreff: [GENERAL] The most efficient way to put this?

The query I'd like to run is fairly simple. Unfortunately, PG doesn't
handle
IN's very well.

SELECT DISTINCT ON (aa.a) aa.a, aa.b, aa.c FROM aa WHERE aa.a NOT IN
(select
zz.a from zz);

This is with two very large tables. Both zz and aa have many millions of
rows.

The best I've come up with so far is...

SELECT DISTINCT ON (aa.a) aa.a, aa.b, aa.c FROM aa WHERE NOT EXISTS
(SELECT
zz.a FROM zz WHERE aa.a = zz.a);

Does anyone have anything better?

--Arsalan

-------------------------------------------------------------------
People often hate those things which they do not know, or cannot
understand.
--Ali Ibn Abi Talib (A.S.)

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

Browse pgsql-general by date

  From Date Subject
Next Message Bjoern Metzdorf 2002-03-05 12:02:29 FATAL 2: open of pg_clog error
Previous Message John Bell 2002-03-05 10:44:44 System Tables Query