34 #include "catalog/pg_opfamily_d.h"
52 #define InvalidBtreeLevel ((uint32) InvalidBlockNumber)
53 #define BTreeTupleGetNKeyAtts(itup, rel) \
54 Min(IndexRelationGetNumberOfKeyAttributes(rel), BTreeTupleGetNAtts(itup, rel))
151 bool heapallindexed,
bool rootdescend,
156 bool heapkeyspace,
bool readonly,
bool heapallindexed,
157 bool rootdescend,
bool checkunique);
191 bool tupleIsAlive,
void *checkstate);
232 bool heapallindexed =
false;
233 bool checkunique =
false;
258 bool heapallindexed =
false;
259 bool rootdescend =
false;
260 bool checkunique =
false;
279 bool rootdescend,
bool checkunique)
286 int save_sec_context;
323 save_sec_context = -1;
349 errmsg(
"could not open parent table of index \"%s\"",
362 (
errcode(ERRCODE_INDEX_CORRUPTED),
363 errmsg(
"index \"%s\" lacks a main relation fork",
368 if (allequalimage && !heapkeyspace)
370 (
errcode(ERRCODE_INDEX_CORRUPTED),
371 errmsg(
"index \"%s\" metapage has equalimage field set on unsupported nbtree version",
375 bool has_interval_ops =
false;
379 has_interval_ops =
true;
381 (
errcode(ERRCODE_INDEX_CORRUPTED),
382 errmsg(
"index \"%s\" metapage incorrectly indicates that deduplication is safe",
385 ?
errhint(
"This is known of \"interval\" indexes last built on a version predating 2023-11.")
391 heapallindexed, rootdescend, checkunique);
421 if (rel->
rd_rel->relkind != RELKIND_INDEX ||
422 rel->
rd_rel->relam != BTREE_AM_OID)
424 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
425 errmsg(
"only B-Tree indexes are supported as targets for verification"),
426 errdetail(
"Relation \"%s\" is not a B-Tree index.",
431 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
432 errmsg(
"cannot access temporary tables of other sessions"),
433 errdetail(
"Index \"%s\" is associated with temporary relation.",
438 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
439 errmsg(
"cannot check index \"%s\"",
455 if (rel->
rd_rel->relpersistence != RELPERSISTENCE_UNLOGGED ||
460 (
errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
461 errmsg(
"cannot verify unlogged index \"%s\" during recovery, skipping",
492 bool readonly,
bool heapallindexed,
bool rootdescend,
503 elog(
DEBUG1,
"verifying consistency of tree structure for index \"%s\"",
506 elog(
DEBUG1,
"verifying consistency of tree structure for index \"%s\" with cross-level checks",
520 state->heaprel = heaprel;
521 state->heapkeyspace = heapkeyspace;
522 state->readonly = readonly;
523 state->heapallindexed = heapallindexed;
524 state->rootdescend = rootdescend;
525 state->checkunique = checkunique;
528 if (
state->heapallindexed)
543 (int64)
state->rel->rd_rel->reltuples);
548 state->heaptuplespresent = 0;
557 if (!
state->readonly)
579 errmsg(
"index \"%s\" cannot be verified using transaction snapshot",
589 if (
state->checkunique)
592 if (
state->indexinfo->ii_Unique)
595 state->snapshot = snapshot;
602 if (
state->rootdescend && !
state->heapkeyspace)
604 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
605 errmsg(
"cannot verify that tuples from index \"%s\" can each be found by an independent index search",
607 errhint(
"Only B-Tree version 4 indexes support rootdescend verification.")));
632 errdetail_internal(
"Fast root block %u (level %u) differs from true root block %u (level %u).",
655 (
errcode(ERRCODE_INDEX_CORRUPTED),
656 errmsg(
"index \"%s\" has no valid pages on level below %u or first level",
659 previouslevel = current.
level;
665 if (
state->heapallindexed)
708 elog(
DEBUG1,
"verifying that tuples from index \"%s\" are present in \"%s\"",
772 " (true root level)" : level.
level == 0 ?
" (leaf level)" :
"");
775 state->previncompletesplit =
false;
783 state->targetblock = current;
804 (
errcode(ERRCODE_INDEX_CORRUPTED),
805 errmsg(
"downlink or sibling link points to deleted block in index \"%s\"",
808 current, leftcurrent, opaque->
btpo_prev)));
812 (
errcode(ERRCODE_INDEX_CORRUPTED),
813 errmsg(
"block %u fell off the end of index \"%s\"",
835 (
errcode(ERRCODE_INDEX_CORRUPTED),
836 errmsg(
"block %u is not leftmost in index \"%s\"",
841 (
errcode(ERRCODE_INDEX_CORRUPTED),
842 errmsg(
"block %u is not true root in index \"%s\"",
902 (
errcode(ERRCODE_INDEX_CORRUPTED),
903 errmsg(
"leftmost down link for level points to block in index \"%s\" whose level is not one level down",
905 errdetail_internal(
"Block pointed to=%u expected level=%u level in pointed to block=%u.",
914 if (current == leftcurrent || current == opaque->
btpo_prev)
916 (
errcode(ERRCODE_INDEX_CORRUPTED),
917 errmsg(
"circular link chain found in block %u of index \"%s\"",
920 leftcurrent = current;
927 state->lowkey = NULL;
962 while (current !=
P_NONE);
968 state->lowkey = NULL;
974 return nextleveldown;
986 tid,
state->snapshot, slot);
1017 itid =
psprintf(
"tid=(%u,%u)", block, offset);
1019 if (nblock != block || noffset != offset)
1020 nitid =
psprintf(
" tid=(%u,%u)", nblock, noffset);
1023 pposting =
psprintf(
" posting %u", posting);
1026 pnposting =
psprintf(
" posting %u", nposting);
1029 (
errcode(ERRCODE_INDEX_CORRUPTED),
1030 errmsg(
"index uniqueness is violated for index \"%s\"",
1032 errdetail(
"Index %s%s and%s%s (point to heap %s and %s) page lsn=%X/%X.",
1033 itid, pposting, nitid, pnposting, htid, nhtid,
1045 bool has_visible_entry =
false;
1060 has_visible_entry =
true;
1064 *lVis_tid, *lVis_block,
1065 *lVis_offset, *lVis_i,
1080 *lVis_offset = offset;
1081 *lVis_block = targetblock;
1096 has_visible_entry =
true;
1100 *lVis_tid, *lVis_block,
1101 *lVis_offset, *lVis_i,
1107 *lVis_offset = offset;
1108 *lVis_block = targetblock;
1113 *lVis_block != targetblock)
1118 posting =
psprintf(
" posting %u", *lVis_i);
1121 errmsg(
"index uniqueness can not be checked for index tid=(%u,%u) in index \"%s\"",
1122 targetblock, offset,
1124 errdetail(
"It doesn't have visible heap tids and key is equal to the tid=(%u,%u)%s (points to heap tid=(%u,%u)).",
1125 *lVis_block, *lVis_offset, posting,
1128 errhint(
"VACUUM the table and repeat the check.")));
1144 reached_from = start;
1145 bool all_half_dead =
true;
1153 while (reached !=
P_NONE && all_half_dead)
1167 reached != reached_from &&
1168 reached_opaque->
btpo_next == reached_from;
1176 errmsg_internal(
"harmless interrupted page deletion detected in index \"%s\"",
1179 reached, reached_from,
1182 reached_from = reached;
1189 return all_half_dead;
1235 if (!
state->readonly)
1265 if (newtargetblock != leftcurrent)
1269 state->checkstrategy);
1275 btpo_prev_from_target = opaque->
btpo_prev;
1297 if (btpo_prev_from_target == leftcurrent)
1301 (
errcode(ERRCODE_INTERNAL_ERROR),
1302 errmsg_internal(
"harmless concurrent page split detected in index \"%s\"",
1305 leftcurrent, newtargetblock,
1306 state->targetblock)));
1317 state->targetblock = newtargetblock;
1321 (
errcode(ERRCODE_INDEX_CORRUPTED),
1322 errmsg(
"left link/right link pair in index \"%s\" not in agreement",
1325 state->targetblock, leftcurrent,
1326 btpo_prev_from_target)));
1384 elog(
DEBUG2,
"verifying %u items on %s block %u", max,
1385 P_ISLEAF(topaque) ?
"leaf" :
"internal",
state->targetblock);
1404 (
errcode(ERRCODE_INDEX_CORRUPTED),
1405 errmsg(
"wrong number of high key index tuple attributes in index \"%s\"",
1410 P_ISLEAF(topaque) ?
"heap" :
"index",
1428 bool lowersizelimit;
1434 state->target, offset);
1446 (
errcode(ERRCODE_INDEX_CORRUPTED),
1447 errmsg(
"index tuple size does not equal lp_len in index \"%s\"",
1450 state->targetblock, offset,
1453 errhint(
"This could be a torn page problem.")));
1470 (
errcode(ERRCODE_INDEX_CORRUPTED),
1471 errmsg(
"wrong number of index tuple attributes in index \"%s\"",
1476 P_ISLEAF(topaque) ?
"heap" :
"index",
1520 (
errcode(ERRCODE_INDEX_CORRUPTED),
1521 errmsg(
"could not find tuple using search from root page in index \"%s\"",
1546 char *itid =
psprintf(
"(%u,%u)",
state->targetblock, offset);
1549 (
errcode(ERRCODE_INDEX_CORRUPTED),
1550 errmsg_internal(
"posting list contains misplaced TID in index \"%s\"",
1603 (
errcode(ERRCODE_INDEX_CORRUPTED),
1604 errmsg(
"index row size %zu exceeds maximum for index \"%s\"",
1608 P_ISLEAF(topaque) ?
"heap" :
"index",
1630 if (norm != logtuple)
1710 (
errcode(ERRCODE_INDEX_CORRUPTED),
1711 errmsg(
"high key invariant violated for index \"%s\"",
1715 P_ISLEAF(topaque) ?
"heap" :
"index",
1756 (
errcode(ERRCODE_INDEX_CORRUPTED),
1757 errmsg(
"item order invariant violated for index \"%s\"",
1760 "higher index tid=%s (points to %s tid=%s) "
1763 P_ISLEAF(topaque) ?
"heap" :
"index",
1766 P_ISLEAF(topaque) ?
"heap" :
"index",
1775 if (
state->checkunique &&
state->indexinfo->ii_Unique &&
1778 &lVis_i, &lVis_tid, &lVis_offset,
1781 if (
state->checkunique &&
state->indexinfo->ii_Unique &&
1848 if (!
state->readonly)
1863 (
errcode(ERRCODE_INDEX_CORRUPTED),
1864 errmsg(
"cross page item order invariant violated for index \"%s\"",
1867 state->targetblock, offset,
1876 if (
state->checkunique &&
state->indexinfo->ii_Unique &&
1879 elog(
DEBUG2,
"check cross page unique condition");
1905 &lVis_i, &lVis_tid, &lVis_offset,
2015 errmsg_internal(
"level %u sibling page in block %u of index \"%s\" was found deleted or half dead",
2017 errdetail_internal(
"Deleted page found when building scankey from right sibling.")));
2147 P_ISLEAF(opaque) ?
"leaf" :
"internal", targetnext,
2246 bool rightsplit =
state->previncompletesplit;
2255 state->target, target_downlinkoffnum);
2292 state->previncompletesplit =
false;
2299 (
errcode(ERRCODE_INDEX_CORRUPTED),
2300 errmsg(
"can't traverse from downlink %u to downlink %u of index \"%s\"",
2301 state->prevrightlink, downlink,
2305 if (blkno == downlink && loaded_child)
2306 page = loaded_child;
2316 (
errcode(ERRCODE_INDEX_CORRUPTED),
2317 errmsg(
"the first child of leftmost target page is not leftmost of its level in index \"%s\"",
2320 state->targetblock, blkno,
2327 (
errcode(ERRCODE_INDEX_CORRUPTED),
2328 errmsg(
"block found while following rightlinks from child of index \"%s\" has invalid level",
2330 errdetail_internal(
"Block pointed to=%u expected level=%u level in pointed to block=%u.",
2331 blkno, target_level - 1, opaque->
btpo_level)));
2334 if ((!first && blkno ==
state->prevrightlink) || blkno == opaque->
btpo_prev)
2336 (
errcode(ERRCODE_INDEX_CORRUPTED),
2337 errmsg(
"circular link chain found in block %u of index \"%s\"",
2340 if (blkno != downlink && !
P_IGNORE(opaque))
2384 if (blkno == downlink)
2387 pivotkey_offset = target_downlinkoffnum;
2402 (
errcode(ERRCODE_INDEX_CORRUPTED),
2403 errmsg(
"child high key is greater than rightmost pivot key on target level in index \"%s\"",
2406 state->targetblock, blkno,
2411 state->target, pivotkey_offset);
2432 (
errcode(ERRCODE_INDEX_CORRUPTED),
2433 errmsg(
"can't find left sibling high key in index \"%s\"",
2436 state->targetblock, blkno,
2438 itup =
state->lowkey;
2444 (
errcode(ERRCODE_INDEX_CORRUPTED),
2445 errmsg(
"mismatch between parent key and child high key in index \"%s\"",
2448 state->targetblock, blkno,
2454 if (blkno == downlink)
2457 state->previncompletesplit = rightsplit;
2465 if (page != loaded_child)
2498 state->target, downlinkoffnum);
2584 (
errcode(ERRCODE_INDEX_CORRUPTED),
2585 errmsg(
"downlink to deleted page found in index \"%s\"",
2588 state->targetblock, childblock,
2592 offset <= maxoffset;
2625 (
errcode(ERRCODE_INDEX_CORRUPTED),
2626 errmsg(
"down-link lower bound invariant violated for index \"%s\"",
2629 state->targetblock, childblock, offset,
2696 errmsg_internal(
"harmless interrupted page split detected in index \"%s\"",
2717 (
errcode(ERRCODE_INDEX_CORRUPTED),
2718 errmsg(
"leaf index block lacks downlink in index \"%s\"",
2725 elog(
DEBUG1,
"checking for interrupted multi-level deletion due to missing downlink in index \"%s\"",
2745 (
errcode(ERRCODE_INDEX_CORRUPTED),
2746 errmsg_internal(
"downlink points to block in index \"%s\" whose level is not one level down",
2748 errdetail_internal(
"Top parent/under check block=%u block pointed to=%u expected level=%u level in pointed to block=%u.",
2783 (
errcode(ERRCODE_INDEX_CORRUPTED),
2784 errmsg_internal(
"downlink to deleted leaf page found in index \"%s\"",
2786 errdetail_internal(
"Top parent/target block=%u leaf block=%u top parent/under check lsn=%X/%X.",
2809 (
errcode(ERRCODE_INDEX_CORRUPTED),
2810 errmsg(
"internal index block lacks downlink in index \"%s\"",
2874 bool *isnull,
bool tupleIsAlive,
void *checkstate)
2892 errmsg(
"heap tuple (%u,%u) from table \"%s\" lacks matching index tuple within index \"%s\"",
2898 ?
errhint(
"Retrying verification using the function bt_index_parent_check() might provide a more specific error.")
2901 state->heaptuplespresent++;
2947 bool formnewtup =
false;
2958 for (
i = 0;
i < tupleDescriptor->
natts;
i++)
2965 toast_free[
i] =
false;
2969 if (att->attbyval || att->attlen != -1 || isnull[
i])
2979 (
errcode(ERRCODE_INDEX_CORRUPTED),
2980 errmsg(
"external varlena datum in tuple that references heap row (%u,%u) in index \"%s\"",
2988 toast_free[
i] =
true;
3009 for (
i = 0;
i < tupleDescriptor->
natts;
i++)
3092 insertstate.
itup = itup;
3097 insertstate.
buf = lbuf;
3175 if (!
key->heapkeyspace)
3206 if (
key->keysz == uppnkeyatts)
3207 return key->scantid == NULL && rheaptid != NULL;
3209 return key->keysz < uppnkeyatts;
3259 if (!
key->heapkeyspace)
3300 if (!
key->heapkeyspace)
3321 if (
key->keysz == uppnkeyatts)
3322 return key->scantid == NULL && childheaptid != NULL;
3324 return key->keysz < uppnkeyatts;
3359 state->checkstrategy);
3376 (
errcode(ERRCODE_INDEX_CORRUPTED),
3377 errmsg(
"invalid meta page found at block %u in index \"%s\"",
3388 (
errcode(ERRCODE_INDEX_CORRUPTED),
3389 errmsg(
"index \"%s\" meta page is corrupt",
3395 (
errcode(ERRCODE_INDEX_CORRUPTED),
3396 errmsg(
"version mismatch in index \"%s\": file version %d, "
3397 "current version %d, minimum supported version %d",
3417 (
errcode(ERRCODE_INDEX_CORRUPTED),
3418 errmsg_internal(
"invalid leaf page level %u for block %u in index \"%s\"",
3424 (
errcode(ERRCODE_INDEX_CORRUPTED),
3425 errmsg_internal(
"invalid internal page level 0 for block %u in index \"%s\"",
3452 (
errcode(ERRCODE_INDEX_CORRUPTED),
3453 errmsg(
"Number of items on block %u of index \"%s\" exceeds MaxIndexTuplesPerPage (%u)",
3459 (
errcode(ERRCODE_INDEX_CORRUPTED),
3460 errmsg(
"internal block %u in index \"%s\" lacks high key and/or at least one downlink",
3465 (
errcode(ERRCODE_INDEX_CORRUPTED),
3466 errmsg(
"non-rightmost leaf block %u in index \"%s\" lacks high key item",
3478 (
errcode(ERRCODE_INDEX_CORRUPTED),
3479 errmsg(
"internal page block %u in index \"%s\" is half-dead",
3481 errhint(
"This can be caused by an interrupted VACUUM in version 9.3 or older, before upgrade. Please REINDEX it.")));
3489 (
errcode(ERRCODE_INDEX_CORRUPTED),
3490 errmsg_internal(
"internal page block %u in index \"%s\" has garbage items",
3495 (
errcode(ERRCODE_INDEX_CORRUPTED),
3496 errmsg_internal(
"full transaction id page flag appears in non-deleted block %u in index \"%s\"",
3501 (
errcode(ERRCODE_INDEX_CORRUPTED),
3555 (
errcode(ERRCODE_INDEX_CORRUPTED),
3556 errmsg(
"line pointer points past end of tuple space in index \"%s\"",
3571 (
errcode(ERRCODE_INDEX_CORRUPTED),
3572 errmsg(
"invalid line pointer storage in index \"%s\"",
3600 (
errcode(ERRCODE_INDEX_CORRUPTED),
3601 errmsg_internal(
"block %u or its right sibling block or child block in index \"%s\" has unexpected pivot tuple",
3607 (
errcode(ERRCODE_INDEX_CORRUPTED),
3608 errmsg_internal(
"block %u or its right sibling block or child block in index \"%s\" has unexpected non-pivot tuple",
3615 (
errcode(ERRCODE_INDEX_CORRUPTED),
3616 errmsg(
"block %u or its right sibling block or child block in index \"%s\" contains non-pivot tuple that lacks a heap TID",
3647 return &itup->
t_tid;
#define InvalidBlockNumber
static bool BlockNumberIsValid(BlockNumber blockNumber)
void bloom_free(bloom_filter *filter)
bloom_filter * bloom_create(int64 total_elems, int bloom_work_mem, uint64 seed)
double bloom_prop_bits_set(bloom_filter *filter)
bool bloom_lacks_element(bloom_filter *filter, unsigned char *elem, size_t len)
void bloom_add_element(bloom_filter *filter, unsigned char *elem, size_t len)
static Datum values[MAXATTR]
void UnlockReleaseBuffer(Buffer buffer)
void LockBuffer(Buffer buffer, int mode)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
#define RelationGetNumberOfBlocks(reln)
static Page BufferGetPage(Buffer buffer)
static bool BufferIsValid(Buffer bufnum)
static Item PageGetItem(Page page, ItemId itemId)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static XLogRecPtr PageGetLSN(Page page)
static OffsetNumber PageGetMaxOffsetNumber(Page page)
#define OidIsValid(objectId)
int errmsg_internal(const char *fmt,...)
int errdetail_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
#define PG_DETOAST_DATUM(datum)
#define PG_GETARG_BOOL(n)
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
int NewGUCNestLevel(void)
void RestrictSearchPath(void)
void AtEOXact_GUC(bool isCommit, int nestLevel)
#define HeapTupleHeaderGetXmin(tup)
Oid IndexGetRelation(Oid indexId, bool missing_ok)
IndexInfo * BuildIndexInfo(Relation index)
void index_close(Relation relation, LOCKMODE lockmode)
Relation index_open(Oid relationId, LOCKMODE lockmode)
IndexTuple index_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
#define ItemIdGetLength(itemId)
#define ItemIdGetOffset(itemId)
#define ItemIdIsDead(itemId)
#define ItemIdIsUsed(itemId)
#define ItemIdIsRedirected(itemId)
#define ItemIdGetFlags(itemId)
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
static OffsetNumber ItemPointerGetOffsetNumberNoCheck(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumberNoCheck(const ItemPointerData *pointer)
static void ItemPointerCopy(const ItemPointerData *fromPointer, ItemPointerData *toPointer)
static bool ItemPointerIsValid(const ItemPointerData *pointer)
#define IndexTupleHasVarwidths(itup)
IndexTupleData * IndexTuple
#define IndexTupleSize(itup)
static Datum index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
#define MaxIndexTuplesPerPage
Assert(fmt[strlen(fmt) - 1] !='\n')
void MemoryContextReset(MemoryContext context)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void * MemoryContextAlloc(MemoryContext context, Size size)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define SECURITY_RESTRICTED_OPERATION
#define CHECK_FOR_INTERRUPTS()
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
void SetUserIdAndSecContext(Oid userid, int sec_context)
IndexTuple _bt_form_posting(IndexTuple base, ItemPointer htids, int nhtids)
void _bt_relbuf(Relation rel, Buffer buf)
void _bt_checkpage(Relation rel, Buffer buf)
void _bt_metaversion(Relation rel, bool *heapkeyspace, bool *allequalimage)
#define P_HAS_FULLXID(opaque)
#define P_ISHALFDEAD(opaque)
static uint16 BTreeTupleGetNPosting(IndexTuple posting)
static bool BTreeTupleIsPivot(IndexTuple itup)
#define BTREE_MIN_VERSION
#define P_HAS_GARBAGE(opaque)
#define BTMaxItemSizeNoHeapTid(page)
#define BTPageGetOpaque(page)
#define P_ISDELETED(opaque)
static BlockNumber BTreeTupleGetTopParent(IndexTuple leafhikey)
#define MaxTIDsPerBTreePage
#define P_FIRSTDATAKEY(opaque)
#define P_RIGHTMOST(opaque)
#define BTMaxItemSize(page)
#define P_INCOMPLETE_SPLIT(opaque)
static ItemPointer BTreeTupleGetPostingN(IndexTuple posting, int n)
static BlockNumber BTreeTupleGetDownLink(IndexTuple pivot)
static ItemPointer BTreeTupleGetMaxHeapTID(IndexTuple itup)
static bool BTreeTupleIsPosting(IndexTuple itup)
static ItemPointer BTreeTupleGetHeapTID(IndexTuple itup)
#define BTreeTupleGetNAtts(itup, rel)
BTStack _bt_search(Relation rel, Relation heaprel, BTScanInsert key, Buffer *bufP, int access)
OffsetNumber _bt_binsrch_insert(Relation rel, BTInsertState insertstate)
int32 _bt_compare(Relation rel, BTScanInsert key, Page page, OffsetNumber offnum)
void _bt_freestack(BTStack stack)
BTScanInsert _bt_mkscankey(Relation rel, IndexTuple itup)
bool _bt_check_natts(Relation rel, bool heapkeyspace, Page page, OffsetNumber offnum)
bool _bt_allequalimage(Relation rel, bool debugmessage)
#define InvalidOffsetNumber
#define OffsetNumberIsValid(offsetNumber)
#define OffsetNumberNext(offsetNumber)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
FormData_pg_attribute * Form_pg_attribute
#define ERRCODE_DATA_CORRUPTED
uint64 pg_prng_uint64(pg_prng_state *state)
pg_prng_state pg_global_prng_state
#define ERRCODE_T_R_SERIALIZATION_FAILURE
#define ERRCODE_UNDEFINED_TABLE
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
char * psprintf(const char *fmt,...)
static int cmp(const chr *x, const chr *y, size_t len)
static SMgrRelation RelationGetSmgr(Relation rel)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RELATION_IS_OTHER_TEMP(relation)
#define IndexRelationGetNumberOfKeyAttributes(relation)
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Snapshot GetTransactionSnapshot(void)
void UnregisterSnapshot(Snapshot snapshot)
Snapshot RegisterSnapshot(Snapshot snapshot)
BufferAccessStrategy checkstrategy
BlockNumber prevrightlink
MemoryContext targetcontext
uint16 * ii_ExclusionStrats
struct HeapTupleData * rd_indextuple
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
static TableScanDesc table_beginscan_strat(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync)
static double table_index_build_scan(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, bool allow_sync, bool progress, IndexBuildCallback callback, void *callback_state, TableScanDesc scan)
static bool table_tuple_fetch_row_version(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
#define TransactionIdIsValid(xid)
#define TupleDescAttr(tupdesc, i)
#define VARATT_IS_COMPRESSED(PTR)
#define VARATT_IS_EXTERNAL(PTR)
static bool offset_is_negative_infinity(BTPageOpaque opaque, OffsetNumber offset)
static bool bt_leftmost_ignoring_half_dead(BtreeCheckState *state, BlockNumber start, BTPageOpaque start_opaque)
static bool invariant_l_offset(BtreeCheckState *state, BTScanInsert key, OffsetNumber upperbound)
static ItemPointer BTreeTupleGetPointsToTID(IndexTuple itup)
struct BtreeCheckState BtreeCheckState
static IndexTuple bt_posting_plain_tuple(IndexTuple itup, int n)
static void bt_target_page_check(BtreeCheckState *state)
static void bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace, bool readonly, bool heapallindexed, bool rootdescend, bool checkunique)
static void bt_entry_unique_check(BtreeCheckState *state, IndexTuple itup, BlockNumber targetblock, OffsetNumber offset, int *lVis_i, ItemPointer *lVis_tid, OffsetNumber *lVis_offset, BlockNumber *lVis_block)
static bool bt_pivot_tuple_identical(bool heapkeyspace, IndexTuple itup1, IndexTuple itup2)
static void bt_report_duplicate(BtreeCheckState *state, ItemPointer tid, BlockNumber block, OffsetNumber offset, int posting, ItemPointer nexttid, BlockNumber nblock, OffsetNumber noffset, int nposting)
static void bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed, bool rootdescend, bool checkunique)
static bool invariant_leq_offset(BtreeCheckState *state, BTScanInsert key, OffsetNumber upperbound)
Datum bt_index_parent_check(PG_FUNCTION_ARGS)
static void bt_child_highkey_check(BtreeCheckState *state, OffsetNumber target_downlinkoffnum, Page loaded_child, uint32 target_level)
static bool heap_entry_is_visible(BtreeCheckState *state, ItemPointer tid)
static BTScanInsert bt_mkscankey_pivotsearch(Relation rel, IndexTuple itup)
Datum bt_index_check(PG_FUNCTION_ARGS)
static BtreeLevel bt_check_level_from_leftmost(BtreeCheckState *state, BtreeLevel level)
static void bt_downlink_missing_check(BtreeCheckState *state, bool rightsplit, BlockNumber blkno, Page page)
PG_FUNCTION_INFO_V1(bt_index_check)
static ItemId PageGetItemIdCareful(BtreeCheckState *state, BlockNumber block, Page page, OffsetNumber offset)
static void bt_tuple_present_callback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *checkstate)
static bool btree_index_mainfork_expected(Relation rel)
static bool bt_rootdescend(BtreeCheckState *state, IndexTuple itup)
static BTScanInsert bt_right_page_check_scankey(BtreeCheckState *state, OffsetNumber *rightfirstoffset)
static bool invariant_g_offset(BtreeCheckState *state, BTScanInsert key, OffsetNumber lowerbound)
#define InvalidBtreeLevel
static Page palloc_btree_page(BtreeCheckState *state, BlockNumber blocknum)
static IndexTuple bt_normalize_tuple(BtreeCheckState *state, IndexTuple itup)
static void bt_recheck_sibling_links(BtreeCheckState *state, BlockNumber btpo_prev_from_target, BlockNumber leftcurrent)
static ItemPointer BTreeTupleGetHeapTIDCareful(BtreeCheckState *state, IndexTuple itup, bool nonpivot)
#define BTreeTupleGetNKeyAtts(itup, rel)
static void bt_child_check(BtreeCheckState *state, BTScanInsert targetkey, OffsetNumber downlinkoffnum)
static void btree_index_checkable(Relation rel)
static bool invariant_l_nontarget_offset(BtreeCheckState *state, BTScanInsert key, BlockNumber nontargetblock, Page nontarget, OffsetNumber upperbound)
struct BtreeLevel BtreeLevel
#define IsolationUsesXactSnapshot()
bool RecoveryInProgress(void)
#define LSN_FORMAT_ARGS(lsn)