Controlling join order with parenthesis

From: "Marc Mamin" <M(dot)Mamin(at)intershop(dot)de>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Controlling join order with parenthesis
Date: 2010-09-09 12:51:27
Message-ID: C4DAC901169B624F933534A26ED7DF31034BB7D3@JENMAIL01.ad.intershop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

According to the documentation, I thought it was possible to force given
join orders with parenthesis.

But in this small example, this seems to have no effect;
With the first query, I'd expected to see t3 in the Merge Right Join
but both queries return the same query plan .

I'm missing a point ?

(Postgres 8.3)

create temp table t1(i int);
create temp table t2(i int);
create temp table t3(i int);

select * from
(
( t1 LEFT OUTER JOIN t2 on (t1.i=t2.i) )
LEFT OUTER JOIN t3 on (t2.i=t3.i)
)

select * from
(
t1 LEFT OUTER JOIN
(t2 LEFT OUTER JOIN t3 on (t2.i=t3.i) )
on (t1.i=t2.i)
)

Merge Right Join (cost=506.24..6206.24 rows=345600 width=12)
Merge Cond: (t2.i = t1.i)
-> Merge Left Join (cost=337.49..781.49 rows=28800 width=8)
Merge Cond: (t2.i = t3.i)
-> Sort (cost=168.75..174.75 rows=2400 width=4)
Sort Key: t2.i
-> Seq Scan on t2 (cost=0.00..34.00 rows=2400 width=4)
-> Sort (cost=168.75..174.75 rows=2400 width=4)
Sort Key: t3.i
-> Seq Scan on t3 (cost=0.00..34.00 rows=2400 width=4)
-> Sort (cost=168.75..174.75 rows=2400 width=4)
Sort Key: t1.i
-> Seq Scan on t1 (cost=0.00..34.00 rows=2400 width=4)

best regards,

Marc Mamin

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2010-09-09 13:49:45 Re: Controlling join order with parenthesis
Previous Message Joe Conway 2010-09-08 16:02:10 Re: Generating Rows from a date and a duration