postgres.git / summary / log / commit / refs

commit    3430fba3b0f0655e203a4b03dd531d7bcad86ff3
Author:   Fujii Masao <fujii@postgresql.org>
Date:     Thu Sep 10 00:46:44 2026 +0000

    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


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; [parent: cb298616463d]