/* Check that the tree has the same height in all branches */ if (GinPageIsLeaf(page))
{
ItemPointerData minItem; int nlist;
ItemPointerData *list; char tidrange_buf[MAXPGPATH];
ItemPointerSetMin(&minItem);
elog(DEBUG1, "page blk: %u, type leaf", stack->blkno);
/* *Ginpagerightboundhasasanevalueonlywhennotahighkey *ontherightmostpage(atagivenlevel).Fortherightmost *pagedoesnotstorethehighkeyexplicitly,andthevalueis *infinity.
*/ if (ItemPointerIsValid(&stack->parentkey) &&
rightlink != InvalidBlockNumber &&
!ItemPointerEquals(&stack->parentkey, &bound))
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\": posting tree page's high key (%u, %u) doesn't match the downlink on block %u (parent blk %u, key (%u, %u))",
RelationGetRelationName(rel),
ItemPointerGetBlockNumberNoCheck(&bound),
ItemPointerGetOffsetNumberNoCheck(&bound),
stack->blkno, stack->parentblk,
ItemPointerGetBlockNumberNoCheck(&stack->parentkey),
ItemPointerGetOffsetNumberNoCheck(&stack->parentkey))));
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
GinPostingTreeScanItem *ptr;
PostingItem *posting_item = GinDataPageGetPostingItem(page, i);
if (i == maxoff && rightlink == InvalidBlockNumber)
{ /* *Therightmostiteminthetreelevelhas(0,0)asthe *key
*/ if (ItemPointerGetBlockNumberNoCheck(&posting_item->key) != 0 ||
ItemPointerGetOffsetNumberNoCheck(&posting_item->key) != 0)
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\": rightmost posting tree page (blk %u) has unexpected last key (%u, %u)",
RelationGetRelationName(rel),
stack->blkno,
ItemPointerGetBlockNumberNoCheck(&posting_item->key),
ItemPointerGetOffsetNumberNoCheck(&posting_item->key))));
} elseif (i != FirstOffsetNumber)
{
PostingItem *previous_posting_item = GinDataPageGetPostingItem(page, i - 1);
if (ItemPointerCompare(&posting_item->key, &previous_posting_item->key) < 0)
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\" has wrong tuple order in posting tree, block %u, offset %u",
RelationGetRelationName(rel), stack->blkno, i)));
}
/* *Checkifthistupleisconsistentwiththedownlinkinthe *parent.
*/ if (i == maxoff && ItemPointerIsValid(&stack->parentkey) &&
ItemPointerCompare(&stack->parentkey, &posting_item->key) < 0)
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\": posting item exceeds parent's high key in postingTree internal page on block %u offset %u",
RelationGetRelationName(rel),
stack->blkno, i)));
/* This is an internal page, recurse into the child. */
ptr = (GinPostingTreeScanItem *) palloc(sizeof(GinPostingTreeScanItem));
ptr->depth = stack->depth + 1;
/* Check that the tree has the same height in all branches */ if (GinPageIsLeaf(page))
{ if (leafdepth == -1)
leafdepth = stack->depth; elseif (stack->depth != leafdepth)
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\": internal pages traversal encountered leaf page unexpectedly on block %u",
RelationGetRelationName(rel), stack->blkno)));
}
/* *Checkthattuplesineachpageareproperlyorderedandconsistent *withparenthighkey
*/
prev_tuple = NULL;
prev_attnum = InvalidAttrNumber; for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
ItemId iid = PageGetItemIdCareful(rel, stack->blkno, page, i);
IndexTuple idxtuple = (IndexTuple) PageGetItem(page, iid);
OffsetNumber current_attnum = gintuple_get_attrnum(&state, idxtuple);
GinNullCategory current_key_category;
Datum current_key;
if (MAXALIGN(ItemIdGetLength(iid)) != MAXALIGN(IndexTupleSize(idxtuple)))
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\" has inconsistent tuple sizes, block %u, offset %u",
RelationGetRelationName(rel), stack->blkno, i)));
/* We found it - make a final check before failing */ if (!stack->parenttup)
elog(NOTICE, "Unable to find parent tuple for block %u on block %u due to concurrent split",
stack->blkno, stack->parentblk); else
{
parent_key_attnum = gintuple_get_attrnum(&state, stack->parenttup);
parent_key = gintuple_get_key(&state,
stack->parenttup,
&parent_key_category);
/* *Checkifitisproperlyadjusted.Ifsucceed, *proceedtothenextkey.
*/ if (ginCompareAttEntries(&state, current_attnum, current_key,
current_key_category, parent_key_attnum,
parent_key, parent_key_category) > 0)
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\" has inconsistent records on page %u offset %u",
RelationGetRelationName(rel), stack->blkno, i)));
}
}
}
/* If this is an internal page, recurse into the child */ if (!GinPageIsLeaf(page))
{
GinScanItem *ptr;
ptr = (GinScanItem *) palloc(sizeof(GinScanItem));
ptr->depth = stack->depth + 1; /* last tuple in layer has no high key */ if (i == maxoff && rightlink == InvalidBlockNumber)
ptr->parenttup = NULL; else
ptr->parenttup = CopyIndexTuple(idxtuple);
ptr->parentblk = stack->blkno;
ptr->blkno = GinGetDownlink(idxtuple);
ptr->next = stack->next;
stack->next = ptr;
} /* If this item is a pointer to a posting tree, recurse into it */ elseif (GinIsPostingTree(idxtuple))
{
BlockNumber rootPostingTree = GinGetPostingTree(idxtuple);
gin_check_posting_tree_parent_keys_consistency(rel, rootPostingTree);
} else
{
ItemPointer ipd; int nipd;
ipd = ginReadTupleWithoutState(idxtuple, &nipd);
for (int j = 0; j < nipd; j++)
{ if (!OffsetNumberIsValid(ItemPointerGetOffsetNumber(&ipd[j])))
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\": posting list contains invalid heap pointer on block %u",
RelationGetRelationName(rel), stack->blkno)));
}
pfree(ipd);
}
if (ItemIdGetOffset(itemid) + ItemIdGetLength(itemid) >
BLCKSZ - MAXALIGN(sizeof(GinPageOpaqueData)))
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("line pointer points past end of tuple space in index \"%s\"",
RelationGetRelationName(rel)),
errdetail_internal("Index tid=(%u,%u) lp_off=%u, lp_len=%u lp_flags=%u.",
block, offset, ItemIdGetOffset(itemid),
ItemIdGetLength(itemid),
ItemIdGetFlags(itemid))));
/* *Verifythatlinepointerisn'tLP_REDIRECTorLP_UNUSEDorLP_DEAD, *sinceGINneverusesallthree.Verifythatlinepointerhasstorage, *too.
*/ if (ItemIdIsRedirected(itemid) || !ItemIdIsUsed(itemid) ||
ItemIdIsDead(itemid) || ItemIdGetLength(itemid) == 0)
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("invalid line pointer storage in index \"%s\"",
RelationGetRelationName(rel)),
errdetail_internal("Index tid=(%u,%u) lp_off=%u, lp_len=%u lp_flags=%u.",
block, offset, ItemIdGetOffset(itemid),
ItemIdGetLength(itemid),
ItemIdGetFlags(itemid))));
return itemid;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.