Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gosho-0002ec-0N for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Jan 2019 16:27:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gosgn-00052d-4v for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Jan 2019 16:26:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gosgm-00052Q-Ut for pgsql-bugs@lists.postgresql.org; Wed, 30 Jan 2019 16:26:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gosgg-0006EM-15 for pgsql-bugs@lists.postgresql.org; Wed, 30 Jan 2019 16:26:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x0UGPv6w019833; Wed, 30 Jan 2019 11:25:58 -0500 From: Tom Lane To: Etsuro Fujita cc: srinivasan.sa@zohocorp.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15613: Bug in PG Planner for Foreign Data Wrappers In-reply-to: <5C51993C.2070606@lab.ntt.co.jp> References: <15613-092be1be9576c728@postgresql.org> <5C51993C.2070606@lab.ntt.co.jp> Comments: In-reply-to Etsuro Fujita message dated "Wed, 30 Jan 2019 21:31:56 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19831.1548865557.1@sss.pgh.pa.us> Date: Wed, 30 Jan 2019 11:25:57 -0500 Message-ID: <19832.1548865557@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Etsuro Fujita writes: > (2019/01/30 18:46), PG Bug reporting form wrote: >> Foreign scan of a table (part of join), has a column of another table >> involved in its qual. > I haven't looked into this in details yet, but do you have this issue in > the latest release of 9.6 (ie 9.6.11), not in 9.6.3? I just thought > this might have been fixed already by commits [1][2]. Nope, cause it's still there in HEAD :-(. What I'm wondering is why the ref_0.t1_col2 IS NOT NULL condition is being pushed down to the ref_1 scan in the first place, rather than ref_0 where you'd think it should go. Yes, this plan shape could have been made to work if the Var reference had been converted to a NestLoopParam reference, but it wasn't. So there are a few interesting questions here: * Why was the IS NOT NULL pushed down to the wrong place? * Having made that mistake, why didn't the NLP mechanism fix it and create a valid plan anyway? * I find that s/RIGHT JOIN/JOIN/ makes the problem go away: the IS NOT NULL is pushed to the right place and there's no error. This is even weirder, because the planner successfully simplifies the outer join to a plain join on its own, and you'd think that that would happen before any mistake that could cause the other two problems. Join strength reduction runs before distribute_qual_to_rels, so how's that happening? Probably the answers to these questions are interrelated and there's only one bug at bottom. But maybe not. I've not really dug into it yet. regards, tom lane