postgresql/src/include
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 calculation of members_size in pg_get_multixact_stats() 2026-05-26 13:49:04 +09:00
archive Update copyright for 2026 2026-01-01 13:24:10 -05:00
backup Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
bootstrap Reduce header inclusions via execnodes.h 2026-03-16 14:34:57 +01:00
catalog Nail pg_parameter_acl in relcache. 2026-06-23 12:19:52 -07:00
commands Disallow direct use of the pgrepack logical decoding plugin 2026-06-09 20:12:55 +02:00
common Don't accept length of -1 in pg_locale.h APIs. 2026-05-15 11:09:15 -07:00
datatype Update copyright for 2026 2026-01-01 13:24:10 -05:00
executor Revert "Enable fast default for domains with non-volatile constraints" 2026-06-08 14:20:39 -04:00
fe_utils psql: Tighten heuristics for BEGIN/END within CREATE SCHEMA. 2026-06-23 14:12:03 -04:00
foreign Add support for importing statistics from remote servers. 2026-04-08 19:15:00 +09:00
jit Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
lib Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
libpq Set notice receiver before libpq connection startup completes 2026-05-23 00:25:48 +09:00
mb Remove MULE_INTERNAL encoding. 2026-04-08 17:40:06 +12:00
nodes Re-index ModifyTable FDW arrays when pruning result relations 2026-06-24 08:59:22 +09:00
optimizer Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
parser Fix parsing of parenthesised OLD/NEW in RETURNING list. 2026-06-11 12:08:47 +01:00
partitioning Update copyright for 2026 2026-01-01 13:24:10 -05:00
pch Update copyright for 2026 2026-01-01 13:24:10 -05:00
port Remove support for 8 byte tear free read/write on 32-bit 2026-05-18 08:59:59 -07:00
portability pg_test_timing: Show additional TSC clock source debug info 2026-05-16 11:51:34 -04:00
postmaster Fix syslogger NULL-pointer-dereference in EXEC_BACKEND 2026-06-08 19:49:54 +02:00
regex Harden our regex engine against integer overflow in size calculations. 2026-05-11 05:13:46 -07:00
replication Disable logical decoding after REPACK (CONCURRENTLY) 2026-05-27 20:11:29 +02:00
rewrite Fix bogus calls in remove_self_join_rel() 2026-04-27 10:40:37 +09:00
snowball Update to latest Snowball sources. 2026-01-05 15:22:37 -05:00
statistics Add support for importing statistics from remote servers. 2026-04-08 19:15:00 +09:00
storage Revert "Allow logical replication snapshots to be database-specific" 2026-05-23 21:33:19 -07:00
tcop Avoid blocking indefinitely while finishing walsender shutdown 2026-05-01 12:12:44 +09:00
tsearch Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
utils Fix PANIC with track_functions due to concurrent drop of pgstats entries 2026-06-18 11:49:30 +09:00
.gitignore Use <stdint.h> and <inttypes.h> for c.h integers. 2024-12-04 15:05:38 +13:00
c.h Ensure USE_AVX... symbols are not defined if not building for x86_64. 2026-06-04 10:37:25 -04:00
fmgr.h Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
funcapi.h Remove bits* typedefs. 2026-03-30 16:12:08 -05:00
getopt_long.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
Makefile Fix build inconsistency due to the generation of wait-event code 2026-02-02 08:02:39 +09:00
meson.build Ensure that all three build methods install the same set of files. 2026-02-16 15:20:15 -05:00
miscadmin.h Fix md5_password_warnings for role and database settings 2026-06-12 08:32:39 +09:00
pg_config.h.in Add errdetail() with PID and UID about source of termination signal. 2026-04-07 10:22:33 -04:00
pg_config_manual.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_getopt.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_trace.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgstat.h Fix double-free in pg_stat_autovacuum_scores. 2026-04-09 13:07:06 -05:00
pgtar.h Harden astreamer tar parsing logic against archives it can't handle. 2026-04-02 12:20:36 -04:00
pgtime.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
port.h Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
postgres.h Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
postgres_ext.h Move pg_int64 back to postgres_ext.h 2025-09-16 10:48:56 +02:00
postgres_fe.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
varatt.h Improve type handling of varlena structures 2026-02-11 07:33:24 +09:00
windowapi.h Update copyright for 2026 2026-01-01 13:24:10 -05:00