Skip to content

Commit d1e241c

Browse files
nbtree: Demote minus infinity "can't happen" error.
Only a very basic logic bug in a _bt_insertonpg() caller could lead to a violation of this invariant. Besides, any newitemoff used for an internal page is sanitized using other "can't happen" errors in _bt_getstackbuf() or its callers, before _bt_insertonpg() even gets called. Also, move the error/assertion from the insert-without-split path of _bt_insertonpg() to the top of the same function. There is no reason why this invariant only applies to insertions that happen to not result in a page split; cover every insertion. The assertion naturally belongs next to the existing generic assertions that document relatively high-level invariants for the item being inserted.
1 parent cacef17 commit d1e241c

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/backend/access/nbtree/nbtinsert.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,14 @@ _bt_insertonpg(Relation rel,
10821082
IndexRelationGetNumberOfKeyAttributes(rel));
10831083
Assert(!BTreeTupleIsPosting(itup));
10841084

1085+
/*
1086+
* Every internal page should have exactly one negative infinity item at
1087+
* all times. Only _bt_split() and _bt_newroot() should add items that
1088+
* become negative infinity items through truncation, since they're the
1089+
* only routines that allocate new internal pages.
1090+
*/
1091+
Assert(P_ISLEAF(lpageop) || newitemoff > P_FIRSTDATAKEY(lpageop));
1092+
10851093
/* The caller should've finished any incomplete splits already. */
10861094
if (P_INCOMPLETE_SPLIT(lpageop))
10871095
elog(ERROR, "cannot insert to incompletely split page %u",
@@ -1212,18 +1220,6 @@ _bt_insertonpg(Relation rel,
12121220
}
12131221
}
12141222

1215-
/*
1216-
* Every internal page should have exactly one negative infinity item
1217-
* at all times. Only _bt_split() and _bt_newroot() should add items
1218-
* that become negative infinity items through truncation, since
1219-
* they're the only routines that allocate new internal pages. Do not
1220-
* allow a retail insertion of a new item at the negative infinity
1221-
* offset.
1222-
*/
1223-
if (!P_ISLEAF(lpageop) && newitemoff == P_FIRSTDATAKEY(lpageop))
1224-
elog(ERROR, "cannot insert second negative infinity item in block %u of index \"%s\"",
1225-
itup_blkno, RelationGetRelationName(rel));
1226-
12271223
/* Do the update. No ereport(ERROR) until changes are logged */
12281224
START_CRIT_SECTION();
12291225

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