WiscDB
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends
Public Member Functions
wiscdb::BTreeIndex Class Reference

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>

List of all members.

Public Member Functions

 BTreeIndex (const std::string &relationName, std::string &outIndexName, BufferManager *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 ()

Detailed Description

BTreeIndex class. It implements a B+ Tree index on a single attribute of a relation. This index supports only one scan at a time.

Definition at line 293 of file btree.h.


Constructor & Destructor Documentation

wiscdb::BTreeIndex::BTreeIndex ( const std::string &  relationName,
std::string &  outIndexName,
BufferManager 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 FileScanner class.

Parameters:
relationNameName of file.
outIndexNameReturn the name of index file.
bufMgrInBuffer Manager Instance
attrByteOffsetOffset of attribute, over which index is to be built, in the record
attrTypeDatatype of attribute over which index is built
Exceptions:
BadIndexInfoExceptionIf 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.


Member Function Documentation

Terminate the current scan. Unpin any pinned pages. Reset scan specific variables.

Exceptions:
ScanNotInitializedExceptionIf no scan has been initialized.

Definition at line 81 of file btree.cpp.

const void wiscdb::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.

Parameters:
keyKey to insert, pointer to integer/double/char string
ridRecord ID of a record whose entry is getting inserted into the index.

Definition at line 51 of file btree.cpp.

const void wiscdb::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.

Parameters:
outRidRecordId of next record found that satisfies the scan criteria returned in this
Exceptions:
ScanNotInitializedExceptionIf no scan has been initialized.
IndexScanCompletedExceptionIf no more records, satisfying the scan criteria, are left to be scanned.

Definition at line 72 of file btree.cpp.

const void wiscdb::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.

Parameters:
lowValLow value of range, pointer to integer / double / char string
lowOpLow operator (GT/GTE)
highValHigh value of range, pointer to integer / double / char string
highOpHigh operator (LT/LTE)
Exceptions:
BadOpcodesExceptionIf lowOp and highOp do not contain one of their their expected values
BadScanrangeExceptionIf lowVal > highval
NoSuchKeyFoundExceptionIf there is no key in the B+ tree that satisfies the scan criteria.

Definition at line 60 of file btree.cpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends