From: | ries van Twisk <pg(at)rvt(dot)dds(dot)nl> |
---|---|
To: | emilu(at)encs(dot)concordia(dot)ca |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: "union" vs. left join |
Date: | 2009-03-03 20:33:43 |
Message-ID: | 9298C092-EC09-49F0-BBBB-B49720008351@rvt.dds.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Mar 3, 2009, at 3:26 PM, Emi Lu wrote:
> Good morning,
>
> Would it be possible to know that whether "union" is quicker than
> "left join" in a general sense?
>
> Queries:
> ========================
> (1) union
> select a.*, b.value
> from a
> left join b
> union
> select a.*, c.value
> from a
> left join c
>
>
> (2) left join
> select distinct a.*,
> case when ... then
> b.value
> else
> c.value
> from a
> left join b
> left join c
>
>
> Will (1) be more efficient than (2) or vice versa? Or it really
> depends on data
>
>
> Thanks a lot!
> Lu Ying
>
I would say try it in your situation...
I never did any real worl testing, but usually I grab a left join
before anything else.
I would suspect that the planner knows a bit better how to optimize
the left join version.
Ries
From | Date | Subject | |
---|---|---|---|
Next Message | Jhonny Velasquez c. | 2009-03-05 15:48:17 | |
Previous Message | Emi Lu | 2009-03-03 20:26:22 | "union" vs. left join |