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 1grkr9-0003jA-J3 for pgsql-bugs@arkaria.postgresql.org; Thu, 07 Feb 2019 14:40:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1grkr7-0001Rb-Sq for pgsql-bugs@arkaria.postgresql.org; Thu, 07 Feb 2019 14:40:45 +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 1grkr7-0001OA-LA for pgsql-bugs@lists.postgresql.org; Thu, 07 Feb 2019 14:40:45 +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 1grkr1-00019G-8J for pgsql-bugs@lists.postgresql.org; Thu, 07 Feb 2019 14:40:45 +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 x17EeSfC018212; Thu, 7 Feb 2019 09:40:29 -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: <5C5BE324.6030601@lab.ntt.co.jp> References: <15613-092be1be9576c728@postgresql.org> <5C51993C.2070606@lab.ntt.co.jp> <19832.1548865557@sss.pgh.pa.us> <24678.1548870484@sss.pgh.pa.us> <5C52C769.5090600@lab.ntt.co.jp> <19209.1548957996@sss.pgh.pa.us> <5C5A5F75.5040203@lab.ntt.co.jp> <5C5ACA1B.3000207@lab.ntt.co.jp> <11975.1549480555@sss.pgh.pa.us> <5C5BE324.6030601@lab.ntt.co.jp> Comments: In-reply-to Etsuro Fujita message dated "Thu, 07 Feb 2019 16:49:56 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18210.1549550428.1@sss.pgh.pa.us> Date: Thu, 07 Feb 2019 09:40:28 -0500 Message-ID: <18211.1549550428@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Etsuro Fujita writes: >> I propose that we apply this or something much like it to HEAD, and leave >> the problem of actually working out parameterized foreign joins for later. > Agreed. One thing I noticed is this bit in create_foreign_join_path: > + /* > + * Since the path's required_outer should always include all the rel's > + * lateral_relids, forcibly add those if necessary. This is a bit of a > + * hack, but up till early 2019 the contrib FDWs failed to ensure that, > + * and it's likely that the same error has propagated into many external > + * FDWs. Don't risk modifying the passed-in relid set here. > + */ > + if (rel->lateral_relids && !bms_is_subset(rel->lateral_relids, > + required_outer)) > + required_outer = bms_union(required_outer, rel->lateral_relids); > I think this would waste cycles. Do we really need this? How about > just throwing an error instead of doing this, if the joinrel has lateral > references? It ends up being the same thing, because of the test below it, but at least in HEAD yes this could be simplified. What I posted is a bit schizophrenic as to whether it's intended for HEAD or back branches. Probably, in HEAD there is no good reason to cater for buggy FDWs at all; the new Asserts in relnode.c are enough, assuming that FDW authors run some tests while updating to v12. And if we decide not to backpatch create_foreign_join_path at all, then it doesn't need a defense like the above either. So we just need the above-quoted bit in the back branch versions of create_foreignscan_path. regards, tom lane