Re: [SQL] comparing 2 tables. . .

From: Engard Ferenc <fery(at)pons(dot)sote(dot)hu>
To: PostgreSQL list <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: [SQL] comparing 2 tables. . .
Date: 1999-09-25 13:35:45
Message-ID: Pine.LNX.4.02.9909251531170.286-100000@domesticus.sote.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, 24 Sep 1999, Albert REINER wrote:

>On Fri, Sep 24, 1999 at 03:32:51PM +0100, Stuart Rison wrote:
>...
>> Try:
>>
>> SELECT tab1.pkey FROM <your_table> tab1 WHERE tab1.pkey NOT IN (SELECT
>> tab2.pkey FROM <your_other_table> tab2.pkey);
>>
>> or else (faster):
>>
>> SELECT tab1.pkey FROM <your_table> tab1 WHERE NOT EXISTS (SELECT 1 FROM
>> <your_other_table> tab2 WHERE tab1.pkey=tab2.pkey);
>
>Maybe this is trivial, but...
>
>Is there a simple way to see that/why the last query is faster?

Yes, the simple way is to look at the thread 'subselect performance'
a few days ago... :-)) In essence, I don't know... ;) Something
about that the subselect's result always recomputed for each row in
the main select or what, if I got the idea. (And in the 2nd case the
subselect has only one row, provided that the primary keys are
unique.)

Circum

PS: Anyway, as I can figure it out, this is that 'EXISTS' workaround
that you mentioned in that thread, right?

__ @
/ \ _ _ Engárd Ferenc
l | ( \ / | | (\/) mailto:s-fery(at)kkt(dot)sote(dot)hu
\__/ | | \_ \_/ I I http://pons.sote.hu/~s-fery

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Radek Kanovsky 1999-09-25 15:15:11 11128.1 != 11128.1
Previous Message omid omoomi 1999-09-25 04:04:24 RE: [SQL] comparing 2 tables. . .