Re: outer join versus not exists

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: chester c young <chestercyoung(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: outer join versus not exists
Date: 2003-03-18 17:30:55
Message-ID: 20030318173055.GA21021@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Mar 18, 2003 at 08:54:27 -0800,
chester c young <chestercyoung(at)yahoo(dot)com> wrote:
> In pg, is there any performance gain in using outer join with null as
> versus using not exists, eg:
>
> select t1.* from t1 right join t2 using( id ) where t2.id is null;
>
> versus
>
> select * from t1 where not exists (select 1 from t2 where t1.id=t2.id);

You can use explain analyze to compare the queries.

Another possible approach is:

select t1.* from t1, (select id from t1 except select id from t2) t3
where t1.id = t3.id;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Matthew Nuzum 2003-03-18 18:00:56 showing records from the last 20 min
Previous Message Tom Lane 2003-03-18 17:29:16 Re: outer join versus not exists