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 1hJl6T-0004ze-JL for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Apr 2019 20:36:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hJl6S-0007mQ-BZ for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Apr 2019 20:36:20 +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 1hJl6S-0007mF-2a; Thu, 25 Apr 2019 20:36:20 +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 1hJl6P-0001d1-Kl; Thu, 25 Apr 2019 20:36:19 +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 x3PKaEas030639; Thu, 25 Apr 2019 16:36:14 -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: <30149.1556224055@sss.pgh.pa.us> References: <15781-2601b1002bad087c@postgresql.org> <25734.1556216681@sss.pgh.pa.us> <30149.1556224055@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 25 Apr 2019 16:27:35 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30637.1556224574.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 25 Apr 2019 16:36:14 -0400 Message-ID: <30638.1556224574@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > Well, that's just coincidental for the case where the problem fdw_expr i= s > a Param. I haven't tried to figure out exactly what upper-path generati= on > thinks it should put into fdw_exprs, but is it really only Params? Oh, this is interesting: regression=3D# explain verbose = select exists(select c1 from ft4) as c, avg(c1) from ft4 where ft4.c1 =3D= 42; QUERY PLAN = = --------------------------------------------------------------------------= --------- Foreign Scan (cost=3D200.07..246.67 rows=3D1 width=3D33) Output: ($0), (avg(ft4.c1)) Relations: Aggregate on (public.ft4) Remote SQL: SELECT $1::boolean, avg(c1) FROM "S 1"."T 3" WHERE ((c1 =3D= 42)) InitPlan 1 (returns $0) -> Foreign Scan on public.ft4 ft4_1 (cost=3D100.00..212.39 rows=3D3= 413 width=3D0) Remote SQL: SELECT NULL FROM "S 1"."T 3" (7 rows) That would crash if I tried to execute it, but: regression=3D# explain verbose = select case when exists(select c1 from ft4) then 1 else 2 end as c, avg(c= 1) from ft4 where ft4.c1 =3D 42; QUERY PLAN = = --------------------------------------------------------------------------= --------- Foreign Scan (cost=3D200.07..246.67 rows=3D1 width=3D36) Output: CASE WHEN $0 THEN 1 ELSE 2 END, (avg(ft4.c1)) Relations: Aggregate on (public.ft4) Remote SQL: SELECT avg(c1) FROM "S 1"."T 3" WHERE ((c1 =3D 42)) InitPlan 1 (returns $0) -> Foreign Scan on public.ft4 ft4_1 (cost=3D100.00..212.39 rows=3D3= 413 width=3D0) Remote SQL: SELECT NULL FROM "S 1"."T 3" (7 rows) That's just fine. So there is something stupid happening in creation of the fdw_scan_tlist when a relation tlist item is a bare Param, which doesn't happen if the same Param is buried in a larger expression. regards, tom lane