NOT EXISTS or LEFT JOIN which one is better?

From: AI Rumman <rummandba(at)gmail(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: NOT EXISTS or LEFT JOIN which one is better?
Date: 2012-04-29 09:27:19
Message-ID: CAGoODpeU62n-gnE2NDMYwPGnszRv6=vmeJac8J=fuBMCNEZHBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

I can write a query to solve my requirement in any of the followings :-

1.
select *
from a
where NOT EXISTS
(
select 1
from b
where a.id = b.id)
union all
select *
from b

2.
select
(
case when b.id is not null then
b.id
else
a.id
) as id
from a
left join b
on a.id = b.id

Any one please tell me which one is better?

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Eyal Wilde 2012-04-29 13:21:23 Re: scale up (postgresql vs mssql)
Previous Message Richard Kojedzinszky 2012-04-28 06:11:25 Re: query optimization