Re: BUG #15781: subselect on foreign table (postgres_fdw) can crash (segfault)
Tom Lane <tgl@sss.pgh.pa.us>
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>
Date: 2019-04-25T20:36:14Z
Lists: pgsql-bugs, pgsql-hackers
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
Commits
-
Avoid postgres_fdw crash for a targetlist entry that's just a Param.
- c25e638b1800 10.8 landed
- 8cad5adb9c0b 12.0 landed
- 1bf52d68800e 11.3 landed