]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Re-index ModifyTable FDW arrays when pruning result relations
authorAmit Langote <amitlan@postgresql.org>
Tue, 23 Jun 2026 12:07:13 +0000 (21:07 +0900)
committerAmit Langote <amitlan@postgresql.org>
Tue, 23 Jun 2026 23:59:22 +0000 (08:59 +0900)
commitb43f8aa4cb302c3f74fd1ed611e3548d4e03dce1
tree33030c8cb6c4554ea0ba754d09745a62bb91452d
parent4cc02b80774ecdc4cf2a2d5df09c07df36d68ca5
Re-index ModifyTable FDW arrays when pruning result relations

ExecInitModifyTable() rebuilds the per-result-relation lists after
dropping result relations removed by initial runtime pruning.  The
re-indexing was done for withCheckOptionLists, returningLists,
updateColnosLists, mergeActionLists and mergeJoinConditions, but
fdwPrivLists and fdwDirectModifyPlans were missed.  As a result, a
kept foreign result relation could be handed the wrong fdw_private,
or ri_usesFdwDirectModify could be set from the wrong plan index,
leading to wrong behavior or a crash in BeginForeignModify() and in
the direct-modify path.

show_modifytable_info() had the same problem: it indexed the
plan-ordered node->fdwPrivLists with the post-pruning executor
position, so once initial pruning removed a result relation it
could read a different relation's fdw_private (often a NIL entry),
producing wrong EXPLAIN output or a crash.

Fix by re-indexing fdwPrivLists and fdwDirectModifyPlans alongside
the other lists, saving the re-indexed private lists in
ModifyTableState.mt_fdwPrivLists and reading from there in both
nodeModifyTable.c and explain.c.

Reported-by: Chi Zhang <798604270@qq.com>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Author: Rafia Sabih <rafia.pghackers@gmail.com>
Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>
Reviewed-by: Etsuro Fujita <etsuro.fujita@gmail.com>
Discussion: https://postgr.es/m/19484-a3cb82c8cde3c8fa%40postgresql.org
Backpatch-through: 18
contrib/postgres_fdw/expected/postgres_fdw.out
contrib/postgres_fdw/sql/postgres_fdw.sql
src/backend/commands/explain.c
src/backend/executor/nodeModifyTable.c
src/include/nodes/execnodes.h