1 #ifndef INDEX_BTREE_BTREE_H 
    2 #define INDEX_BTREE_BTREE_H 
   76     static std::unique_ptr<BTree> 
Create(
 
   77         std::shared_ptr<const IndexDesc> idxdesc);
 
   80     BTree(std::shared_ptr<const IndexDesc> idxdesc,
 
   81           std::unique_ptr<File> file,
 
   82           std::vector<FunctionInfo> lt_funcs,
 
   83           std::vector<FunctionInfo> eq_funcs);
 
  103                                                bool upper_isstrict) 
override;
 
  121         bool Next() 
override;
 
  134                  const IndexKey *key, 
bool upper_isstrict);
 
  211                           const char *tuplebuf,
 
  250                           std::vector<PathItem> *p_search_path);
 
  276                           std::vector<PathItem> *p_search_path);
 
  306                             std::vector<PathItem> &&search_path);
 
  369                                     std::vector<PathItem> &search_path);
 
  390                             std::vector<PathItem> &&search_path);
 
bool Next() override
Moves the iterator to the next indexed item if any.
Definition: BTreeIterator.cpp:53
 
SlotId m_sid
Definition: BTree.h:138
 
bool m_upper_isstrict
Definition: BTree.h:146
 
RecordId GetCurrentRecordId() override
Returns the record id of the indexed item the iterator is currently at.
Definition: BTreeIterator.cpp:109
 
void EndScan() override
Ends the index scan.
Definition: BTreeIterator.cpp:114
 
const Record & GetCurrentItem() override
Returns the current indexed item the iterator is currently at, where the GetData() and GetLength() pa...
Definition: BTreeIterator.cpp:104
 
ScopedBufferId m_bufid
Definition: BTree.h:136
 
~Iterator()
Definition: BTree.h:117
 
std::vector< Datum > m_upper_data_buffer
Definition: BTree.h:144
 
Record m_rec
Definition: BTree.h:140
 
UniqueIndexKey m_upper
Definition: BTree.h:142
 
bool IsAtValidItem() override
Returns whether the iterator is currently at a valid indexed item.
Definition: BTreeIterator.cpp:99
 
A B-tree stored in the persistent files.
Definition: BTree.h:70
 
bool IsEmpty()
Returns whether this tree is empty.
Definition: BTree.cpp:109
 
BufferId GetBTreeMetaPage()
Pins the BTree meta page and returns the buffer ID of the buffer frame where it is pinned.
Definition: BTreeUtils.cpp:46
 
bool MergePages(BufferId lbufid, BufferId rbufid, BufferId pbufid, SlotId lsid)
Merges two sibling pages if there're enough space.
Definition: BTreeDelete.cpp:288
 
void HandleMinPageUsage(BufferId bufid, std::vector< PathItem > &&search_path)
Checks if a page pinned in buffer frame bufid needs to be merged or rebalanced with a sibling page sh...
Definition: BTreeDelete.cpp:139
 
friend class TestBTree
Definition: BTree.h:437
 
void CreateInternalRecord(const Record &child_recbuf, PageNumber child_pid, bool child_isleaf, maxaligned_char_buf &recbuf)
Creates a new internal record with separator key and heap record id from child_recbuf,...
Definition: BTreeUtils.cpp:67
 
int BTreeTupleCompare(const IndexKey *key, const RecordId &recid, const char *tuplebuf, bool isleaf) const
Compares a (key, recid) pair to a leaf or internal record in the B-tree.
Definition: BTreeSearch.cpp:8
 
bool RebalancePages(BufferId lbufid, BufferId rbufid, BufferId pbufid, SlotId lsid)
Rebalances two sibling pages if it is possible and it should choose a way that minimizes the differen...
Definition: BTreeDelete.cpp:395
 
void InsertRecordOnPage(BufferId bufid, SlotId insertion_sid, maxaligned_char_buf &&recbuf, std::vector< PathItem > &&search_path)
Inserts a record in recbuf onto a leaf page already pinned in the buffer frame bufid whose key range ...
Definition: BTreeInsert.cpp:95
 
SlotId BinarySearchOnPage(char *buf, const IndexKey *key, const RecordId &recid)
Uses binary search to find the last slot whose key-recid pair is smaller than or equal to the (key,...
Definition: BTreeSearch.cpp:46
 
static std::unique_ptr< BTree > Create(std::shared_ptr< const IndexDesc > idxdesc)
Definition: BTree.cpp:67
 
void CreateLeafRecord(const IndexKey *key, const RecordId &recid, maxaligned_char_buf &recbuf)
Creates a new leaf record with the given key and heap \recid in recbuf.
Definition: BTreeUtils.cpp:53
 
static void Initialize(const IndexDesc *idxdesc)
Definition: BTree.cpp:17
 
std::unique_ptr< File > m_file
Definition: BTree.h:85
 
bool InsertKey(const IndexKey *key, RecordId recid) override
Inserts the (key, rid) pair into the index.
Definition: BTreeInsert.cpp:6
 
std::unique_ptr< Index::Iterator > StartScan(const IndexKey *lower, bool lower_isstrict, const IndexKey *upper, bool upper_isstrict) override
Returns a forward-iterator for all the indexed items in the specified range defined by the arguments.
Definition: BTreeIterator.cpp:7
 
BufferId FindLeafPage(const IndexKey *key, const RecordId &recid, std::vector< PathItem > *p_search_path)
Finds a leaf page from the root such that:
Definition: BTreeSearch.cpp:83
 
bool TryMergeOrRebalancePages(BufferId lbufid, BufferId rbufid, BufferId pbufid, SlotId lsid)
Try to merge or reblanace two sibling pages.
Definition: BTreeDelete.cpp:266
 
BTree(std::shared_ptr< const IndexDesc > idxdesc, std::unique_ptr< File > file, std::vector< FunctionInfo > lt_funcs, std::vector< FunctionInfo > eq_funcs)
Definition: BTree.cpp:95
 
BufferId CreateNewBTreePage(bool isroot, bool isleaf, PageNumber prev_pid, PageNumber next_pid)
Allocates and initializes a new BTree internal or leaf page.
Definition: BTreeUtils.cpp:28
 
void BulkLoad(BulkLoadIterator &iter) override
Loads all the (key, record id) pairs provided by the iterator iter into an empty index.
Definition: BTreeBulkLoad.cpp:6
 
virtual ~BTree()
Definition: BTree.cpp:105
 
SlotId FindDeletionSlotIdOnLeaf(const IndexKey *key, const RecordId &recid, BufferId &bufid, std::vector< PathItem > &search_path)
Finds the slot to delete for the (key, recid) pair.
Definition: BTreeDelete.cpp:46
 
maxaligned_char_buf SplitPage(BufferId bufid, SlotId insertion_sid, maxaligned_char_buf &&recbuf)
Splits a page pinned in bufid that is too full to insert an additional record in recbuf at slot inser...
Definition: BTreeInsert.cpp:190
 
bool DeleteKey(const IndexKey *key, RecordId &recid) override
Deletes an arbitrary data entry with matching key if rid is invalid.
Definition: BTreeDelete.cpp:13
 
void DeleteSlotOnPage(BufferId bufid, SlotId sid)
Deletes a slot from a page.
Definition: BTreeDelete.cpp:122
 
uint32_t GetTreeHeight()
Returns the tree height.
Definition: BTree.cpp:123
 
SlotId FindInsertionSlotIdOnLeaf(const IndexKey *key, const RecordId &recid, BufferId bufid)
Finds the slot id where the inserting (key, recid) pair at that slot will keep the page's key and rec...
Definition: BTreeInsert.cpp:47
 
std::vector< FunctionInfo > m_lt_funcs
Definition: BTree.h:87
 
std::vector< FunctionInfo > m_eq_funcs
Definition: BTree.h:89
 
void CreateNewRoot(BufferId bufid, maxaligned_char_buf &&recbuf)
Creates a new root page and updates the B-Tree meta page.
Definition: BTreeInsert.cpp:141
 
BulkLoadIterator is an interface for providing (key, RecordId) pairs for index bulk loading.
Definition: BulkLoadIterator.h:17
 
Definition: IndexDesc.h:11
 
A forward-iterator for the items in the index.
Definition: Index.h:181
 
An interface class for index implementations.
Definition: Index.h:19
 
uint64_t BufferId
Definition: tdb_base.h:214
 
uint16_t SlotId
Definition: tdb_base.h:222
 
std::unique_ptr< IndexKey, AlignedAllocImpl::FreeMem > UniqueIndexKey
The returned smart pointer of IndexKey::Create().
Definition: IndexKey.h:10
 
uint32_t PageNumber
Definition: tdb_base.h:213
 
RecordId PathItem
Each PathItem is a (PageNumber, SlotId) pair of an B-tree internal record.
Definition: BTree.h:21
 
An IndexKey stores references to a few data (Datum objects) that comprise a key tuple to in an index.
Definition: IndexKey.h:35
 
The record ID of a record on a page is a pair of ‘(PageNumber, SlotId)’.
Definition: Record.h:17
 
std::vector< char, AlignedAllocImpl::aligned_allocator< 8, char > > maxaligned_char_buf
Definition: tdb_base.h:155