The most efficient way to put this?

From: "Arsalan Zaidi" <azaidi(at)directi(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: The most efficient way to put this?
Date: 2002-03-05 10:11:51
Message-ID: 01bf01c1c42e$377f16a0$4301a8c0@directi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Bell 2002-03-05 10:44:44 System Tables Query
Previous Message Ulrich Wisser 2002-03-05 08:02:04 vacuum statistics