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 1hJky8-0004a8-TF for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Apr 2019 20:27:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hJky6-0004rE-1U for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Apr 2019 20:27:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hJky5-0004po-KV; Thu, 25 Apr 2019 20:27:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hJky3-0004Jh-6v; Thu, 25 Apr 2019 20:27:40 +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 x3PKRZSr030150; Thu, 25 Apr 2019 16:27:35 -0400 From: Tom Lane To: Dmitry Dolgov <9erthalion6@gmail.com> cc: sean.johnston@edgeintelligence.com, pgsql-bugs@lists.postgresql.org, PostgreSQL Developers Subject: Re: BUG #15781: subselect on foreign table (postgres_fdw) can crash (segfault) In-reply-to: References: <15781-2601b1002bad087c@postgresql.org> <25734.1556216681@sss.pgh.pa.us> Comments: In-reply-to Dmitry Dolgov <9erthalion6@gmail.com> message dated "Thu, 25 Apr 2019 22:20:59 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30148.1556224055.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 25 Apr 2019 16:27:35 -0400 Message-ID: <30149.1556224055@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Dmitry Dolgov <9erthalion6@gmail.com> writes: >> On Thu, Apr 25, 2019 at 8:24 PM Tom Lane wrote: >> The proximate cause of the crash is that we have {PARAM 1} >> (representing the output of the InitPlan) in the path's fdw_exprs, and >> also the identical expression in fdw_scan_tlist, and that means that wh= en >> setrefs.c processes the ForeignScan node it thinks it should replace th= e >> {PARAM 1} in fdw_exprs with a Var representing a reference to the >> fdw_scan_tlist entry. > I've noticed, that it behaves like that since f9f63ed1f2e5 (originally I= found > it pretty strange, but after this explanation it does make sense). As an > experiment, I've changed the position of condition of > if (context->subplan_itlist->has_non_vars) > back - it also made problem to disappear, Well, that's just coincidental for the case where the problem fdw_expr is a Param. I haven't tried to figure out exactly what upper-path generation thinks it should put into fdw_exprs, but is it really only Params? Anyway, ideally we'd not have any entries in fdw_scan_tlist that don't include at least one foreign Var, and then there can't be a false match. regards, tom lane