Skip to content

Commit 9dde24e

Browse files
committed
Back-patch fix for oversize index tuples during index creation.
1 parent 6580668 commit 9dde24e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/backend/access/nbtree/nbtsort.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*
77
* IDENTIFICATION
8-
* $Id: nbtsort.c,v 1.40.2.1 1999/08/02 05:24:41 scrappy Exp $
8+
* $Id: nbtsort.c,v 1.40.2.2 2000/01/08 21:47:31 tgl Exp $
99
*
1010
* NOTES
1111
*
@@ -904,6 +904,23 @@ _bt_buildadd(Relation index, void *pstate, BTItem bti, int flags)
904904
pgspc = PageGetFreeSpace(npage);
905905
btisz = BTITEMSZ(bti);
906906
btisz = MAXALIGN(btisz);
907+
908+
/*
909+
* Check whether the item can fit on a btree page at all.
910+
* (Eventually, we ought to try to apply TOAST methods if not.)
911+
* We actually need to be able to fit three items on every page,
912+
* so restrict any one item to 1/3 the per-page available space.
913+
* Note that at this point, btisz doesn't include the ItemId.
914+
*
915+
* NOTE: similar code appears in _bt_insertonpg() to defend against
916+
* oversize items being inserted into an already-existing index.
917+
* But during creation of an index, we don't go through there.
918+
*/
919+
if (btisz > (PageGetPageSize(npage)-sizeof(PageHeaderData)-MAXALIGN(sizeof(BTPageOpaqueData)))/3 - sizeof(ItemIdData))
920+
elog(ERROR, "btree: index item size %d exceeds maximum %d",
921+
btisz,
922+
(PageGetPageSize(npage)-sizeof(PageHeaderData)-MAXALIGN(sizeof(BTPageOpaqueData)))/3 - sizeof(ItemIdData));
923+
907924
if (pgspc < btisz)
908925
{
909926
Buffer obuf = nbuf;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy