Re: [SQL] outer joins strangeness

From: Alex Pilosov <alex(at)pilosoft(dot)com>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [SQL] outer joins strangeness
Date: 2001-09-24 05:09:31
Message-ID: Pine.BSO.4.10.10109240102090.28103-100000@spider.pilosoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

On Sun, 23 Sep 2001, Stephan Szabo wrote:

> On Sun, 23 Sep 2001, Alex Pilosov wrote:
>
> > It may be just me, or I am grossly misunderstanding syntax of outer joins,
> > but I see that plans for my queries are different depending on how I place
> > join conditions and sometimes even on order of the tables.
> >
> > Example:
> > 1:
> > explain select * from customers c,orders o left outer join adsl_orders ao
> > on ao.order_id=o.order_id
> > where c.cust_id=o.cust_id
> > and c.cust_id=152
<snip>
> >
> > explain select * from customers c join orders o on c.cust_id=o.cust_id
> > left outer join adsl_orders ao on ao.order_id=o.order_id
> > where c.cust_id=152

> Postgres treats join syntax as an explicit definition of what order to
> joins in. So, I'd guess it sees the first as: do the LOJ and then join
> that to the separate table.
Yeah, I figure that's how it sees it, but that's pretty stupid from
performance reasons :P)

It _should_ realize that left outer join only constricts join order
between two tables in outer join, and joins to all other tables should
still be treated normally.

I'm going to CC this to -hackers, maybe someone will shed a light on the
internals of this.

> And for right outer join (for example), those two queries would not
> be equivalent if I read the ordering correctly. The former syntax
> would mean outer first and then the inner, whereas the second would
> be inner first then the outer, and that could have different results.
True. But this is not right outer join, its a left outer join...:)

Postgres should understand that left outer join does not constrict join
order...

-alex

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gavin Sherry 2001-09-24 05:19:10 Re: CLUSTER TODO item
Previous Message Stephan Szabo 2001-09-24 04:57:11 Re: outer joins strangeness

Browse pgsql-sql by date

  From Date Subject
Next Message Oleg Bartunov 2001-09-24 05:54:11 Re: loading array_iterator.so does not work with Postgresql
Previous Message Stephan Szabo 2001-09-24 04:57:11 Re: outer joins strangeness