X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 28AE147632C for ; Wed, 26 Mar 2003 18:02:34 -0500 (EST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id D60C3475CBC for ; Wed, 26 Mar 2003 18:02:02 -0500 (EST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 61E9FD5FA; Wed, 26 Mar 2003 15:02:04 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 57BF55C0A; Wed, 26 Mar 2003 15:02:04 -0800 (PST) Date: Wed, 26 Mar 2003 15:02:04 -0800 (PST) From: Stephan Szabo To: Tom Lane Cc: Greg Stark , "Correia, Carla" , "'pgsql-sql@postgresql.org'" Subject: Re: Complex outer joins? In-Reply-To: <7039.1048718031@sss.pgh.pa.us> Message-ID: <20030326145855.J66362-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Status: No, hits=-26.0 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/592 X-Sequence-Number: 12630 On Wed, 26 Mar 2003, Tom Lane wrote: > Stephan Szabo writes: > > On 26 Mar 2003, Greg Stark wrote: > >> Can you show an example where the join order would affect the result set? I > >> can't think of any. > > > I can think of a few somewhat degenerate cases. > > I don't think you need a degenerate case. Consider > > from (G left join L on (G.SELID = L.SELID)) > right join C on (L.SELID = C.SELID) > > versus > > from G left join > (L right join C on (L.SELID = C.SELID)) > on (G.SELID = L.SELID) I'd noticed that too, but I was trying to do it without changing the type of join since I wasn't sure whether he'd meant one using only left joins or outer joins in general. > The difference between this and the query we were discussing is just use > of "right" rather than "left" in the second JOIN. AIUI, in the Oracle > syntax this difference would be expressed by moving the (*) from one > side to the other of the L.SELID = C.SELID clause. Unless they have > strange restrictions on the combinations of clauses you can mark with > (*), I don't see how they can assume that join order is insignificant. I'd guess that they might check that the conditions are in a specific set of limited conditions in order to allow the reordering and disallow the reordering otherwise (well, I'd hope that they do this if they ever allow reordering).