48 Size *updatedbuflen,
bool needswal);
156 (
errcode(ERRCODE_INDEX_CORRUPTED),
157 errmsg(
"index \"%s\" is not a btree",
163 (
errcode(ERRCODE_INDEX_CORRUPTED),
164 errmsg(
"version mismatch in index \"%s\": file version %d, "
165 "current version %d, minimal supported version %d",
218 if (prev_num_delpages > 0 &&
547 elog(
ERROR,
"no live root page found in index \"%s\"",
553 elog(
ERROR,
"root page %u of index \"%s\" has level %u, expected %u",
610 (
errcode(ERRCODE_INDEX_CORRUPTED),
611 errmsg(
"index \"%s\" is not a btree",
617 (
errcode(ERRCODE_INDEX_CORRUPTED),
618 errmsg(
"version mismatch in index \"%s\": file version %d, "
619 "current version %d, minimal supported version %d",
650 elog(
ERROR,
"no live root page found in index \"%s\"",
656 elog(
ERROR,
"root page %u of index \"%s\" has level %u, expected %u",
809 (
errcode(ERRCODE_INDEX_CORRUPTED),
810 errmsg(
"index \"%s\" contains unexpected zero page at block %u",
813 errhint(
"Please REINDEX it.")));
820 (
errcode(ERRCODE_INDEX_CORRUPTED),
821 errmsg(
"index \"%s\" contains corrupted page at block %u",
824 errhint(
"Please REINDEX it.")));
945 xlrec_reuse.
block = blkno;
960 elog(
DEBUG2,
"FSM returned nonrecyclable page");
965 elog(
DEBUG2,
"FSM returned nonlockable page");
1161 char *updatedbuf = NULL;
1162 Size updatedbuflen = 0;
1166 Assert(ndeletable > 0 || nupdatable > 0);
1171 updatedoffsets, &updatedbuflen,
1189 for (
int i = 0;
i < nupdatable;
i++)
1195 itup = updatable[
i]->
itup;
1199 elog(
PANIC,
"failed to update partially dead item in block %u of index \"%s\"",
1232 xlrec_vacuum.
ndeleted = ndeletable;
1233 xlrec_vacuum.
nupdated = nupdatable;
1258 if (updatedbuf != NULL)
1261 for (
int i = 0;
i < nupdatable;
i++)
1262 pfree(updatable[
i]->itup);
1292 char *updatedbuf = NULL;
1293 Size updatedbuflen = 0;
1297 Assert(ndeletable > 0 || nupdatable > 0);
1302 updatedoffsets, &updatedbuflen,
1309 for (
int i = 0;
i < nupdatable;
i++)
1315 itup = updatable[
i]->
itup;
1319 elog(
PANIC,
"failed to update partially dead item in block %u of index \"%s\"",
1350 xlrec_delete.
ndeleted = ndeletable;
1351 xlrec_delete.
nupdated = nupdatable;
1377 if (updatedbuf != NULL)
1380 for (
int i = 0;
i < nupdatable;
i++)
1381 pfree(updatable[
i]->itup);
1409 char *updatedbuf = NULL;
1415 for (
int i = 0;
i < nupdatable;
i++)
1437 updatedbuf =
palloc(buflen);
1438 *updatedbuflen = buflen;
1439 for (
int i = 0;
i < nupdatable;
i++)
1451 memcpy(updatedbuf + offset, vacposting->
deletetids, itemsz);
1469 Assert(indexdelete1->
id != indexdelete2->
id);
1565 if (idxoffnum == postingidxoffnum)
1584 deletable[ndeletable++] = idxoffnum;
1596 postingidxoffnum = idxoffnum;
1600 for (
int p = 0; p < nitem; p++)
1611 for (; nestedi < delstate->
ndeltids; nestedi++)
1639 if (vacposting == NULL)
1643 vacposting->
itup = itup;
1652 if (vacposting == NULL)
1659 deletable[ndeletable++] = idxoffnum;
1668 updatable[nupdatable++] = vacposting;
1674 deletable, ndeletable, updatable, nupdatable);
1677 for (
int i = 0;
i < nupdatable;
i++)
1805 bool rightsib_empty;
1860 (
errcode(ERRCODE_INDEX_CORRUPTED),
1861 errmsg(
"index \"%s\" contains a half-dead internal page",
1863 errhint(
"This can be caused by an interrupted VACUUM in version 9.3 or older, before upgrade. Please REINDEX it.")));
1867 (
errcode(ERRCODE_INDEX_CORRUPTED),
1868 errmsg_internal(
"found deleted block %u while following right link from block %u in index \"%s\"",
1949 Assert(leafblkno == scanblkno);
2014 rightsib_empty =
false;
2020 &rightsib_empty, vstate))
2062 if (!rightsib_empty)
2127 elog(
DEBUG1,
"could not delete page %u because its right sibling %u is half-dead",
2128 leafblkno, leafrightsib);
2147 topparent = leafblkno;
2148 topparentrightsib = leafrightsib;
2150 &subtreeparent, &poffset,
2151 &topparent, &topparentrightsib))
2157 #ifdef USE_ASSERT_CHECKING
2182 (
errcode(ERRCODE_INDEX_CORRUPTED),
2183 errmsg_internal(
"right sibling %u of block %u is not next child %u of block %u in index \"%s\"",
2184 topparentrightsib, topparent,
2237 if (topparent != leafblkno)
2244 elog(
ERROR,
"could not overwrite high key in half-dead page");
2258 if (topparent != leafblkno)
2334 bool rightsib_is_rightmost;
2368 leftsib = leafleftsib;
2374 Assert(target != leafblkno);
2400 if (target != leafblkno)
2409 bool leftsibvalid =
true;
2422 leftsibvalid =
false;
2435 (
errcode(ERRCODE_INDEX_CORRUPTED),
2436 errmsg_internal(
"valid left sibling for deletion target could not be located: "
2437 "left sibling %u of target %u with leafblkno %u and scanblkno %u on level %u of index \"%s\"",
2438 leftsib, target, leafblkno, scanblkno,
2443 if (target != leafblkno)
2471 elog(
ERROR,
"target page changed status unexpectedly in block %u of index \"%s\"",
2476 (
errcode(ERRCODE_INDEX_CORRUPTED),
2477 errmsg_internal(
"target page left link unexpectedly changed from %u to %u in block %u of index \"%s\"",
2481 if (target == leafblkno)
2485 elog(
ERROR,
"target leaf page changed status unexpectedly in block %u of index \"%s\"",
2497 elog(
ERROR,
"target internal page on level %u changed status unexpectedly in block %u of index \"%s\"",
2505 if (leaftopparent == leafblkno)
2533 (
errcode(ERRCODE_INDEX_CORRUPTED),
2535 "right sibling %u of target %u with leafblkno %u "
2536 "and scanblkno %u spuriously links to non-target %u "
2537 "on level %u of index \"%s\"",
2538 rightsib, target, leafblkno,
2547 if (target != leafblkno)
2565 if (leftsib ==
P_NONE && rightsib_is_rightmost)
2625 if (target != leafblkno)
2666 if (target != leafblkno)
2683 if (target != leafblkno)
2689 xlrec.
level = targetlevel;
2733 if (target != leafblkno)
2752 if (target != leafblkno)
2765 if (target <= scanblkno)
2846 (
errcode(ERRCODE_INDEX_CORRUPTED),
2847 errmsg_internal(
"failed to re-find parent key in index \"%s\" for deletion target page %u",
2875 if (parentoffset < maxoff)
2881 *subtreeparent = pbuf;
2882 *poffset = parentoffset;
2893 Assert(parentoffset == maxoff);
2911 *topparent = parent;
2936 subtreeparent, poffset,
2937 topparent, topparentrightsib);
2973 maxbufsize =
Min(maxbufsize, INT_MAX);
2976 maxbufsize =
Max(maxbufsize, vstate->
bufsize);
3012 #ifdef DEBUG_BTREE_PENDING_FSM
3069 #ifdef USE_ASSERT_CHECKING
3098 int newbufsize = vstate->
bufsize * 2;
#define InvalidBlockNumber
static bool BlockNumberIsValid(BlockNumber blockNumber)
BlockNumber BufferGetBlockNumber(Buffer buffer)
Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation, BlockNumber blockNum)
Buffer ExtendBufferedRel(BufferManagerRelation bmr, ForkNumber forkNum, BufferAccessStrategy strategy, uint32 flags)
bool ConditionalLockBuffer(Buffer buffer)
void ReleaseBuffer(Buffer buffer)
void MarkBufferDirty(Buffer buffer)
void LockBufferForCleanup(Buffer buffer)
void LockBuffer(Buffer buffer, int mode)
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
#define BUFFER_LOCK_UNLOCK
#define RelationGetNumberOfBlocks(reln)
static Page BufferGetPage(Buffer buffer)
static Size BufferGetPageSize(Buffer buffer)
static bool BufferIsValid(Buffer bufnum)
void PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
bool PageIndexTupleOverwrite(Page page, OffsetNumber offnum, Item newtup, Size newsize)
void PageIndexTupleDelete(Page page, OffsetNumber offnum)
void PageInit(Page page, Size pageSize, Size specialSize)
PageHeaderData * PageHeader
static Item PageGetItem(Page page, ItemId itemId)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static bool PageIsNew(Page page)
static void PageSetLSN(Page page, XLogRecPtr lsn)
static OffsetNumber PageGetMaxOffsetNumber(Page page)
static uint16 PageGetSpecialSize(Page page)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
#define MemSet(start, val, len)
int errmsg_internal(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
BlockNumber GetFreeIndexPage(Relation rel)
void RecordFreeIndexPage(Relation rel, BlockNumber freeBlock)
IndexTuple CopyIndexTuple(IndexTuple source)
static int pg_cmp_s16(int16 a, int16 b)
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
IndexTupleData * IndexTuple
#define IndexTupleSize(itup)
struct IndexTupleData IndexTupleData
#define MaxIndexTuplesPerPage
void pfree(void *pointer)
void * repalloc(void *pointer, Size size)
void * MemoryContextAlloc(MemoryContext context, Size size)
#define VALGRIND_MAKE_MEM_DEFINED(addr, size)
#define VALGRIND_CHECK_MEM_IS_DEFINED(addr, size)
#define VALGRIND_MAKE_MEM_NOACCESS(addr, size)
#define START_CRIT_SECTION()
#define CHECK_FOR_INTERRUPTS()
#define END_CRIT_SECTION()
void _bt_update_posting(BTVacuumPosting vacposting)
Buffer _bt_getstackbuf(Relation rel, Relation heaprel, BTStack stack, BlockNumber child)
Buffer _bt_relandgetbuf(Relation rel, Buffer obuf, BlockNumber blkno, int access)
static bool _bt_lock_subtree_parent(Relation rel, Relation heaprel, BlockNumber child, BTStack stack, Buffer *subtreeparent, OffsetNumber *poffset, BlockNumber *topparent, BlockNumber *topparentrightsib)
void _bt_upgrademetapage(Page page)
void _bt_relbuf(Relation rel, Buffer buf)
Buffer _bt_gettrueroot(Relation rel)
int _bt_getrootheight(Relation rel)
void _bt_pageinit(Page page, Size size)
static bool _bt_rightsib_halfdeadflag(Relation rel, BlockNumber leafrightsib)
void _bt_pagedel(Relation rel, Buffer leafbuf, BTVacState *vstate)
Buffer _bt_allocbuf(Relation rel, Relation heaprel)
void _bt_delitems_vacuum(Relation rel, Buffer buf, OffsetNumber *deletable, int ndeletable, BTVacuumPosting *updatable, int nupdatable)
static bool _bt_leftsib_splitflag(Relation rel, BlockNumber leftsib, BlockNumber target)
void _bt_checkpage(Relation rel, Buffer buf)
void _bt_metaversion(Relation rel, bool *heapkeyspace, bool *allequalimage)
static BTMetaPageData * _bt_getmeta(Relation rel, Buffer metabuf)
static void _bt_delitems_delete(Relation rel, Buffer buf, TransactionId snapshotConflictHorizon, bool isCatalogRel, OffsetNumber *deletable, int ndeletable, BTVacuumPosting *updatable, int nupdatable)
void _bt_set_cleanup_info(Relation rel, BlockNumber num_delpages)
static bool _bt_mark_page_halfdead(Relation rel, Relation heaprel, Buffer leafbuf, BTStack stack)
bool _bt_conditionallockbuf(Relation rel, Buffer buf)
Buffer _bt_getbuf(Relation rel, BlockNumber blkno, int access)
void _bt_unlockbuf(Relation rel, Buffer buf)
void _bt_upgradelockbufcleanup(Relation rel, Buffer buf)
void _bt_initmetapage(Page page, BlockNumber rootbknum, uint32 level, bool allequalimage)
void _bt_delitems_delete_check(Relation rel, Buffer buf, Relation heapRel, TM_IndexDeleteOp *delstate)
bool _bt_vacuum_needs_cleanup(Relation rel)
static char * _bt_delitems_update(BTVacuumPosting *updatable, int nupdatable, OffsetNumber *updatedoffsets, Size *updatedbuflen, bool needswal)
static int _bt_delitems_cmp(const void *a, const void *b)
void _bt_pendingfsm_finalize(Relation rel, BTVacState *vstate)
void _bt_lockbuf(Relation rel, Buffer buf, int access)
Buffer _bt_getroot(Relation rel, Relation heaprel, int access)
void _bt_pendingfsm_init(Relation rel, BTVacState *vstate, bool cleanuponly)
static void _bt_pendingfsm_add(BTVacState *vstate, BlockNumber target, FullTransactionId safexid)
static bool _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, BlockNumber scanblkno, bool *rightsib_empty, BTVacState *vstate)
#define P_ISHALFDEAD(opaque)
static uint16 BTreeTupleGetNPosting(IndexTuple posting)
static FullTransactionId BTPageGetDeleteXid(Page page)
#define BTREE_MIN_VERSION
static void BTreeTupleSetTopParent(IndexTuple leafhikey, BlockNumber blkno)
#define P_LEFTMOST(opaque)
#define BTPageGetOpaque(page)
#define P_ISDELETED(opaque)
static BlockNumber BTreeTupleGetTopParent(IndexTuple leafhikey)
static void BTreeTupleSetDownLink(IndexTuple pivot, BlockNumber blkno)
#define P_FIRSTDATAKEY(opaque)
#define P_RIGHTMOST(opaque)
#define P_INCOMPLETE_SPLIT(opaque)
static ItemPointer BTreeTupleGetPostingN(IndexTuple posting, int n)
static bool BTPageIsRecyclable(Page page, Relation heaprel)
static BlockNumber BTreeTupleGetDownLink(IndexTuple pivot)
static ItemPointer BTreeTupleGetMaxHeapTID(IndexTuple itup)
static bool BTreeTupleIsPosting(IndexTuple itup)
static void BTPageSetDeleted(Page page, FullTransactionId safexid)
#define BTREE_NOVAC_VERSION
static ItemPointer BTreeTupleGetHeapTID(IndexTuple itup)
BTStack _bt_search(Relation rel, Relation heaprel, BTScanInsert key, Buffer *bufP, int access)
BTScanInsert _bt_mkscankey(Relation rel, IndexTuple itup)
#define SizeOfBtreeVacuum
#define XLOG_BTREE_META_CLEANUP
#define SizeOfBtreeUpdate
#define XLOG_BTREE_VACUUM
#define SizeOfBtreeDelete
#define SizeOfBtreeMarkPageHalfDead
#define XLOG_BTREE_UNLINK_PAGE
#define XLOG_BTREE_UNLINK_PAGE_META
#define SizeOfBtreeNewroot
#define XLOG_BTREE_MARK_PAGE_HALFDEAD
#define XLOG_BTREE_REUSE_PAGE
#define SizeOfBtreeUnlinkPage
#define SizeOfBtreeReusePage
#define XLOG_BTREE_NEWROOT
#define XLOG_BTREE_DELETE
#define InvalidOffsetNumber
#define OffsetNumberIsValid(offsetNumber)
#define OffsetNumberNext(offsetNumber)
#define qsort(a, b, c, d)
void PredicateLockPageCombine(Relation relation, BlockNumber oldblkno, BlockNumber newblkno)
TransactionId GetOldestNonRemovableTransactionId(Relation rel)
bool GlobalVisCheckRemovableFullXid(Relation rel, FullTransactionId fxid)
#define RelationGetRelationName(relation)
#define RelationIsAccessibleInLogicalDecoding(relation)
#define RelationNeedsWAL(relation)
#define RelationUsesLocalBuffers(relation)
void pg_usleep(long microsec)
static pg_noinline void Size size
uint32 btm_last_cleanup_num_delpages
float8 btm_last_cleanup_num_heap_tuples
FullTransactionId safexid
struct BTStackData * bts_parent
IndexBulkDeleteResult * stats
BTPendingFSM * pendingpages
uint16 deletetids[FLEXIBLE_ARRAY_MEMBER]
OffsetNumber updatedoffset
BlockNumber pages_deleted
BlockNumber pages_newly_deleted
MemoryContext rd_indexcxt
RelFileLocator rd_locator
TransactionId snapshotConflictHorizon
FullTransactionId snapshotConflictHorizon
FullTransactionId safexid
BlockNumber leaftopparent
static TransactionId table_index_delete_tuples(Relation rel, TM_IndexDeleteOp *delstate)
#define InvalidTransactionId
#define FullTransactionIdFollowsOrEquals(a, b)
FullTransactionId ReadNextFullTransactionId(void)
#define XLogStandbyInfoActive()
void XLogRegisterBufData(uint8 block_id, const char *data, uint32 len)
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void XLogRegisterData(const char *data, uint32 len)
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
void XLogBeginInsert(void)