Re: BUG #19484: Segmentation fault triggered by FDW
Matheus Alcantara <matheusssilv97@gmail.com>
From: "Matheus Alcantara" <matheusssilv97@gmail.com>
To: "Ayush Tiwari" <ayushtiwari.slg01@gmail.com>, <798604270@qq.com>,
<pgsql-bugs@lists.postgresql.org>, "Etsuro Fujita"
<etsuro.fujita@gmail.com>
Date: 2026-05-22T20:56:05Z
Lists: pgsql-bugs
On Wed May 20, 2026 at 9:37 AM -03, Ayush Tiwari wrote: > I reproduced the crash on master. The plan EXPLAIN under > force_generic_plan shows runtime pruning is in effect: > > Update on pt > Foreign Update on pt_p2 pt_2 > -> Append > Subplans Removed: 1 > -> Foreign Update on pt_p2 pt_2 > > The SEGV happens inside postgresBeginForeignModify() because > ExecInitModifyTable() builds re-indexed "kept" copies of several > parallel per-result-relation lists after dropping pruned relations - > withCheckOptionLists, returningLists, updateColnosLists, > mergeActionLists and mergeJoinConditions, however two members were > missed: > > - node->fdwPrivLists, read with list_nth(node->fdwPrivLists, i) when > BeginForeignModify() is called, and > - node->fdwDirectModifyPlans, checked with bms_is_member(i, ...) when > setting ri_usesFdwDirectModify. > > Both were still indexed against the original (pre-pruning) positions > while the surrounding loop's "i" is now the kept position. When the > foreign partition's kept-index no longer matched its original index, > BeginForeignModify() got the wrong fdw_private and crashed. > > Attached patch builds re-indexed kept copies for these two arrays in > the same loop as the other parallel lists, and uses them at the two > call sites. > Hi, thanks for the patch. This issue started on version 18 by commit cbc127917e0. The patch fixes the issue and it make sense to me. One a minor comment is that I think pg_indent is needed on nodeModifyTable.c -- Matheus Alcantara EDB: https://www.enterprisedb.com
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Avoid ABI break in ModifyTableState from the FDW pruning fix
- bba4e095d250 18 (unreleased) landed
-
Re-index ModifyTable FDW arrays when pruning result relations
- b43f8aa4cb30 19 (unreleased) landed
- 1ef917e3a61a 18 (unreleased) landed
-
Fix universal builds on MacOS
- 901ed9b352b4 19 (unreleased) cited
-
Track unpruned relids to avoid processing pruned relations
- cbc127917e04 18.0 cited