Back-patch fix for 'btree: failed to add item to the page in _bt_sort (2)'
authorTom Lane <[email protected]>
Thu, 4 Jan 2001 21:51:49 +0000 (21:51 +0000)
committerTom Lane <[email protected]>
Thu, 4 Jan 2001 21:51:49 +0000 (21:51 +0000)
failure during index creation.  This problem should be gone in current
sources, but I just thought I'd commit the 7.0.* patch in case anyone
else needs it.

src/backend/access/nbtree/nbtsort.c

index cef2c45dd45cf419c26ff7124fa46aa59e24f934..5843d8642989f018197914f0642683814497f347 100644 (file)
@@ -321,7 +321,7 @@ _bt_buildadd(Relation index, Size keysz, ScanKey scankey,
                         btisz,
                         (PageGetPageSize(npage) - sizeof(PageHeaderData) - MAXALIGN(sizeof(BTPageOpaqueData))) /3 - sizeof(ItemIdData));
 
-       if (pgspc < btisz)
+       while (pgspc < btisz)
        {
                Buffer          obuf = nbuf;
                Page            opage = npage;
@@ -436,6 +436,13 @@ _bt_buildadd(Relation index, Size keysz, ScanKey scankey,
                 * we aren't locking).
                 */
                _bt_wrtbuf(index, obuf);
+
+               /*
+                * Recompute pgspc and loop back to check free space again.  If
+                * we were forced to split at a bad split point, we might need
+                * to split again.
+                */
+               pgspc = PageGetFreeSpace(npage);
        }
 
        /*