📄 nbtree.h
字号:
* split record should follow. Note that a split record never carries a * metapage update --- we'll do that in the parent-level update. */typedef struct xl_btree_split{ xl_btreetid target; /* inserted tuple id */ BlockNumber otherblk; /* second block participated in split: */ /* first one is stored in target' tid */ BlockNumber leftblk; /* prev/left block */ BlockNumber rightblk; /* next/right block */ uint32 level; /* tree level of page being split */ uint16 leftlen; /* len of left page items below */ /* LEFT AND RIGHT PAGES TUPLES FOLLOW AT THE END */} xl_btree_split;#define SizeOfBtreeSplit (offsetof(xl_btree_split, leftlen) + sizeof(uint16))/* * This is what we need to know about delete of individual leaf btitems. * The WAL record can represent deletion of any number of btitems on a * single index page. */typedef struct xl_btree_delete{ 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 btitems 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 BTITEMS FOLLOW AT END OF STRUCT */} xl_btree_newroot;#define SizeOfBtreeNewroot (offsetof(xl_btree_newroot, level) + sizeof(uint32))/* * New metapage log record. This is not issued during routine operations; * it's only used when initializing an empty index. */typedef struct xl_btree_newmeta{ RelFileNode node; xl_btree_metadata meta;} xl_btree_newmeta;#define SizeOfBtreeNewmeta (sizeof(xl_btree_newmeta))/* * 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; BTItemData bts_btitem; struct BTStackData *bts_parent;} BTStackData;typedef BTStackData *BTStack;/* * BTScanOpaqueData is used to remember which buffers we're currently * examining in the scan. We keep these buffers pinned (but not locked, * see nbtree.c) and recorded in the opaque entry of the scan to avoid * doing a ReadBuffer() for every tuple in the index. * * And it's used to remember actual scankey info (we need it * if some scankeys evaled at runtime). * * curHeapIptr & mrkHeapIptr are heap iptr-s from current/marked * index tuples: we don't adjust scans on insertions (and, if LLL * is ON, don't hold locks on index pages between passes) - we * use these pointers to restore index scan positions... * - vadim 07/29/98 */typedef struct BTScanOpaqueData{ Buffer btso_curbuf; Buffer btso_mrkbuf; ItemPointerData curHeapIptr; ItemPointerData mrkHeapIptr; /* 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 */ int numberOfRequiredKeys; /* number of keys that must be matched * to continue the scan */ ScanKey keyData; /* array of preprocessed scan keys */} BTScanOpaqueData;typedef BTScanOpaqueData *BTScanOpaque;/* * 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);/* * prototypes for functions in nbtinsert.c */extern void _bt_doinsert(Relation rel, BTItem btitem, 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_metapinit(Relation rel);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 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_wrtbuf(Relation rel, Buffer buf);extern void _bt_wrtnorelbuf(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, 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_next(IndexScanDesc scan, ScanDirection dir);extern bool _bt_first(IndexScanDesc scan, ScanDirection dir);extern bool _bt_step(IndexScanDesc scan, Buffer *bufP, 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, IndexTuple tuple, ScanDirection dir, bool *continuescan);extern BTItem _bt_formitem(IndexTuple itup);/* * 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(BTItem btitem, 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(char *buf, uint8 xl_info, char *rec);extern void btree_xlog_startup(void);extern void btree_xlog_cleanup(void);#endif /* NBTREE_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -