pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedpostgres_fdw: Fix crash when estimating joins with functions
3+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2026-09-10 3430fba3b0 postgres_fdw: Fix crash when estimating joins with functions
* postgres_fdw: Fix crash when estimating joins with functions
@ 2026-09-09 14:02 Fujii Masao <masao.fujii@gmail.com>
2026-09-09 15:09 ` Re: postgres_fdw: Fix crash when estimating joins with functions Alexander Pyhalov <a.pyhalov@postgrespro.ru>
0 siblings, 1 reply; 3+ messages in thread
From: Fujii Masao @ 2026-09-09 14:02 UTC (permalink / raw)
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Hi,
On master, I found that the following causes a segmentation fault:
CREATE EXTENSION postgres_fdw;
CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw;
CREATE USER MAPPING FOR PUBLIC SERVER loopback;
CREATE TABLE t (i int);
CREATE FOREIGN TABLE ft (i int) SERVER loopback
OPTIONS (table_name 't', use_remote_estimate 'true');
EXPLAIN SELECT * FROM generate_series(1, 3) g JOIN ft ON ft.i = g;
This crash seems to occur because init_func_stub_fpinfo() forgets to copy
the user mapping to the function-side stub, leaving it NULL. The NULL
mapping is then passed to GetConnection() when requesting a remote
estimate, causing the segmentation fault.
This seems to have been introduced by commit 0ee83dd4a99.
The attached patch fixes this by also copying the user mapping from the
foreign side.
Regards,
--
Fujii Masao
Attachments:
v1-0001-postgres_fdw-Fix-crash-when-estimating-joins-with.patch (application/octet-stream, 1.9K) download
From 71677685b933aeec6b87549a7a8f448ff9de7bc2 Mon Sep 17 00:00:00 2001
From: Fujii Masao <fujii@postgresql.org>
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: postgres_fdw: Fix crash when estimating joins with functions
2026-09-09 14:02 postgres_fdw: Fix crash when estimating joins with functions Fujii Masao <masao.fujii@gmail.com>
@ 2026-09-09 15:09 ` Alexander Pyhalov <a.pyhalov@postgrespro.ru>
2026-09-10 00:48 ` Re: postgres_fdw: Fix crash when estimating joins with functions Fujii Masao <masao.fujii@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Alexander Pyhalov @ 2026-09-09 15:09 UTC (permalink / raw)
To: Fujii Masao <masao.fujii@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Fujii Masao писал(а) 2026-09-09 17:02:
> Hi,
>
> On master, I found that the following causes a segmentation fault:
>
> CREATE EXTENSION postgres_fdw;
> CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw;
> CREATE USER MAPPING FOR PUBLIC SERVER loopback;
> CREATE TABLE t (i int);
> CREATE FOREIGN TABLE ft (i int) SERVER loopback
> OPTIONS (table_name 't', use_remote_estimate 'true');
> EXPLAIN SELECT * FROM generate_series(1, 3) g JOIN ft ON ft.i = g;
>
> This crash seems to occur because init_func_stub_fpinfo() forgets to
> copy
> the user mapping to the function-side stub, leaving it NULL. The NULL
> mapping is then passed to GetConnection() when requesting a remote
> estimate, causing the segmentation fault.
>
> This seems to have been introduced by commit 0ee83dd4a99.
>
> The attached patch fixes this by also copying the user mapping from the
> foreign side.
>
> Regards,
Hi. Thanks. Looks good to me.
--
Best regards,
Alexander Pyhalov,
Postgres Professional
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: postgres_fdw: Fix crash when estimating joins with functions
2026-09-09 14:02 postgres_fdw: Fix crash when estimating joins with functions Fujii Masao <masao.fujii@gmail.com>
2026-09-09 15:09 ` Re: postgres_fdw: Fix crash when estimating joins with functions Alexander Pyhalov <a.pyhalov@postgrespro.ru>
@ 2026-09-10 00:48 ` Fujii Masao <masao.fujii@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Fujii Masao @ 2026-09-10 00:48 UTC (permalink / raw)
To: Alexander Pyhalov <a.pyhalov@postgrespro.ru>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, Sep 10, 2026 at 12:09 AM Alexander Pyhalov
<a.pyhalov@postgrespro.ru> wrote:
> Hi. Thanks. Looks good to me.
Thanks for the review! I've pushed the patch.
Regards,
--
Fujii Masao
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-09-10 00:48 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-09 14:02 postgres_fdw: Fix crash when estimating joins with functions Fujii Masao <masao.fujii@gmail.com>
2026-09-09 15:09 ` Alexander Pyhalov <a.pyhalov@postgrespro.ru>
2026-09-10 00:48 ` Fujii Masao <masao.fujii@gmail.com>
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