From 71677685b933aeec6b87549a7a8f448ff9de7bc2 Mon Sep 17 00:00:00 2001 From: Fujii Masao Date: Wed, 9 Sep 2026 21:52:13 +0900 Subject: [PATCH v1] postgres_fdw: Fix crash when estimating joins with functions Commit 0ee83dd4a99 allowed postgres_fdw to push down inner joins between foreign tables and functions in FROM clauses to the remote server. However, planning such a join with use_remote_estimate enabled could cause a segmentation fault. For example, the following query crashed when ft had use_remote_estimate set to true: EXPLAIN SELECT * FROM generate_series(1, 3) g JOIN ft ON ft.i = g; The crash occurred because init_func_stub_fpinfo() copied the connection information and options from the foreign side to the function-side stub, but omitted the user mapping, leaving it NULL. When the function was the outer side of the join, the join inherited this NULL mapping and passed it to GetConnection() when requesting a remote estimate, causing a segmentation fault. Fix this by having init_func_stub_fpinfo() also copy the user mapping from the foreign side. --- contrib/postgres_fdw/postgres_fdw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index c731ee199e2..c02d7e7ec1d 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -6940,8 +6940,9 @@ init_func_stub_fpinfo(const PgFdwRelationInfo *fpinfo_foreign, stub->pushdown_safe = true; - /* Server-level options, inherited from the foreign side. */ + /* Connection information and options, inherited from the foreign side */ stub->server = fpinfo_foreign->server; + stub->user = fpinfo_foreign->user; stub->shippable_extensions = fpinfo_foreign->shippable_extensions; stub->fdw_startup_cost = fpinfo_foreign->fdw_startup_cost; stub->fdw_tuple_cost = fpinfo_foreign->fdw_tuple_cost; -- 2.55.0