Skip to content

Commit 21b1634

Browse files
committed
Fix heap_multi_insert to set t_self field in the caller's tuples.
If tuples were toasted, heap_multi_insert didn't update the ctid on the original tuples. This caused a failure if there was an after trigger (including a foreign key), on the table, and a tuple got toasted. Per off-list report and test case from Ted Phelps
1 parent b4e3633 commit 21b1634

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/backend/access/heap/heapam.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,6 +2291,14 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
22912291
CacheInvalidateHeapTuple(relation, heaptuples[i], NULL);
22922292
}
22932293

2294+
/*
2295+
* Copy t_self fields back to the caller's original tuples. This does
2296+
* nothing for untoasted tuples (tuples[i] == heaptuples[i)], but it's
2297+
* probably faster to always copy than check.
2298+
*/
2299+
for (i = 0; i < ntuples; i++)
2300+
tuples[i]->t_self = heaptuples[i]->t_self;
2301+
22942302
pgstat_count_heap_insert(relation, ntuples);
22952303
}
22962304

0 commit comments

Comments
 (0)