]> granicus.if.org Git - postgresql/commitdiff
Fix heap_multi_insert to set t_self field in the caller's tuples.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 13 Feb 2012 08:14:49 +0000 (10:14 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 13 Feb 2012 08:20:50 +0000 (10:20 +0200)
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

src/backend/access/heap/heapam.c

index 99a431a95ff0662c82de5dfbd253f00777ca2c7c..c910863e27384f5775376d97e7f5263ca17125d4 100644 (file)
@@ -2291,6 +2291,14 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
                        CacheInvalidateHeapTuple(relation, heaptuples[i], NULL);
        }
 
+       /*
+        * Copy t_self fields back to the caller's original tuples. This does
+        * nothing for untoasted tuples (tuples[i] == heaptuples[i)], but it's
+        * probably faster to always copy than check.
+        */
+       for (i = 0; i < ntuples; i++)
+               tuples[i]->t_self = heaptuples[i]->t_self;
+
        pgstat_count_heap_insert(relation, ntuples);
 }