35#include "catalog/pg_opfamily_d.h"
51#define InvalidBtreeLevel ((uint32) InvalidBlockNumber)
52#define BTreeTupleGetNKeyAtts(itup, rel) \
53 Min(IndexRelationGetNumberOfKeyAttributes(rel), BTreeTupleGetNAtts(itup, rel))
163 bool heapallindexed,
bool rootdescend,
168 bool heapkeyspace,
bool readonly,
bool heapallindexed,
169 bool rootdescend,
bool checkunique);
200 bool tupleIsAlive,
void *checkstate);
241 bool heapallindexed =
false;
242 bool checkunique =
false;
267 bool heapallindexed =
false;
268 bool rootdescend =
false;
269 bool checkunique =
false;
288 bool rootdescend,
bool checkunique)
295 int save_sec_context;
332 save_sec_context = -1;
358 errmsg(
"could not open parent table of index \"%s\"",
371 (
errcode(ERRCODE_INDEX_CORRUPTED),
372 errmsg(
"index \"%s\" lacks a main relation fork",
377 if (allequalimage && !heapkeyspace)
379 (
errcode(ERRCODE_INDEX_CORRUPTED),
380 errmsg(
"index \"%s\" metapage has equalimage field set on unsupported nbtree version",
384 bool has_interval_ops =
false;
388 has_interval_ops =
true;
390 (
errcode(ERRCODE_INDEX_CORRUPTED),
391 errmsg(
"index \"%s\" metapage incorrectly indicates that deduplication is safe",
394 ?
errhint(
"This is known of \"interval\" indexes last built on a version predating 2023-11.")
400 heapallindexed, rootdescend, checkunique);
430 if (rel->
rd_rel->relkind != RELKIND_INDEX ||
431 rel->
rd_rel->relam != BTREE_AM_OID)
433 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
434 errmsg(
"only B-Tree indexes are supported as targets for verification"),
435 errdetail(
"Relation \"%s\" is not a B-Tree index.",
440 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
441 errmsg(
"cannot access temporary tables of other sessions"),
442 errdetail(
"Index \"%s\" is associated with temporary relation.",
447 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
448 errmsg(
"cannot check index \"%s\"",
464 if (rel->
rd_rel->relpersistence != RELPERSISTENCE_UNLOGGED ||
469 (
errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
470 errmsg(
"cannot verify unlogged index \"%s\" during recovery, skipping",
501 bool readonly,
bool heapallindexed,
bool rootdescend,
512 elog(
DEBUG1,
"verifying consistency of tree structure for index \"%s\"",
515 elog(
DEBUG1,
"verifying consistency of tree structure for index \"%s\" with cross-level checks",
529 state->heaprel = heaprel;
530 state->heapkeyspace = heapkeyspace;
531 state->readonly = readonly;
532 state->heapallindexed = heapallindexed;
533 state->rootdescend = rootdescend;
534 state->checkunique = checkunique;
537 if (
state->heapallindexed)
557 state->heaptuplespresent = 0;
566 if (!
state->readonly)
588 errmsg(
"index \"%s\" cannot be verified using transaction snapshot",
598 if (
state->checkunique)
601 if (
state->indexinfo->ii_Unique)
604 state->snapshot = snapshot;
611 if (
state->rootdescend && !
state->heapkeyspace)
613 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
614 errmsg(
"cannot verify that tuples from index \"%s\" can each be found by an independent index search",
616 errhint(
"Only B-Tree version 4 indexes support rootdescend verification.")));
641 errdetail_internal(
"Fast root block %u (level %u) differs from true root block %u (level %u).",
664 (
errcode(ERRCODE_INDEX_CORRUPTED),
665 errmsg(
"index \"%s\" has no valid pages on level below %u or first level",
668 previouslevel = current.
level;
674 if (
state->heapallindexed)
717 elog(
DEBUG1,
"verifying that tuples from index \"%s\" are present in \"%s\"",
781 " (true root level)" : level.
level == 0 ?
" (leaf level)" :
"");
784 state->previncompletesplit =
false;
792 state->targetblock = current;
813 (
errcode(ERRCODE_INDEX_CORRUPTED),
814 errmsg(
"downlink or sibling link points to deleted block in index \"%s\"",
817 current, leftcurrent, opaque->
btpo_prev)));
821 (
errcode(ERRCODE_INDEX_CORRUPTED),
822 errmsg(
"block %u fell off the end of index \"%s\"",
844 (
errcode(ERRCODE_INDEX_CORRUPTED),
845 errmsg(
"block %u is not leftmost in index \"%s\"",
850 (
errcode(ERRCODE_INDEX_CORRUPTED),
851 errmsg(
"block %u is not true root in index \"%s\"",
911 (
errcode(ERRCODE_INDEX_CORRUPTED),
912 errmsg(
"leftmost down link for level points to block in index \"%s\" whose level is not one level down",
914 errdetail_internal(
"Block pointed to=%u expected level=%u level in pointed to block=%u.",
923 if (current == leftcurrent || current == opaque->
btpo_prev)
925 (
errcode(ERRCODE_INDEX_CORRUPTED),
926 errmsg(
"circular link chain found in block %u of index \"%s\"",
929 leftcurrent = current;
936 state->lowkey = NULL;
971 while (current !=
P_NONE);
977 state->lowkey = NULL;
983 return nextleveldown;
995 tid,
state->snapshot, slot);
1027 if (nblock != lVis->
blkno || noffset != lVis->
offset)
1028 nitid =
psprintf(
" tid=(%u,%u)", nblock, noffset);
1034 pnposting =
psprintf(
" posting %u", nposting);
1037 (
errcode(ERRCODE_INDEX_CORRUPTED),
1038 errmsg(
"index uniqueness is violated for index \"%s\"",
1040 errdetail(
"Index %s%s and%s%s (point to heap %s and %s) page lsn=%X/%X.",
1041 itid, pposting, nitid, pnposting, htid, nhtid,
1052 bool has_visible_entry =
false;
1067 has_visible_entry =
true;
1084 lVis->
blkno = targetblock;
1102 has_visible_entry =
true;
1111 lVis->
blkno = targetblock;
1118 if (!has_visible_entry &&
1120 lVis->
blkno != targetblock)
1128 errmsg(
"index uniqueness can not be checked for index tid=(%u,%u) in index \"%s\"",
1129 targetblock, offset,
1131 errdetail(
"It doesn't have visible heap tids and key is equal to the tid=(%u,%u)%s (points to heap tid=(%u,%u)).",
1135 errhint(
"VACUUM the table and repeat the check.")));
1151 reached_from =
start;
1152 bool all_half_dead =
true;
1160 while (reached !=
P_NONE && all_half_dead)
1174 reached != reached_from &&
1175 reached_opaque->
btpo_next == reached_from;
1183 errmsg_internal(
"harmless interrupted page deletion detected in index \"%s\"",
1186 reached, reached_from,
1189 reached_from = reached;
1196 return all_half_dead;
1242 if (!
state->readonly)
1272 if (newtargetblock != leftcurrent)
1276 state->checkstrategy);
1282 btpo_prev_from_target = opaque->
btpo_prev;
1304 if (btpo_prev_from_target == leftcurrent)
1308 (
errcode(ERRCODE_INTERNAL_ERROR),
1309 errmsg_internal(
"harmless concurrent page split detected in index \"%s\"",
1312 leftcurrent, newtargetblock,
1313 state->targetblock)));
1324 state->targetblock = newtargetblock;
1328 (
errcode(ERRCODE_INDEX_CORRUPTED),
1329 errmsg(
"left link/right link pair in index \"%s\" not in agreement",
1332 state->targetblock, leftcurrent,
1333 btpo_prev_from_target)));
1387 elog(
DEBUG2,
"verifying %u items on %s block %u", max,
1388 P_ISLEAF(topaque) ?
"leaf" :
"internal",
state->targetblock);
1407 (
errcode(ERRCODE_INDEX_CORRUPTED),
1408 errmsg(
"wrong number of high key index tuple attributes in index \"%s\"",
1413 P_ISLEAF(topaque) ?
"heap" :
"index",
1431 bool lowersizelimit;
1439 bool unique_checked =
false;
1444 state->target, offset);
1456 (
errcode(ERRCODE_INDEX_CORRUPTED),
1457 errmsg(
"index tuple size does not equal lp_len in index \"%s\"",
1460 state->targetblock, offset,
1463 errhint(
"This could be a torn page problem.")));
1480 (
errcode(ERRCODE_INDEX_CORRUPTED),
1481 errmsg(
"wrong number of index tuple attributes in index \"%s\"",
1486 P_ISLEAF(topaque) ?
"heap" :
"index",
1530 (
errcode(ERRCODE_INDEX_CORRUPTED),
1531 errmsg(
"could not find tuple using search from root page in index \"%s\"",
1556 char *itid =
psprintf(
"(%u,%u)",
state->targetblock, offset);
1559 (
errcode(ERRCODE_INDEX_CORRUPTED),
1560 errmsg_internal(
"posting list contains misplaced TID in index \"%s\"",
1612 (
errcode(ERRCODE_INDEX_CORRUPTED),
1613 errmsg(
"index row size %zu exceeds maximum for index \"%s\"",
1617 P_ISLEAF(topaque) ?
"heap" :
"index",
1639 if (norm != logtuple)
1719 (
errcode(ERRCODE_INDEX_CORRUPTED),
1720 errmsg(
"high key invariant violated for index \"%s\"",
1724 P_ISLEAF(topaque) ?
"heap" :
"index",
1765 (
errcode(ERRCODE_INDEX_CORRUPTED),
1766 errmsg(
"item order invariant violated for index \"%s\"",
1769 "higher index tid=%s (points to %s tid=%s) "
1772 P_ISLEAF(topaque) ?
"heap" :
"index",
1775 P_ISLEAF(topaque) ?
"heap" :
"index",
1786 if (
state->checkunique &&
state->indexinfo->ii_Unique &&
1792 unique_checked =
true;
1795 if (
state->checkunique &&
state->indexinfo->ii_Unique &&
1824 else if (!unique_checked)
1869 if (!
state->readonly)
1884 (
errcode(ERRCODE_INDEX_CORRUPTED),
1885 errmsg(
"cross page item order invariant violated for index \"%s\"",
1888 state->targetblock, offset,
1896 if (
state->checkunique &&
state->indexinfo->ii_Unique &&
1901 elog(
DEBUG2,
"check cross page unique condition");
1920 if (!unique_checked)
1937 (
errcode(ERRCODE_INDEX_CORRUPTED),
1938 errmsg(
"right block of leaf block is non-leaf for index \"%s\"",
2060 errmsg_internal(
"level %u sibling page in block %u of index \"%s\" was found deleted or half dead",
2062 errdetail_internal(
"Deleted page found when building scankey from right sibling.")));
2192 P_ISLEAF(opaque) ?
"leaf" :
"internal", targetnext,
2291 bool rightsplit =
state->previncompletesplit;
2300 state->target, target_downlinkoffnum);
2337 state->previncompletesplit =
false;
2344 (
errcode(ERRCODE_INDEX_CORRUPTED),
2345 errmsg(
"can't traverse from downlink %u to downlink %u of index \"%s\"",
2346 state->prevrightlink, downlink,
2350 if (blkno == downlink && loaded_child)
2351 page = loaded_child;
2361 (
errcode(ERRCODE_INDEX_CORRUPTED),
2362 errmsg(
"the first child of leftmost target page is not leftmost of its level in index \"%s\"",
2365 state->targetblock, blkno,
2372 (
errcode(ERRCODE_INDEX_CORRUPTED),
2373 errmsg(
"block found while following rightlinks from child of index \"%s\" has invalid level",
2375 errdetail_internal(
"Block pointed to=%u expected level=%u level in pointed to block=%u.",
2376 blkno, target_level - 1, opaque->
btpo_level)));
2379 if ((!first && blkno ==
state->prevrightlink) || blkno == opaque->
btpo_prev)
2381 (
errcode(ERRCODE_INDEX_CORRUPTED),
2382 errmsg(
"circular link chain found in block %u of index \"%s\"",
2385 if (blkno != downlink && !
P_IGNORE(opaque))
2429 if (blkno == downlink)
2432 pivotkey_offset = target_downlinkoffnum;
2447 (
errcode(ERRCODE_INDEX_CORRUPTED),
2448 errmsg(
"child high key is greater than rightmost pivot key on target level in index \"%s\"",
2451 state->targetblock, blkno,
2456 state->target, pivotkey_offset);
2477 (
errcode(ERRCODE_INDEX_CORRUPTED),
2478 errmsg(
"can't find left sibling high key in index \"%s\"",
2481 state->targetblock, blkno,
2483 itup =
state->lowkey;
2489 (
errcode(ERRCODE_INDEX_CORRUPTED),
2490 errmsg(
"mismatch between parent key and child high key in index \"%s\"",
2493 state->targetblock, blkno,
2499 if (blkno == downlink)
2502 state->previncompletesplit = rightsplit;
2510 if (page != loaded_child)
2543 state->target, downlinkoffnum);
2629 (
errcode(ERRCODE_INDEX_CORRUPTED),
2630 errmsg(
"downlink to deleted page found in index \"%s\"",
2633 state->targetblock, childblock,
2637 offset <= maxoffset;
2670 (
errcode(ERRCODE_INDEX_CORRUPTED),
2671 errmsg(
"down-link lower bound invariant violated for index \"%s\"",
2674 state->targetblock, childblock, offset,
2741 errmsg_internal(
"harmless interrupted page split detected in index \"%s\"",
2762 (
errcode(ERRCODE_INDEX_CORRUPTED),
2763 errmsg(
"leaf index block lacks downlink in index \"%s\"",
2770 elog(
DEBUG1,
"checking for interrupted multi-level deletion due to missing downlink in index \"%s\"",
2790 (
errcode(ERRCODE_INDEX_CORRUPTED),
2791 errmsg_internal(
"downlink points to block in index \"%s\" whose level is not one level down",
2793 errdetail_internal(
"Top parent/under check block=%u block pointed to=%u expected level=%u level in pointed to block=%u.",
2828 (
errcode(ERRCODE_INDEX_CORRUPTED),
2829 errmsg_internal(
"downlink to deleted leaf page found in index \"%s\"",
2831 errdetail_internal(
"Top parent/target block=%u leaf block=%u top parent/under check lsn=%X/%X.",
2854 (
errcode(ERRCODE_INDEX_CORRUPTED),
2855 errmsg(
"internal index block lacks downlink in index \"%s\"",
2919 bool *isnull,
bool tupleIsAlive,
void *checkstate)
2937 errmsg(
"heap tuple (%u,%u) from table \"%s\" lacks matching index tuple within index \"%s\"",
2943 ?
errhint(
"Retrying verification using the function bt_index_parent_check() might provide a more specific error.")
2946 state->heaptuplespresent++;
2992 bool formnewtup =
false;
3003 for (
i = 0;
i < tupleDescriptor->
natts;
i++)
3010 need_free[
i] =
false;
3014 if (att->attbyval || att->attlen != -1 || isnull[
i])
3024 (
errcode(ERRCODE_INDEX_CORRUPTED),
3025 errmsg(
"external varlena datum in tuple that references heap row (%u,%u) in index \"%s\"",
3031 (att->attstorage == TYPSTORAGE_EXTENDED ||
3032 att->attstorage == TYPSTORAGE_MAIN))
3045 need_free[
i] =
true;
3063 need_free[
i] =
true;
3092 for (
i = 0;
i < tupleDescriptor->
natts;
i++)
3175 insertstate.
itup = itup;
3180 insertstate.
buf = lbuf;
3258 if (!
key->heapkeyspace)
3289 if (
key->keysz == uppnkeyatts)
3290 return key->scantid == NULL && rheaptid != NULL;
3292 return key->keysz < uppnkeyatts;
3342 if (!
key->heapkeyspace)
3383 if (!
key->heapkeyspace)
3404 if (
key->keysz == uppnkeyatts)
3405 return key->scantid == NULL && childheaptid != NULL;
3407 return key->keysz < uppnkeyatts;
3442 state->checkstrategy);
3459 (
errcode(ERRCODE_INDEX_CORRUPTED),
3460 errmsg(
"invalid meta page found at block %u in index \"%s\"",
3471 (
errcode(ERRCODE_INDEX_CORRUPTED),
3472 errmsg(
"index \"%s\" meta page is corrupt",
3478 (
errcode(ERRCODE_INDEX_CORRUPTED),
3479 errmsg(
"version mismatch in index \"%s\": file version %d, "
3480 "current version %d, minimum supported version %d",
3500 (
errcode(ERRCODE_INDEX_CORRUPTED),
3501 errmsg_internal(
"invalid leaf page level %u for block %u in index \"%s\"",
3507 (
errcode(ERRCODE_INDEX_CORRUPTED),
3508 errmsg_internal(
"invalid internal page level 0 for block %u in index \"%s\"",
3535 (
errcode(ERRCODE_INDEX_CORRUPTED),
3536 errmsg(
"Number of items on block %u of index \"%s\" exceeds MaxIndexTuplesPerPage (%u)",
3542 (
errcode(ERRCODE_INDEX_CORRUPTED),
3543 errmsg(
"internal block %u in index \"%s\" lacks high key and/or at least one downlink",
3548 (
errcode(ERRCODE_INDEX_CORRUPTED),
3549 errmsg(
"non-rightmost leaf block %u in index \"%s\" lacks high key item",
3561 (
errcode(ERRCODE_INDEX_CORRUPTED),
3562 errmsg(
"internal page block %u in index \"%s\" is half-dead",
3564 errhint(
"This can be caused by an interrupted VACUUM in version 9.3 or older, before upgrade. Please REINDEX it.")));
3572 (
errcode(ERRCODE_INDEX_CORRUPTED),
3573 errmsg_internal(
"internal page block %u in index \"%s\" has garbage items",
3578 (
errcode(ERRCODE_INDEX_CORRUPTED),
3579 errmsg_internal(
"full transaction id page flag appears in non-deleted block %u in index \"%s\"",
3584 (
errcode(ERRCODE_INDEX_CORRUPTED),
3638 (
errcode(ERRCODE_INDEX_CORRUPTED),
3639 errmsg(
"line pointer points past end of tuple space in index \"%s\"",
3654 (
errcode(ERRCODE_INDEX_CORRUPTED),
3655 errmsg(
"invalid line pointer storage in index \"%s\"",
3683 (
errcode(ERRCODE_INDEX_CORRUPTED),
3684 errmsg_internal(
"block %u or its right sibling block or child block in index \"%s\" has unexpected pivot tuple",
3690 (
errcode(ERRCODE_INDEX_CORRUPTED),
3691 errmsg_internal(
"block %u or its right sibling block or child block in index \"%s\" has unexpected non-pivot tuple",
3698 (
errcode(ERRCODE_INDEX_CORRUPTED),
3699 errmsg(
"block %u or its right sibling block or child block in index \"%s\" contains non-pivot tuple that lacks a heap TID",
3730 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(const PageData *page, const ItemIdData *itemId)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static XLogRecPtr PageGetLSN(const PageData *page)
static OffsetNumber PageGetMaxOffsetNumber(const PageData *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)
Assert(PointerIsAligned(start, uint64))
#define TOAST_INDEX_TARGET
static TransactionId HeapTupleHeaderGetXmin(const HeapTupleHeaderData *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)
static bool IndexTupleHasVarwidths(const IndexTupleData *itup)
IndexTupleData * IndexTuple
static Datum index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static Size IndexTupleSize(const IndexTupleData *itup)
#define MaxIndexTuplesPerPage
void * MemoryContextAlloc(MemoryContext context, Size size)
void MemoryContextReset(MemoryContext context)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
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 BTPageGetOpaque(page)
#define P_ISDELETED(opaque)
static BlockNumber BTreeTupleGetTopParent(IndexTuple leafhikey)
#define MaxTIDsPerBTreePage
#define P_FIRSTDATAKEY(opaque)
#define P_RIGHTMOST(opaque)
#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)
#define BTMaxItemSizeNoHeapTid
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)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
#define SET_VARSIZE_SHORT(PTR, len)
#define VARATT_CAN_MAKE_SHORT(PTR)
#define VARATT_IS_COMPRESSED(PTR)
#define VARATT_CONVERTED_SHORT_SIZE(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)
struct BtreeLastVisibleEntry BtreeLastVisibleEntry
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_report_duplicate(BtreeCheckState *state, BtreeLastVisibleEntry *lVis, ItemPointer nexttid, BlockNumber nblock, OffsetNumber noffset, int nposting)
static bool bt_pivot_tuple_identical(bool heapkeyspace, IndexTuple itup1, IndexTuple itup2)
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 bt_entry_unique_check(BtreeCheckState *state, IndexTuple itup, BlockNumber targetblock, OffsetNumber offset, BtreeLastVisibleEntry *lVis)
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)