From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dmitry Dolgov <9erthalion6@gmail.com>
Cc: sean.johnston@edgeintelligence.com, pgsql-bugs@lists.postgresql.org, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Subject: Re: BUG #15781: subselect on foreign table (postgres_fdw) can crash (segfault)
Date: Thu, 25 Apr 2019 16:36:14 -0400
Message-ID: <30638.1556224574@sss.pgh.pa.us> (raw)
In-Reply-To: <30149.1556224055@sss.pgh.pa.us>
References: <15781-2601b1002bad087c@postgresql.org>
<25734.1556216681@sss.pgh.pa.us>
<CA+q6zcXXYdee8vyjxNqk7SPXhwSz9SrpDNTQDF=Yz_0C8LGgzw@mail.gmail.com>
<30149.1556224055@sss.pgh.pa.us>
I wrote:
> 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?
Oh, this is interesting:
regression=# explain verbose
select exists(select c1 from ft4) as c, avg(c1) from ft4 where ft4.c1 = 42;
QUERY PLAN
-----------------------------------------------------------------------------------
Foreign Scan (cost=200.07..246.67 rows=1 width=33)
Output: ($0), (avg(ft4.c1))
Relations: Aggregate on (public.ft4)
Remote SQL: SELECT $1::boolean, avg(c1) FROM "S 1"."T 3" WHERE ((c1 = 42))
InitPlan 1 (returns $0)
-> Foreign Scan on public.ft4 ft4_1 (cost=100.00..212.39 rows=3413 width=0)
Remote SQL: SELECT NULL FROM "S 1"."T 3"
(7 rows)
That would crash if I tried to execute it, but:
regression=# explain verbose
select case when exists(select c1 from ft4) then 1 else 2 end as c, avg(c1) from ft4 where ft4.c1 = 42;
QUERY PLAN
-----------------------------------------------------------------------------------
Foreign Scan (cost=200.07..246.67 rows=1 width=36)
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 = 42))
InitPlan 1 (returns $0)
-> Foreign Scan on public.ft4 ft4_1 (cost=100.00..212.39 rows=3413 width=0)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, 9erthalion6@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: BUG #15781: subselect on foreign table (postgres_fdw) can crash (segfault)
In-Reply-To: <30638.1556224574@sss.pgh.pa.us>
References: <15781-2601b1002bad087c@postgresql.org> <25734.1556216681@sss.pgh.pa.us> <CA+q6zcXXYdee8vyjxNqk7SPXhwSz9SrpDNTQDF=Yz_0C8LGgzw@mail.gmail.com> <30149.1556224055@sss.pgh.pa.us> <30638.1556224574@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox