Re: BUG #15781: subselect on foreign table (postgres_fdw) can crash (segfault) - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #15781: subselect on foreign table (postgres_fdw) can crash (segfault)
Date
Msg-id 30638.1556224574@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #15781: subselect on foreign table (postgres_fdw) can crash (segfault)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
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



pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #15781: subselect on foreign table (postgres_fdw) can crash (segfault)
Next
From: PG Bug reporting form
Date:
Subject: BUG #15782: Error in pgAdmin4.5