22 #include "catalog/pg_am_d.h" 74 #define BTP_LEAF (1 << 0) 75 #define BTP_ROOT (1 << 1) 76 #define BTP_DELETED (1 << 2) 77 #define BTP_META (1 << 3) 78 #define BTP_HALF_DEAD (1 << 4) 79 #define BTP_SPLIT_END (1 << 5) 80 #define BTP_HAS_GARBAGE (1 << 6) 81 #define BTP_INCOMPLETE_SPLIT (1 << 7) 82 #define BTP_HAS_FULLXID (1 << 8) 91 #define MAX_BT_CYCLE_ID 0xFF7F 119 #define BTPageGetMeta(p) \ 120 ((BTMetaPageData *) PageGetContents(p)) 146 #define BTREE_METAPAGE 0 147 #define BTREE_MAGIC 0x053162 148 #define BTREE_VERSION 4 149 #define BTREE_MIN_VERSION 2 150 #define BTREE_NOVAC_VERSION 3 162 #define BTMaxItemSize(page) \ 163 MAXALIGN_DOWN((PageGetPageSize(page) - \ 164 MAXALIGN(SizeOfPageHeaderData + \ 165 3*sizeof(ItemIdData) + \ 166 3*sizeof(ItemPointerData)) - \ 167 MAXALIGN(sizeof(BTPageOpaqueData))) / 3) 168 #define BTMaxItemSizeNoHeapTid(page) \ 169 MAXALIGN_DOWN((PageGetPageSize(page) - \ 170 MAXALIGN(SizeOfPageHeaderData + 3*sizeof(ItemIdData)) - \ 171 MAXALIGN(sizeof(BTPageOpaqueData))) / 3) 184 #define MaxTIDsPerBTreePage \ 185 (int) ((BLCKSZ - SizeOfPageHeaderData - sizeof(BTPageOpaqueData)) / \ 186 sizeof(ItemPointerData)) 198 #define BTREE_MIN_FILLFACTOR 10 199 #define BTREE_DEFAULT_FILLFACTOR 90 200 #define BTREE_NONLEAF_FILLFACTOR 70 201 #define BTREE_SINGLEVAL_FILLFACTOR 96 217 #define P_LEFTMOST(opaque) ((opaque)->btpo_prev == P_NONE) 218 #define P_RIGHTMOST(opaque) ((opaque)->btpo_next == P_NONE) 219 #define P_ISLEAF(opaque) (((opaque)->btpo_flags & BTP_LEAF) != 0) 220 #define P_ISROOT(opaque) (((opaque)->btpo_flags & BTP_ROOT) != 0) 221 #define P_ISDELETED(opaque) (((opaque)->btpo_flags & BTP_DELETED) != 0) 222 #define P_ISMETA(opaque) (((opaque)->btpo_flags & BTP_META) != 0) 223 #define P_ISHALFDEAD(opaque) (((opaque)->btpo_flags & BTP_HALF_DEAD) != 0) 224 #define P_IGNORE(opaque) (((opaque)->btpo_flags & (BTP_DELETED|BTP_HALF_DEAD)) != 0) 225 #define P_HAS_GARBAGE(opaque) (((opaque)->btpo_flags & BTP_HAS_GARBAGE) != 0) 226 #define P_INCOMPLETE_SPLIT(opaque) (((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT) != 0) 227 #define P_HAS_FULLXID(opaque) (((opaque)->btpo_flags & BTP_HAS_FULLXID) != 0) 348 #define P_HIKEY ((OffsetNumber) 1) 349 #define P_FIRSTKEY ((OffsetNumber) 2) 350 #define P_FIRSTDATAKEY(opaque) (P_RIGHTMOST(opaque) ? P_HIKEY : P_FIRSTKEY) 440 #define INDEX_ALT_TID_MASK INDEX_AM_RESERVED_BIT 443 #define BT_OFFSET_MASK 0x0FFF 444 #define BT_STATUS_OFFSET_MASK 0xF000 446 #define BT_PIVOT_HEAP_TID_ATTR 0x1000 447 #define BT_IS_POSTING 0x2000 551 #define BTreeTupleGetNAtts(itup, rel) \ 553 (BTreeTupleIsPivot(itup)) ? \ 555 ItemPointerGetOffsetNumberNoCheck(&(itup)->t_tid) & BT_OFFSET_MASK \ 558 IndexRelationGetNumberOfAttributes(rel) \ 573 Assert(!heaptid || nkeyatts > 0);
659 #define BTCommuteStrategyNumber(strat) (BTMaxStrategyNumber + 1 - (strat)) 681 #define BTORDER_PROC 1 682 #define BTSORTSUPPORT_PROC 2 683 #define BTINRANGE_PROC 3 684 #define BTEQUALIMAGE_PROC 4 685 #define BTOPTIONS_PROC 5 693 #define BT_READ BUFFER_LOCK_SHARE 694 #define BT_WRITE BUFFER_LOCK_EXCLUSIVE 969 #define BTScanPosIsPinned(scanpos) \ 971 AssertMacro(BlockNumberIsValid((scanpos).currPage) || \ 972 !BufferIsValid((scanpos).buf)), \ 973 BufferIsValid((scanpos).buf) \ 975 #define BTScanPosUnpin(scanpos) \ 977 ReleaseBuffer((scanpos).buf); \ 978 (scanpos).buf = InvalidBuffer; \ 980 #define BTScanPosUnpinIfPinned(scanpos) \ 982 if (BTScanPosIsPinned(scanpos)) \ 983 BTScanPosUnpin(scanpos); \ 986 #define BTScanPosIsValid(scanpos) \ 988 AssertMacro(BlockNumberIsValid((scanpos).currPage) || \ 989 !BufferIsValid((scanpos).buf)), \ 990 BlockNumberIsValid((scanpos).currPage) \ 992 #define BTScanPosInvalidate(scanpos) \ 994 (scanpos).currPage = InvalidBlockNumber; \ 995 (scanpos).nextPage = InvalidBlockNumber; \ 996 (scanpos).buf = InvalidBuffer; \ 997 (scanpos).lsn = InvalidXLogRecPtr; \ 998 (scanpos).nextTupleOffset = 0; \ 1060 #define SK_BT_REQFWD 0x00010000 1061 #define SK_BT_REQBKWD 0x00020000 1062 #define SK_BT_INDOPTION_SHIFT 24 1063 #define SK_BT_DESC (INDOPTION_DESC << SK_BT_INDOPTION_SHIFT) 1064 #define SK_BT_NULLS_FIRST (INDOPTION_NULLS_FIRST << SK_BT_INDOPTION_SHIFT) 1075 #define BTGetFillFactor(relation) \ 1076 (AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \ 1077 relation->rd_rel->relam == BTREE_AM_OID), \ 1078 (relation)->rd_options ? \ 1079 ((BTOptions *) (relation)->rd_options)->fillfactor : \ 1080 BTREE_DEFAULT_FILLFACTOR) 1081 #define BTGetTargetPageFreeSpace(relation) \ 1082 (BLCKSZ * (100 - BTGetFillFactor(relation)) / 100) 1083 #define BTGetDeduplicateItems(relation) \ 1084 (AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \ 1085 relation->rd_rel->relam == BTREE_AM_OID), \ 1086 ((relation)->rd_options ? \ 1087 ((BTOptions *) (relation)->rd_options)->deduplicate_items : true)) 1094 #define PROGRESS_BTREE_PHASE_INDEXBUILD_TABLESCAN 2 1095 #define PROGRESS_BTREE_PHASE_PERFORMSORT_1 3 1096 #define PROGRESS_BTREE_PHASE_PERFORMSORT_2 4 1097 #define PROGRESS_BTREE_PHASE_LEAF_LOAD 5 1106 bool indexUnchanged,
1114 ScanKey orderbys,
int norderbys);
1122 void *callback_state);
1140 bool checkingunique);
1167 bool *newitemonleft);
1173 bool allequalimage);
1181 bool *allequalimage);
1237 bool *res,
bool *isnull);
void btparallelrescan(IndexScanDesc scan)
BTInsertStateData * BTInsertState
BTCycleId _bt_start_vacuum(Relation rel)
struct BTInsertStateData BTInsertStateData
void btendscan(IndexScanDesc scan)
#define ItemPointerGetOffsetNumberNoCheck(pointer)
struct BTMetaPageData BTMetaPageData
bool _bt_first(IndexScanDesc scan, ScanDirection dir)
bool _bt_advance_array_keys(IndexScanDesc scan, ScanDirection dir)
struct BTOptions BTOptions
bool _bt_check_natts(Relation rel, bool heapkeyspace, Page page, OffsetNumber offnum)
void _bt_preprocess_keys(IndexScanDesc scan)
bool btinsert(Relation rel, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, struct IndexInfo *indexInfo)
MemoryContext pagedelcontext
int _bt_getrootheight(Relation rel)
BTStack _bt_search(Relation rel, BTScanInsert key, Buffer *bufP, int access, Snapshot snapshot)
static bool BTreeTupleIsPivot(IndexTuple itup)
static ItemPointer BTreeTupleGetHeapTID(IndexTuple itup)
void _bt_pageinit(Page page, Size size)
bool _bt_checkkeys(IndexScanDesc scan, IndexTuple tuple, int tupnatts, ScanDirection dir, bool *continuescan)
MemoryContext arrayContext
void _bt_checkpage(Relation rel, Buffer buf)
static ItemPointer BTreeTupleGetPosting(IndexTuple posting)
OffsetNumber updatedoffset
IndexBulkDeleteCallback callback
static BlockNumber BTreeTupleGetDownLink(IndexTuple pivot)
#define FLEXIBLE_ARRAY_MEMBER
Buffer _bt_getstackbuf(Relation rel, BTStack stack, BlockNumber child)
IndexBulkDeleteResult * btbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
bool _bt_bottomupdel_pass(Relation rel, Buffer buf, Relation heapRel, Size newitemsz)
struct BTDedupInterval BTDedupInterval
BTVacuumPostingData * BTVacuumPosting
Buffer _bt_getbuf(Relation rel, BlockNumber blkno, int access)
void _bt_check_third_page(Relation rel, Relation heap, bool needheaptidspace, Page page, IndexTuple newtup)
void btinitparallelscan(void *target)
void _bt_end_vacuum_callback(int code, Datum arg)
void _bt_delitems_delete_check(Relation rel, Buffer buf, Relation heapRel, TM_IndexDeleteOp *delstate)
#define SizeOfPageHeaderData
#define MaxTIDsPerBTreePage
IndexTuple _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
void _bt_delitems_vacuum(Relation rel, Buffer buf, OffsetNumber *deletable, int ndeletable, BTVacuumPosting *updatable, int nupdatable)
struct BTVacState BTVacState
void btrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
BTPageOpaqueData * BTPageOpaque
IndexTuple _bt_truncate(Relation rel, IndexTuple lastleft, IndexTuple firstright, BTScanInsert itup_key)
struct BTScanPosData BTScanPosData
char * btbuildphasename(int64 phasenum)
#define P_HAS_FULLXID(opaque)
IndexBuildResult * btbuild(Relation heap, Relation index, struct IndexInfo *indexInfo)
void _bt_update_posting(BTVacuumPosting vacposting)
void _bt_parallel_done(IndexScanDesc scan)
static void BTreeTupleSetNAtts(IndexTuple itup, uint16 nkeyatts, bool heaptid)
void btadjustmembers(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
struct BTPageOpaqueData BTPageOpaqueData
bool btcanreturn(Relation index, int attno)
void _bt_mark_array_keys(IndexScanDesc scan)
float8 vacuum_cleanup_index_scale_factor
#define INDEX_ALT_TID_MASK
void _bt_upgradelockbufcleanup(Relation rel, Buffer buf)
void _bt_parallel_advance_array_keys(IndexScanDesc scan)
int32 _bt_compare(Relation rel, BTScanInsert key, Page page, OffsetNumber offnum)
void _bt_initmetapage(Page page, BlockNumber rootbknum, uint32 level, bool allequalimage)
BTScanOpaqueData * BTScanOpaque
struct BTArrayKeyInfo BTArrayKeyInfo
void _bt_metaversion(Relation rel, bool *heapkeyspace, bool *allequalimage)
void _bt_set_cleanup_info(Relation rel, BlockNumber num_delpages, float8 num_heap_tuples)
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
struct BTScanPosItem BTScanPosItem
static void BTreeTupleSetPosting(IndexTuple itup, uint16 nhtids, int postingoffset)
#define FirstNormalFullTransactionId
FullTransactionId safexid
void _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
struct BTScanInsertData BTScanInsertData
bool btvalidate(Oid opclassoid)
Buffer _bt_moveright(Relation rel, BTScanInsert key, Buffer buf, bool forupdate, BTStack stack, int access, Snapshot snapshot)
IndexScanDesc btbeginscan(Relation rel, int nkeys, int norderbys)
void _bt_unlockbuf(Relation rel, Buffer buf)
void BTreeShmemInit(void)
void btrestrpos(IndexScanDesc scan)
BTCycleId _bt_vacuum_cycleid(Relation rel)
Size btestimateparallelscan(void)
static void BTreeTupleSetDownLink(IndexTuple pivot, BlockNumber blkno)
void _bt_end_vacuum(Relation rel)
void _bt_freestack(BTStack stack)
void _bt_upgrademetapage(Page page)
uint32 btm_last_cleanup_num_delpages
#define P_ISDELETED(opaque)
void _bt_parallel_release(IndexScanDesc scan, BlockNumber scan_page)
BTScanPosData * BTScanPos
bool _bt_doinsert(Relation rel, IndexTuple itup, IndexUniqueCheck checkUnique, bool indexUnchanged, Relation heapRel)
static ItemPointer BTreeTupleGetMaxHeapTID(IndexTuple itup)
bool _bt_next(IndexScanDesc scan, ScanDirection dir)
IndexBulkDeleteResult * btvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
bool _bt_conditionallockbuf(Relation rel, Buffer buf)
void _bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel, IndexTuple newitem, Size newitemsz, bool checkingunique)
#define PageGetContents(page)
Size _bt_dedup_finish_pending(Page newpage, BTDedupState state)
bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup)
int _bt_keep_natts_fast(Relation rel, IndexTuple lastleft, IndexTuple firstright)
bool btproperty(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
void _bt_relbuf(Relation rel, Buffer buf)
static ItemPointer BTreeTupleGetPostingN(IndexTuple posting, int n)
OffsetNumber _bt_binsrch_insert(Relation rel, BTInsertState insertstate)
static void BTPageSetDeleted(Page page, FullTransactionId safexid)
static bool BTreeTupleIsPosting(IndexTuple itup)
static uint32 BTreeTupleGetPostingOffset(IndexTuple posting)
bool GlobalVisCheckRemovableFullXid(Relation rel, FullTransactionId fxid)
void _bt_killitems(IndexScanDesc scan)
PageHeaderData * PageHeader
#define Assert(condition)
IndexTuple _bt_form_posting(IndexTuple base, ItemPointer htids, int nhtids)
void _bt_dedup_start_pending(BTDedupState state, IndexTuple base, OffsetNumber baseoff)
void _bt_restore_array_keys(IndexScanDesc scan)
bool _bt_allequalimage(Relation rel, bool debugmessage)
Buffer _bt_getroot(Relation rel, int access)
void _bt_finish_split(Relation rel, Buffer lbuf, BTStack stack)
#define BT_STATUS_OFFSET_MASK
Buffer _bt_relandgetbuf(Relation rel, Buffer obuf, BlockNumber blkno, int access)
static FullTransactionId BTPageGetDeleteXid(Page page)
struct ItemPointerData ItemPointerData
void _bt_lockbuf(Relation rel, Buffer buf, int access)
#define PageGetSpecialPointer(page)
static bool BTPageIsRecyclable(Page page)
float8 btm_last_cleanup_num_heap_tuples
static const struct fns functions
struct BTStackData * bts_parent
IndexBulkDeleteResult * stats
#define ItemPointerSetBlockNumber(pointer, blockNumber)
static void header(const char *fmt,...) pg_attribute_printf(1
OffsetNumber _bt_findsplitloc(Relation rel, Page origpage, OffsetNumber newitemoff, Size newitemsz, IndexTuple newitem, bool *newitemonleft)
#define ItemPointerSetOffsetNumber(pointer, offsetNumber)
static Datum values[MAXATTR]
struct BTVacuumPostingData BTVacuumPostingData
int64 btgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
bool btgettuple(IndexScanDesc scan, ScanDirection dir)
#define MaxIndexTuplesPerPage
void btmarkpos(IndexScanDesc scan)
#define ItemPointerGetBlockNumberNoCheck(pointer)
Buffer _bt_get_endpoint(Relation rel, uint32 level, bool rightmost, Snapshot snapshot)
BTArrayKeyInfo * arrayKeys
void _bt_start_array_keys(IndexScanDesc scan, ScanDirection dir)
BTScanInsert _bt_mkscankey(Relation rel, IndexTuple itup)
static BlockNumber BTreeTupleGetTopParent(IndexTuple leafhikey)
struct BTDeletedPageData BTDeletedPageData
static uint16 BTreeTupleGetNPosting(IndexTuple posting)
Size BTreeShmemSize(void)
struct BTDedupStateData BTDedupStateData
BTDedupStateData * BTDedupState
#define BT_PIVOT_HEAP_TID_ATTR
bool _bt_parallel_seize(IndexScanDesc scan, BlockNumber *pageno)
BTScanInsertData * BTScanInsert
LocationIndex tupleOffset
bytea * btoptions(Datum reloptions, bool validate)
struct BTStackData BTStackData
void _bt_pagedel(Relation rel, Buffer leafbuf, BTVacState *vstate)
void btbuildempty(Relation index)
static void BTreeTupleSetTopParent(IndexTuple leafhikey, BlockNumber blkno)
struct BTScanOpaqueData BTScanOpaqueData
void _bt_preprocess_array_keys(IndexScanDesc scan)
#define IndexTupleSize(itup)
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Buffer _bt_gettrueroot(Relation rel)