agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: postgres_fdw: Fix crash when estimating joins with functions
Date: Thu, 10 Sep 2026 00:48:10 +0000
Message-ID: <E1x4SxV-00000004CiD-25AJ@gemulon.postgresql.org> (raw)

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.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Alexander Pyhalov <a.pyhalov@postgrespro.ru>
Discussion: https://postgr.es/m/CAHGQGwGE9xPzCke0C0r4omTkh-hU08aBd2j9oSA0FYmJLCf9jA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3430fba3b0f0655e203a4b03dd531d7bcad86ff3

Modified Files
--------------
contrib/postgres_fdw/postgres_fdw.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)



Message-ID: <E1x4SxV-00000004CiD-25AJ@gemulon.postgresql.org>
Permalink:  ../E1x4SxV-00000004CiD-25AJ@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x4SxV-00000004CiD-25AJ@gemulon.postgresql.org

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: fujii@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: postgres_fdw: Fix crash when estimating joins with functions
  In-Reply-To: <E1x4SxV-00000004CiD-25AJ@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox