Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 5BA99B5DCBB for ; Mon, 8 Aug 2011 14:32:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 01908-01-5 for ; Mon, 8 Aug 2011 17:32:05 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 42DB5B5DBBF for ; Mon, 8 Aug 2011 14:31:54 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Mon, 08 Aug 2011 12:31:54 -0500 Message-Id: <4E3FD730020000250003FC3D@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Mon, 08 Aug 2011 12:31:44 -0500 From: "Kevin Grittner" To: "ai" ,"'Tom Lane'" Cc: Subject: Re: BUG #6154: wrong result with nested left-joins References: <201108081313.p78DDX6W021751@wwwmaster.postgresql.org> <4E3FA39B020000250003FC1F@gw.wicourts.gov> <25701.1312815692@sss.pgh.pa.us> <01bc01cc55e0$4592ddf0$d0b899d0$@mail.ru> In-Reply-To: <01bc01cc55e0$4592ddf0$d0b899d0$@mail.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.711 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.811 X-Spam-Level: X-Archive-Number: 201108/70 X-Sequence-Number: 30882 "ai" wrote: > Oops.. I just saw, that I send you "correct" (already with "workaround") > sql-code instead of "wrong"... > here is "wrong" (difference is in "SELECT sub3.key3, sub4.value2 FROM" ): OK, that is still happening, and looks wrong to me. The outermost LEFT JOIN is between this: test=# SELECT * FROM (SELECT 1 as key1) sub1; key1 ------ 1 (1 row) as sub1 and this: test=# SELECT sub3.key3, sub4.value2 test-# FROM (SELECT 1 as key3) sub3 test-# LEFT JOIN test-# ( test(# SELECT sub5.key5, COALESCE(sub6.value1, 1) as value2 test(# FROM (SELECT 1 as key5) sub5 test(# LEFT JOIN test(# ( test(# SELECT 1 as key6, value1 test(# FROM (SELECT NULL::integer as value1) sub7 test(# WHERE false test(# ) sub6 ON false test(# ) sub4 ON sub4.key5=sub3.key3; key3 | value2 ------+-------- 1 | 1 (1 row) as sub2 joining on sub1.key1 = sub2.key3. Yet: test=# SELECT * test-# FROM (SELECT 1 as key1) sub1 test-# LEFT JOIN test-# ( test(# SELECT sub3.key3, sub4.value2 test(# FROM (SELECT 1 as key3) sub3 test(# LEFT JOIN test(# ( test(# SELECT sub5.key5, COALESCE(sub6.value1, 1) as value2 test(# FROM (SELECT 1 as key5) sub5 test(# LEFT JOIN test(# ( test(# SELECT 1 as key6, value1 test(# FROM (SELECT NULL::integer as value1) sub7 test(# WHERE false test(# ) sub6 ON false test(# ) sub4 ON sub4.key5=sub3.key3 test(# ) sub2 ON sub1.key1 = sub2.key3; key1 | key3 | value2 ------+------+-------- 1 | 1 | (1 row) This is on HEAD from today. Clearly there's a problem. -Kevin