postgresql/src/backend
Amit Langote b43f8aa4cb 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
2026-06-24 08:59:22 +09:00
..
access Fix pgstat_count_io_op_time() calls passing incorrect information 2026-06-17 16:05:11 +09:00
archive Don't include wait_event.h in pgstat.h 2026-03-06 16:24:58 +01:00
backup Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
bootstrap Rework signal handler infrastructure to pass sender info as argument. 2026-04-15 07:30:34 -04:00
catalog Readable identity strings for property graph objects 2026-06-23 09:13:11 +02:00
commands Re-index ModifyTable FDW arrays when pruning result relations 2026-06-24 08:59:22 +09:00
executor Re-index ModifyTable FDW arrays when pruning result relations 2026-06-24 08:59:22 +09:00
foreign Remove bits* typedefs. 2026-03-30 16:12:08 -05:00
jit Update JIT tuple deforming code for virtual generated columns 2026-06-19 15:26:18 +12:00
lib Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
libpq Fix md5_password_warnings for role and database settings 2026-06-12 08:32:39 +09:00
main Update copyright for 2026 2026-01-01 13:24:10 -05:00
nodes IS JSON/JSON(): Protect against expressions uncoercible to text 2026-06-11 16:17:58 +02:00
optimizer Strip removed-relation references from PlaceHolderVars at join removal 2026-06-22 10:40:40 +09:00
parser Fix error message typo. 2026-06-17 12:43:07 +09:00
partitioning Reject degenerate SPLIT PARTITION with DEFAULT partition 2026-05-25 11:57:42 +03:00
po Translation updates 2026-06-01 12:13:54 +02:00
port Use "grep -E" not "egrep". 2026-05-13 12:07:19 -04:00
postmaster Fix comments on data checksum cost settings 2026-06-18 23:16:35 +02:00
regex Harden our regex engine against integer overflow in size calculations. 2026-05-11 05:13:46 -07:00
replication Fix misreporting of publisher sequence permissions during sync 2026-06-20 18:19:23 +09:00
rewrite Fix LATERAL references in GRAPH_TABLE with multi-label pattern 2026-06-05 09:27:51 +02:00
snowball Fix meson build of snowball code. 2026-01-05 16:51:36 -05:00
statistics Reject oversized MCV lists in pg_restore_extended_stats() 2026-06-16 15:14:58 +09:00
storage Make StandbyAcquireAccessExclusiveLock() more resilent with OOMs 2026-06-20 15:00:40 +09:00
tcop Simplify signature of ProcessStartupPacket() 2026-05-17 07:44:17 +09:00
tsearch dict_synonym.c: remove incorrect outlen. 2026-06-08 11:47:53 -07:00
utils Nail pg_parameter_acl in relcache. 2026-06-23 12:19:52 -07:00
.gitignore
common.mk
Makefile ssl: Serverside SNI support for libpq 2026-03-18 12:37:11 +01:00
meson.build Add CONCURRENTLY option to REPACK 2026-04-06 21:55:08 +02:00
nls.mk Create a separate file listing backend types 2025-09-26 15:21:49 +02:00