Re: BUG #19484: Segmentation fault triggered by FDW
Matheus Alcantara <matheusssilv97@gmail.com>
From: "Matheus Alcantara" <matheusssilv97@gmail.com>
To: "Rafia Sabih" <rafia.pghackers@gmail.com>
Cc: "Ayush Tiwari" <ayushtiwari.slg01@gmail.com>, <798604270@qq.com>,
<pgsql-bugs@lists.postgresql.org>, "Etsuro Fujita"
<etsuro.fujita@gmail.com>
Date: 2026-06-09T15:10:42Z
Lists: pgsql-bugs
Attachments
- 0001-Re-index-ModifyTable-FDW-arrays-when-pruning-result-.patch (text/plain) patch 0001
On Sat May 30, 2026 at 3:18 AM -03, Rafia Sabih wrote: > A good catch. However there is one issue that remains here, > in show_modifytable_info still is using the old index here fdw_private = > (List *) list_nth(node->fdwPrivLists, j) i.e. the one before pruning. > In fact I found a scenario where it is causing crash, try this > > create table fdw_part_update2 (a int not null, b int) partition by list (a); > create table fdw_part_update2_p1 partition of fdw_part_update2 for values > in (1); > create table fdw_part_update2_remote (a int not null, b int); > create foreign table fdw_part_update2_p2 partition of fdw_part_update2 > for values in (2) > server loopback options (table_name 'fdw_part_update2_remote'); > insert into fdw_part_update2_p1 values (1, 10); > insert into fdw_part_update2_remote values (2, 20); > set plan_cache_mode = force_generic_plan; > prepare fdw_part_upd2(int) as > update fdw_part_update2 set b = b + random()::int * 0 + 1 where a = $1 > returning tableoid::regclass, a, b; > execute fdw_part_upd2(2); > explain (analyze, verbose, costs off, timing off, summary off) > execute fdw_part_upd2(2); > > Please find the attached file for the patch to fix this. This patch applies > over the earlier patch (given by Ayush) in this thread. > Thanks for catching this, Rafia. The fix is correct — show_modifytable_info() was indeed still reading from node->fdwPrivLists using the post-pruning index j, which causes an out-of-bounds access when partitions are pruned. I think both patches should be squashed into a single one since they fix the same underlying issue. I've done this locally and also ran pg_indent over the result. Attached is the combined patch. One minor naming observation: the new fdwPrivLists field in ModifyTableState doesn't follow the mt_ prefix convention used by the other re-indexed lists (mt_updateColnosLists, mt_mergeActionLists, mt_mergeJoinConditions). Should we rename it to mt_fdwPrivLists for consistency? -- 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