]> granicus.if.org Git - postgresql/commitdiff
Fix bug in freespace calculation in heap_multi_insert().
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 16 May 2012 11:10:29 +0000 (14:10 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 16 May 2012 11:13:06 +0000 (14:13 +0300)
If the amount of freespace on page was less than the amount reserved by
fillfactor, the calculation would underflow.

This fixes bug #6643 reported by Tomonari Katsumata.

src/backend/access/heap/heapam.c

index 7e4c8f52ab2a503cae4b0fd15d6be1fa0adb4bd5..0d6fe3f0acd38a87af759bd3d5196da504202486 100644 (file)
@@ -2159,7 +2159,7 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
                {
                        HeapTuple       heaptup = heaptuples[ndone + nthispage];
 
-                       if (PageGetHeapFreeSpace(page) - saveFreeSpace < MAXALIGN(heaptup->t_len))
+                       if (PageGetHeapFreeSpace(page) < MAXALIGN(heaptup->t_len) + saveFreeSpace)
                                break;
 
                        RelationPutHeapTuple(relation, buffer, heaptup);