nbtree.h
来自「PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开」· C头文件 代码 · 共 564 行 · 第 1/2 页
H
564 行
{ RelFileNode node; BlockNumber block; /* TARGET OFFSET NUMBERS FOLLOW AT THE END */} xl_btree_delete;#define SizeOfBtreeDelete (offsetof(xl_btree_delete, block) + sizeof(BlockNumber))/* * This is what we need to know about deletion of a btree page. The target * identifies the tuple removed from the parent page (note that we remove * this tuple's downlink and the *following* tuple's key). Note we do not * store any content for the deleted page --- it is just rewritten as empty * during recovery. */typedef struct xl_btree_delete_page{ xl_btreetid target; /* deleted tuple id in parent page */ BlockNumber deadblk; /* child block being deleted */ BlockNumber leftblk; /* child block's left sibling, if any */ BlockNumber rightblk; /* child block's right sibling */ /* xl_btree_metadata FOLLOWS IF XLOG_BTREE_DELETE_PAGE_META */} xl_btree_delete_page;#define SizeOfBtreeDeletePage (offsetof(xl_btree_delete_page, rightblk) + sizeof(BlockNumber))/* * New root log record. There are zero tuples if this is to establish an * empty root, or two if it is the result of splitting an old root. * * Note that although this implies rewriting the metadata page, we don't need * an xl_btree_metadata record --- the rootblk and level are sufficient. */typedef struct xl_btree_newroot{ RelFileNode node; BlockNumber rootblk; /* location of new root */ uint32 level; /* its tree level */ /* 0 or 2 INDEX TUPLES FOLLOW AT END OF STRUCT */} xl_btree_newroot;#define SizeOfBtreeNewroot (offsetof(xl_btree_newroot, level) + sizeof(uint32))/* * Operator strategy numbers for B-tree have been moved to access/skey.h, * because many places need to use them in ScanKeyInit() calls. *//* * When a new operator class is declared, we require that the user * supply us with an amproc procedure for determining whether, for * two keys a and b, a < b, a = b, or a > b. This routine must * return < 0, 0, > 0, respectively, in these three cases. Since we * only have one such proc in amproc, it's number 1. */#define BTORDER_PROC 1/* * We need to be able to tell the difference between read and write * requests for pages, in order to do locking correctly. */#define BT_READ BUFFER_LOCK_SHARE#define BT_WRITE BUFFER_LOCK_EXCLUSIVE/* * BTStackData -- As we descend a tree, we push the (location, downlink) * pairs from internal pages onto a private stack. If we split a * leaf, we use this stack to walk back up the tree and insert data * into parent pages (and possibly to split them, too). Lehman and * Yao's update algorithm guarantees that under no circumstances can * our private stack give us an irredeemably bad picture up the tree. * Again, see the paper for details. */typedef struct BTStackData{ BlockNumber bts_blkno; OffsetNumber bts_offset; IndexTupleData bts_btentry; struct BTStackData *bts_parent;} BTStackData;typedef BTStackData *BTStack;/* * BTScanOpaqueData is the btree-private state needed for an indexscan. * This consists of preprocessed scan keys (see _bt_preprocess_keys() for * details of the preprocessing), information about the current location * of the scan, and information about the marked location, if any. (We use * BTScanPosData to represent the data needed for each of current and marked * locations.) In addition we can remember some known-killed index entries * that must be marked before we can move off the current page. * * Index scans work a page at a time: we pin and read-lock the page, identify * all the matching items on the page and save them in BTScanPosData, then * release the read-lock while returning the items to the caller for * processing. This approach minimizes lock/unlock traffic. Note that we * keep the pin on the index page until the caller is done with all the items * (this is needed for VACUUM synchronization, see nbtree/README). When we * are ready to step to the next page, if the caller has told us any of the * items were killed, we re-lock the page to mark them killed, then unlock. * Finally we drop the pin and step to the next page in the appropriate * direction. * * NOTE: in this implementation, btree does not use or set the * currentItemData and currentMarkData fields of IndexScanDesc at all. */typedef struct BTScanPosItem /* what we remember about each match */{ ItemPointerData heapTid; /* TID of referenced heap item */ OffsetNumber indexOffset; /* index item's location within page */} BTScanPosItem;typedef struct BTScanPosData{ Buffer buf; /* if valid, the buffer is pinned */ BlockNumber nextPage; /* page's right link when we scanned it */ /* * moreLeft and moreRight track whether we think there may be matching * index entries to the left and right of the current page, respectively. * We can clear the appropriate one of these flags when _bt_checkkeys() * returns continuescan = false. */ bool moreLeft; bool moreRight; /* * The items array is always ordered in index order (ie, increasing * indexoffset). When scanning backwards it is convenient to fill the * array back-to-front, so we start at the last slot and fill downwards. * Hence we need both a first-valid-entry and a last-valid-entry counter. * itemIndex is a cursor showing which entry was last returned to caller. */ int firstItem; /* first valid index in items[] */ int lastItem; /* last valid index in items[] */ int itemIndex; /* current index in items[] */ BTScanPosItem items[MaxIndexTuplesPerPage]; /* MUST BE LAST */} BTScanPosData;typedef BTScanPosData *BTScanPos;#define BTScanPosIsValid(scanpos) BufferIsValid((scanpos).buf)typedef struct BTScanOpaqueData{ /* these fields are set by _bt_preprocess_keys(): */ bool qual_ok; /* false if qual can never be satisfied */ int numberOfKeys; /* number of preprocessed scan keys */ ScanKey keyData; /* array of preprocessed scan keys */ /* info about killed items if any (killedItems is NULL if never used) */ int *killedItems; /* currPos.items indexes of killed items */ int numKilled; /* number of currently stored items */ /* * If the marked position is on the same page as current position, we * don't use markPos, but just keep the marked itemIndex in markItemIndex * (all the rest of currPos is valid for the mark position). Hence, to * determine if there is a mark, first look at markItemIndex, then at * markPos. */ int markItemIndex; /* itemIndex, or -1 if not valid */ /* keep these last in struct for efficiency */ BTScanPosData currPos; /* current position data */ BTScanPosData markPos; /* marked position, if any */} BTScanOpaqueData;typedef BTScanOpaqueData *BTScanOpaque;/* * We use these private sk_flags bits in preprocessed scan keys */#define SK_BT_REQFWD 0x00010000 /* required to continue forward scan */#define SK_BT_REQBKWD 0x00020000 /* required to continue backward scan *//* * prototypes for functions in nbtree.c (external entry points for btree) */extern Datum btbuild(PG_FUNCTION_ARGS);extern Datum btinsert(PG_FUNCTION_ARGS);extern Datum btbeginscan(PG_FUNCTION_ARGS);extern Datum btgettuple(PG_FUNCTION_ARGS);extern Datum btgetmulti(PG_FUNCTION_ARGS);extern Datum btrescan(PG_FUNCTION_ARGS);extern Datum btendscan(PG_FUNCTION_ARGS);extern Datum btmarkpos(PG_FUNCTION_ARGS);extern Datum btrestrpos(PG_FUNCTION_ARGS);extern Datum btbulkdelete(PG_FUNCTION_ARGS);extern Datum btvacuumcleanup(PG_FUNCTION_ARGS);extern Datum btoptions(PG_FUNCTION_ARGS);/* * prototypes for functions in nbtinsert.c */extern void _bt_doinsert(Relation rel, IndexTuple itup, bool index_is_unique, Relation heapRel);extern Buffer _bt_getstackbuf(Relation rel, BTStack stack, int access);extern void _bt_insert_parent(Relation rel, Buffer buf, Buffer rbuf, BTStack stack, bool is_root, bool is_only);/* * prototypes for functions in nbtpage.c */extern void _bt_initmetapage(Page page, BlockNumber rootbknum, uint32 level);extern Buffer _bt_getroot(Relation rel, int access);extern Buffer _bt_gettrueroot(Relation rel);extern void _bt_checkpage(Relation rel, Buffer buf);extern Buffer _bt_getbuf(Relation rel, BlockNumber blkno, int access);extern Buffer _bt_relandgetbuf(Relation rel, Buffer obuf, BlockNumber blkno, int access);extern void _bt_relbuf(Relation rel, Buffer buf);extern void _bt_pageinit(Page page, Size size);extern bool _bt_page_recyclable(Page page);extern void _bt_delitems(Relation rel, Buffer buf, OffsetNumber *itemnos, int nitems);extern int _bt_pagedel(Relation rel, Buffer buf, BTStack stack, bool vacuum_full);/* * prototypes for functions in nbtsearch.c */extern BTStack _bt_search(Relation rel, int keysz, ScanKey scankey, bool nextkey, Buffer *bufP, int access);extern Buffer _bt_moveright(Relation rel, Buffer buf, int keysz, ScanKey scankey, bool nextkey, int access);extern OffsetNumber _bt_binsrch(Relation rel, Buffer buf, int keysz, ScanKey scankey, bool nextkey);extern int32 _bt_compare(Relation rel, int keysz, ScanKey scankey, Page page, OffsetNumber offnum);extern bool _bt_first(IndexScanDesc scan, ScanDirection dir);extern bool _bt_next(IndexScanDesc scan, ScanDirection dir);extern Buffer _bt_get_endpoint(Relation rel, uint32 level, bool rightmost);/* * prototypes for functions in nbtutils.c */extern ScanKey _bt_mkscankey(Relation rel, IndexTuple itup);extern ScanKey _bt_mkscankey_nodata(Relation rel);extern void _bt_freeskey(ScanKey skey);extern void _bt_freestack(BTStack stack);extern void _bt_preprocess_keys(IndexScanDesc scan);extern bool _bt_checkkeys(IndexScanDesc scan, Page page, OffsetNumber offnum, ScanDirection dir, bool *continuescan);extern void _bt_killitems(IndexScanDesc scan, bool haveLock);extern BTCycleId _bt_vacuum_cycleid(Relation rel);extern BTCycleId _bt_start_vacuum(Relation rel);extern void _bt_end_vacuum(Relation rel);extern Size BTreeShmemSize(void);extern void BTreeShmemInit(void);/* * prototypes for functions in nbtsort.c */typedef struct BTSpool BTSpool; /* opaque type known only within nbtsort.c */extern BTSpool *_bt_spoolinit(Relation index, bool isunique, bool isdead);extern void _bt_spooldestroy(BTSpool *btspool);extern void _bt_spool(IndexTuple itup, BTSpool *btspool);extern void _bt_leafbuild(BTSpool *btspool, BTSpool *spool2);/* * prototypes for functions in nbtxlog.c */extern void btree_redo(XLogRecPtr lsn, XLogRecord *record);extern void btree_desc(StringInfo buf, uint8 xl_info, char *rec);extern void btree_xlog_startup(void);extern void btree_xlog_cleanup(void);extern bool btree_safe_restartpoint(void);#endif /* NBTREE_H */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?