summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-01-27 20:53:36 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-01-27 20:53:36 +0000
commit223cd82c1db13a9bf2f4d886abd6c7820b87512a (patch)
treea0f22531f52f31c43d1ca8bfc4e3f084ac4ed72e /src
parentcb476c1ec35590e5915ebf44ab2b3410cb844585 (diff)
Correct an old logic error in btree page splitting: when considering a split
exactly at the point where we need to insert a new item, the calculation used the wrong size for the "high key" of the new left page. This could lead to choosing an unworkable split, resulting in "PANIC: failed to add item to the left sibling" (or "right sibling") failure. Although this bug has been there a long time, it's very difficult to trigger a failure before 8.2, since there was generally a lot of free space on both sides of a chosen split. In 8.2, where the user-selected fill factor determines how much free space the code tries to leave, an unworkable split is much more likely. Report by Joe Conway, diagnosis and fix by Heikki Linnakangas.
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/nbtree/nbtinsert.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index c528460b622..beb543f0939 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.146 2006/11/11 01:14:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.146.2.1 2007/01/27 20:53:36 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1153,7 +1153,12 @@ _bt_findsplitloc(Relation rel,
/* need to try it both ways! */
_bt_checksplitloc(&state, offnum, leftfree, rightfree,
true, itemsz);
- /* here we are contemplating newitem as first on right */
+ /*
+ * Here we are contemplating newitem as first on right. In this
+ * case it, not the current item, will become the high key of the
+ * left page, and so we have to correct the allowance made above.
+ */
+ leftfree += (int) itemsz - (int) newitemsz;
_bt_checksplitloc(&state, offnum, leftfree, rightfree,
false, newitemsz);
}