Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 06F4FB5DC44 for ; Mon, 8 Aug 2011 14:50:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 26153-09 for ; Mon, 8 Aug 2011 17:50:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtp18.mail.ru (smtp18.mail.ru [94.100.176.155]) by mail.postgresql.org (Postfix) with ESMTP id 98297B5DC3F for ; Mon, 8 Aug 2011 14:50:42 -0300 (ADT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:In-Reply-To:References:Cc:To:From; bh=5C4DBNO13YMw8oy2JMM7A7uyNhtixG2YHCN3SwkazjQ=; b=hWdwt5pVNI/uafOtF10McMmHulJifZIvoZkC4U2NMlgz6Gn8+kGWvA7TkXrVvj4AMTVvB5nn/3fi6/6DGjpT2Z3G6TeLwlfE9J/lCZxLvyAappm8N+pidd2B8U8CLy69; Received: from [180.183.160.156] (port=10547 helo=ws) by smtp18.mail.ru with asmtp id 1QqTyK-0006mL-00; Mon, 08 Aug 2011 21:50:40 +0400 From: "ai" To: "'Kevin Grittner'" , "'Tom Lane'" Cc: References: <201108081313.p78DDX6W021751@wwwmaster.postgresql.org> <4E3FA39B020000250003FC1F@gw.wicourts.gov> <25701.1312815692@sss.pgh.pa.us> <01bc01cc55e0$4592ddf0$d0b899d0$@mail.ru> <4E3FD730020000250003FC3D@gw.wicourts.gov> In-Reply-To: <4E3FD730020000250003FC3D@gw.wicourts.gov> Subject: Re: BUG #6154: wrong result with nested left-joins Date: Tue, 9 Aug 2011 00:50:33 +0700 Message-ID: <01ce01cc55f3$afa6cd60$0ef46820$@mail.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQKtBagl8fgbDVr+0xwL5rgFD0w44gLDzn4lAgnuvfgC5NSmfwHPDG/SkwXOjBA= Content-Language: ru X-Spam: Not detected X-Mras: Ok X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201108/71 X-Sequence-Number: 30883 Kevin and all others, thanks for your work! -----Original Message----- From: Kevin Grittner [mailto:Kevin.Grittner@wicourts.gov] Sent: Tuesday, August 09, 2011 12:32 AM To: ai; 'Tom Lane' Cc: pgsql-bugs@postgresql.org Subject: RE: [BUGS] BUG #6154: wrong result with nested left-joins "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