postgresql/contrib
Amit Langote 1ef917e3a6 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-23 21:08:50 +09:00
..
amcheck amcheck: Use correct varlena size accessor in bt_normalize_tuple() 2026-06-14 04:05:50 +03:00
auth_delay Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
auto_explain Allow resetting unknown custom GUCs with reserved prefixes. 2025-08-01 16:52:11 -05:00
basebackup_to_shell Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
basic_archive basic_archive: Allow archive directory to be missing at startup. 2026-03-02 13:12:25 -06:00
bloom Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
bool_plperl Fix erroneous construction of functions' dependencies on transforms. 2025-04-07 13:31:37 -04:00
btree_gin Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
btree_gist Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:43:42 +13:00
citext Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
cube Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
dblink postgres_fdw, dblink: Validate use_scram_passthrough values 2026-05-28 20:58:45 +09:00
dict_int Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
dict_xsyn Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:43:42 +13:00
earthdistance Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
file_fdw Fix bogus ctid requirement for dummy-root partitioned targets 2026-01-23 10:23:26 +09:00
fuzzystrmatch Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
hstore hstore: Fix NULL pointer dereference with receive function 2026-02-17 08:41:30 +09:00
hstore_plperl hstore_plperl: Add CHECK_FOR_INTERRUPTS() in reference-unwinding loop. 2026-06-18 12:22:55 -04:00
hstore_plpython Use palloc_array() in a few more places to avoid overflow 2026-05-11 21:28:46 +03:00
intagg Update copyright for 2025 2025-01-01 11:21:55 -05:00
intarray Fix missed ReleaseVariableStats() in intarray's _int_matchsel(). 2026-05-25 18:15:49 -04:00
isn Revert a few small patches that were intended for version 19. 2025-06-11 15:10:12 -07:00
jsonb_plperl jsonb_plperl, jsonb_plpython: Fix unguarded recursion and loops. 2026-06-17 11:04:41 -04:00
jsonb_plpython jsonb_plperl, jsonb_plpython: Fix unguarded recursion and loops. 2026-06-17 11:04:41 -04:00
lo Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
ltree Fix int32 overflow in ltree_compare() 2026-06-16 09:31:08 +03:00
ltree_plpython Remove circular #include's between plpython.h and plpy_util.h. 2025-04-27 11:43:02 -04:00
oid2name Update copyright for 2025 2025-01-01 11:21:55 -05:00
pageinspect Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:43:42 +13:00
passwordcheck Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
pg_buffercache pgindent fix for 3fccbd94cb 2026-01-27 00:28:01 +01:00
pg_freespacemap Prevent assertion failure in contrib/pg_freespacemap. 2025-03-27 13:20:23 -04:00
pg_logicalinspect Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
pg_overexplain Fix pg_overexplain to emit valid output with RANGE_TABLE option. 2026-04-16 13:49:39 +09:00
pg_prewarm Allow role created by new test to log in on Windows. 2025-10-18 18:36:21 -04:00
pg_stat_statements Avoid memory leak on error while parsing pg_stat_statements dump file 2026-03-27 12:21:29 +02:00
pg_surgery pg_surgery: Fix off-by-one bug with heap offset 2026-06-06 08:16:40 +09:00
pg_trgm Fix expanding 'bounds' in pg_trgm's calc_word_similarity() function 2026-02-20 11:56:50 +02:00
pg_visibility read_stream: Introduce and use optional batchmode support 2025-03-30 18:36:41 -04:00
pg_walinspect Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
pgcrypto pgcrypto: avoid recursive ResourceOwnerForget(). 2026-06-22 12:59:16 -04:00
pgrowlocks Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
pgstattuple pgstattuple: Improve reports generated for indexes (hash, gist, btree) 2025-10-02 11:09:10 +09:00
postgres_fdw Re-index ModifyTable FDW arrays when pruning result relations 2026-06-23 21:08:50 +09:00
seg seg: Fix seg_out() to preserve the upper boundary's certainty indicator 2026-06-11 12:34:26 +03:00
sepgsql Update expected output for contrib/sepgsql's regression tests. 2025-10-23 17:47:10 -04:00
spi refint: Remove plan cache. 2026-06-05 12:08:05 -05:00
sslinfo Fix compilation with OpenSSL 4 2026-06-12 13:57:22 +02:00
start-scripts Remove gratuitous references to postmaster program 2023-01-26 10:48:32 +01:00
tablefunc Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
tcn Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
test_decoding Fix re-distributing previously distributed invalidation messages during logical decoding. 2025-06-16 17:36:01 -07:00
tsm_system_rows Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
tsm_system_time Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
unaccent Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:43:42 +13:00
uuid-ossp Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
vacuumlo Update copyright for 2025 2025-01-01 11:21:55 -05:00
xml2 xml2: Fix crash with namespace nodes in xpath_nodeset() 2026-06-11 14:29:22 +09:00
contrib-global.mk Respect TEMP_CONFIG when pg_regress_check and friends are called 2016-02-27 12:28:21 -05:00
Makefile pg_overexplain: Additional EXPLAIN options for debugging. 2025-03-26 13:52:21 -04:00
meson.build pg_overexplain: Additional EXPLAIN options for debugging. 2025-03-26 13:52:21 -04:00
README Rename 'gmake' to 'make' in docs and recommended commands 2014-02-12 17:29:19 -05:00

The PostgreSQL contrib tree
---------------------------

This subtree contains porting tools, analysis utilities, and plug-in
features that are not part of the core PostgreSQL system, mainly
because they address a limited audience or are too experimental to be
part of the main source tree.  This does not preclude their
usefulness.

User documentation for each module appears in the main SGML
documentation.

When building from the source distribution, these modules are not
built automatically, unless you build the "world" target.  You can
also build and install them all by running "make all" and "make
install" in this directory; or to build and install just one selected
module, do the same in that module's subdirectory.

Some directories supply new user-defined functions, operators, or
types.  To make use of one of these modules, after you have installed
the code you need to register the new SQL objects in the database
system by executing a CREATE EXTENSION command.  In a fresh database,
you can simply do

    CREATE EXTENSION module_name;

See the PostgreSQL documentation for more information about this
procedure.