summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2000-01-08 21:47:31 +0000
committerTom Lane2000-01-08 21:47:31 +0000
commit9dde24e272e05108e498f517633a861648f0c7c3 (patch)
tree5c6ab72aeb6a87def96a01455a9e8529b9e3b083
parent65806683924e0932a06cab1746bd815f2da8a716 (diff)
Back-patch fix for oversize index tuples during index creation.
-rw-r--r--src/backend/access/nbtree/nbtsort.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index 54899c016a9..a257e0c8d8e 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -5,7 +5,7 @@
*
*
* IDENTIFICATION
- * $Id: nbtsort.c,v 1.40.2.1 1999/08/02 05:24:41 scrappy Exp $
+ * $Id: nbtsort.c,v 1.40.2.2 2000/01/08 21:47:31 tgl Exp $
*
* NOTES
*
@@ -904,6 +904,23 @@ _bt_buildadd(Relation index, void *pstate, BTItem bti, int flags)
pgspc = PageGetFreeSpace(npage);
btisz = BTITEMSZ(bti);
btisz = MAXALIGN(btisz);
+
+ /*
+ * Check whether the item can fit on a btree page at all.
+ * (Eventually, we ought to try to apply TOAST methods if not.)
+ * We actually need to be able to fit three items on every page,
+ * so restrict any one item to 1/3 the per-page available space.
+ * Note that at this point, btisz doesn't include the ItemId.
+ *
+ * NOTE: similar code appears in _bt_insertonpg() to defend against
+ * oversize items being inserted into an already-existing index.
+ * But during creation of an index, we don't go through there.
+ */
+ if (btisz > (PageGetPageSize(npage)-sizeof(PageHeaderData)-MAXALIGN(sizeof(BTPageOpaqueData)))/3 - sizeof(ItemIdData))
+ elog(ERROR, "btree: index item size %d exceeds maximum %d",
+ btisz,
+ (PageGetPageSize(npage)-sizeof(PageHeaderData)-MAXALIGN(sizeof(BTPageOpaqueData)))/3 - sizeof(ItemIdData));
+
if (pgspc < btisz)
{
Buffer obuf = nbuf;