BTreeIndex class. It implements a B+ Tree index on a single attribute of a relation. This index supports only one scan at a time. More...
#include <btree.h>
Public Member Functions | |
BTreeIndex (const std::string &relationName, std::string &outIndexName, BufMgr *bufMgrIn, const int attrByteOffset, const Datatype attrType) | |
~BTreeIndex () | |
const void | insertEntry (const void *key, const RecordId rid) |
const void | startScan (const void *lowVal, const Operator lowOp, const void *highVal, const Operator highOp) |
const void | scanNext (RecordId &outRid) |
const void | endScan () |
BTreeIndex class. It implements a B+ Tree index on a single attribute of a relation. This index supports only one scan at a time.
badgerdb::BTreeIndex::BTreeIndex | ( | const std::string & | relationName, |
std::string & | outIndexName, | ||
BufMgr * | bufMgrIn, | ||
const int | attrByteOffset, | ||
const Datatype | attrType | ||
) |
BTreeIndex Constructor. Check to see if the corresponding index file exists. If so, open the file. If not, create it and insert entries for every tuple in the base relation using FileScan class.
relationName | Name of file. |
outIndexName | Return the name of index file. |
bufMgrIn | Buffer Manager Instance |
attrByteOffset | Offset of attribute, over which index is to be built, in the record |
attrType | Datatype of attribute over which index is built |
BadIndexInfoException | If the index file already exists for the corresponding attribute, but values in metapage(relationName, attribute byte offset, attribute type etc.) do not match with values received through constructor parameters. |
Definition at line 29 of file btree.cpp.
{ }
BTreeIndex Destructor. End any initialized scan, flush index file, after unpinning any pinned pages, from the buffer manager and delete file instance thereby closing the index file. Destructor should not throw any exceptions. All exceptions should be caught in here itself.
Definition at line 43 of file btree.cpp.
{ }
const void badgerdb::BTreeIndex::endScan | ( | ) |
Terminate the current scan. Unpin any pinned pages. Reset scan specific variables.
ScanNotInitializedException | If no scan has been initialized. |
Definition at line 81 of file btree.cpp.
{ }
const void badgerdb::BTreeIndex::insertEntry | ( | const void * | key, |
const RecordId | rid | ||
) |
Insert a new entry using the pair <value,rid>. Start from root to recursively find out the leaf to insert the entry in. The insertion may cause splitting of leaf node. This splitting will require addition of new leaf page number entry into the parent non-leaf, which may in-turn get split. This may continue all the way upto the root causing the root to get split. If root gets split, metapage needs to be changed accordingly. Make sure to unpin pages as soon as you can.
key | Key to insert, pointer to integer/double/char string |
rid | Record ID of a record whose entry is getting inserted into the index. |
Definition at line 51 of file btree.cpp.
{ }
const void badgerdb::BTreeIndex::scanNext | ( | RecordId & | outRid | ) |
Fetch the record id of the next index entry that matches the scan. Return the next record from current page being scanned. If current page has been scanned to its entirety, move on to the right sibling of current page, if any exists, to start scanning that page. Make sure to unpin any pages that are no longer required.
outRid | RecordId of next record found that satisfies the scan criteria returned in this |
ScanNotInitializedException | If no scan has been initialized. |
IndexScanCompletedException | If no more records, satisfying the scan criteria, are left to be scanned. |
Definition at line 72 of file btree.cpp.
{ }
const void badgerdb::BTreeIndex::startScan | ( | const void * | lowVal, |
const Operator | lowOp, | ||
const void * | highVal, | ||
const Operator | highOp | ||
) |
Begin a filtered scan of the index. For instance, if the method is called using ("a",GT,"d",LTE) then we should seek all entries with a value greater than "a" and less than or equal to "d". If another scan is already executing, that needs to be ended here. Set up all the variables for scan. Start from root to find out the leaf page that contains the first RecordID that satisfies the scan parameters. Keep that page pinned in the buffer pool.
lowVal | Low value of range, pointer to integer / double / char string |
lowOp | Low operator (GT/GTE) |
highVal | High value of range, pointer to integer / double / char string |
highOp | High operator (LT/LTE) |
BadOpcodesException | If lowOp and highOp do not contain one of their their expected values |
BadScanrangeException | If lowVal > highval |
NoSuchKeyFoundException | If there is no key in the B+ tree that satisfies the scan criteria. |
Definition at line 60 of file btree.cpp.
{ }