SwatDB
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Friends | List of all members
HashIndexFile Class Reference
Inheritance diagram for HashIndexFile:
Inheritance graph
[legend]
Collaboration diagram for HashIndexFile:
Collaboration graph
[legend]

Public Member Functions

 HashIndexFile (Catalog *catalog, BufferManager *buf_mgr, FileId relation, std::vector< std::string > field_list)
 Constructor for IndexFile class.
 
 HashIndexFile (Catalog *catalog, BufferManager *buf_mgr, FileId relation, std::vector< FieldId > field_list)
 Constructor for IndexFile class.
 
 ~HashIndexFile ()
 Destructor. Data members are cleaned up, but none of the dynamically allocated data members are deleted except for the search key format that is created in the constructor. The underlying Unix file is not deleted.
 
void createHeader ()
 Allocates and initializes the header Page of the file.
 
void flushHeader ()
 Flushes header Page to disk.
 
void insertEntry (Key key, RecordId record_id)
 Inserts an Entry into the HashIndexFile.
 
std::vector< RecordIdgetEntries (Key key)
 Returns a list all RecordIds with the given Key.
 
void deleteEntry (Key key, RecordId record_id)
 Method for deleting an entry of the given Key and RecordId.
 
void deleteKey (Key key)
 Method for deleting all entires with the given key.
 
HashIndexHeader getHeader ()
 THIS METHOD IS FOR DEBUGGING ONLY. Returns the current HashIndexHeader.
 
- Public Member Functions inherited from IndexFile
 IndexFile (Catalog *catalog, BufferManager *buf_mgr, FileId relation, std::vector< std::string > field_list)
 Constructor for IndexFile class.
 
 IndexFile (Catalog *catalog, BufferManager *buf_mgr, FileId relation, std::vector< FieldId > field_list)
 Constructor for IndexFile class.
 
virtual ~IndexFile ()
 Destructor. Data members are cleaned up, but none of the dynamically allocated data members are deleted. The underlying Unix file is not deleted.
 
SearchKeyFormatgetKeyFormat ()
 Returns the key format of the Index.
 
- Public Member Functions inherited from File
 File (Catalog *catalog, BufferManager *buf_mgr)
 Constructor. Initializes common state associated with every file, including catalog, buf_mgr, and schema.
 
virtual ~File ()
 Destructor. Data members are cleaned up, but none of the dynamically allocated data members are deleted. The underlying Unix file is not deleted.
 
FileId getFileId ()
 Returns the FileId of the File.
 
virtual void printFile ()
 Prints out information and/or the contents of the file. Can be overwritten in derived classes. Useful for debugging and testing purposes.
 
PageId getHeaderId ()
 Returns Header PageId.
 

Private Member Functions

std::pair< SlotId, SlotId > _findDirSlot (HashVal hash_val, Level level)
 Helper function for computing the location of the slot for PageNum of the bucket, corresponding to the given hash value and global level.

 
void _levelUp (HashIndexHeader *file_header)
 Helper function for incrementing the global level of the hash index.
 
PageId _splitPage (HashIndexHeader *file_header, HashBucketPage *bucket_page, PageId bucket_page_id)
 Helper function for splitting a bucket.
 

Friends

class HashIndexScanner
 

Additional Inherited Members

- Protected Member Functions inherited from File
void _setFileId (FileId file_id)
 Sets the file_id and the schema fields of this File.
 
- Protected Attributes inherited from IndexFile
FileId relation
 
SearchKeyFormatkey_format
 
- Protected Attributes inherited from File
FileId file_id
 
Catalogcatalog
 
BufferManagerbuf_mgr
 
PageId header_id
 

Constructor & Destructor Documentation

◆ HashIndexFile() [1/2]

HashIndexFile::HashIndexFile ( Catalog catalog,
BufferManager buf_mgr,
FileId  relation,
std::vector< std::string >  field_list 
)

Constructor for IndexFile class.

Precondition
A valid Catalog pointer and BufferManager pointer are provided as inputs.
Postcondition
IndexFile object is constructed. Catalog, BufferManager,
and relation FileId are set to the given values. Appropriate key format is constructed based on field_list. FileId and Header Page data are set later.
Parameters
catalogPointer to the SwatDB Catalog object.
buf_mgrPointer to the SwatDB BufferManager object.
relationFileId of the relation of which the index is created.
field_listThe list of the attributes for which the index is created.

◆ HashIndexFile() [2/2]

HashIndexFile::HashIndexFile ( Catalog catalog,
BufferManager buf_mgr,
FileId  relation,
std::vector< FieldId field_list 
)

Constructor for IndexFile class.

Precondition
A valid Catalog pointer and BufferManager pointer are provided as inputs.
Postcondition
IndexFile object is constructed. Catalog, BufferManager,
and relation FileId are set to the given values. Appropriate key format is constructed based on field_list. FileId and Header Page data are set later.
Parameters
catalogPointer to the SwatDB Catalog object.
buf_mgrPointer to the SwatDB BufferManager object.
relationFileId of the relation of which the index is created.
field_listThe list of the attributes for which the index is created.

Member Function Documentation

◆ _findDirSlot()

std::pair< SlotId, SlotId > HashIndexFile::_findDirSlot ( HashVal  hash_val,
Level  level 
)
private

Helper function for computing the location of the slot for PageNum of the bucket, corresponding to the given hash value and global level.

Precondition
None.
Postcondition
A std::pair of SlotId is returned. The first entry of the pair is the slot in the header page, containing PageNum of the directory Page that stores the PageNum of the bucket corresponding to the hash value at the given level. The second entry of the pair is slot in the directory page, containing the PageNum of the bucket corresponding to the hash value at the given level. For example, if function with input parameters of 0b1 and 1 returns <0,1>, the PageNum of the directory page is at 0th slot of dir PageNum array in the header page and the PageNum of the bucket page is at 1st slot of the directory page.

◆ _levelUp()

void HashIndexFile::_levelUp ( HashIndexHeader file_header)
private

Helper function for incrementing the global level of the hash index.

Precondition
There is enough space in the buffer for two Pages.
Postcondition
The global level rises by 1, doubling the number of entries in the directory pages. All entries in the directory pages at the current global level is copied over to the set of entries that follow at the right offset in the next global level. For example, an entry for hash value of 0b10 at the global level of 1 would need to be copied to entry for hash value of 0b110 at the new global level of 2. Any splitting of individual bucket occurs outside of the scope of this function. Extra HashDirPages may be allocated if extra space is needed for new entries. All metadata, including global_level, dir_size, and dir PageNum array are updated appropriately. If there is not enough space on the header page for extra entries or not enough directory pages can be allocated for the next level (because of MAX_PAGE_NUM) the function returns without changing any state of the index. Any Page that has been pinned during the operation is released at the end or before exception is thrown.
Exceptions
InsufficientSpaceBufMgrIf there is not enough space in the bufferpool for getting or allocating Page.

◆ _splitPage()

PageId HashIndexFile::_splitPage ( HashIndexHeader file_header,
HashBucketPage bucket_page,
PageId  bucket_page_id 
)
private

Helper function for splitting a bucket.

Precondition
There is enough space in the buffer for a Page.
Postcondition
The given bucket is split to 2 pages and the local level is incremented by 1. Entries are moved to the new page per the extendible hash index implementation. Directory pages and header page (num_bucket) are updated accordingly.
Parameters
keyKey of the entries to be retrieved.
Returns
RecordId of the new split page
Exceptions
InsufficientSpaceBufMgrIf there is not enough space in the bufferpool for getting or allocating Page.

◆ createHeader()

void HashIndexFile::createHeader ( )
virtual

Allocates and initializes the header Page of the file.

Precondition
There is sufficient space for a Page in buffer pool. The file with the corresponding FileId is already created.
Postcondition
A Page is allocated and the header_id field is initialized to the PageId of the allocated Page. dir_size is set to 1 and num_bucket, num_entries, and global_level are set to 0. One bucket is allocated.
Exceptions
InsufficientSpaceBufMgrIf there is not enough space in the bufferpool.

Implements File.

◆ deleteEntry()

void HashIndexFile::deleteEntry ( Key  key,
RecordId  record_id 
)
virtual

Method for deleting an entry of the given Key and RecordId.

Precondition
A valid Key with key format matching that of the IndexFile and valid RecordId are provided as input.
Postcondition
Entry with the given Key and RecordId is deleted. All pages pinned during the operation are released at the end or before exeption is thrown.
Parameters
keyKey of the entry to be deleted.
record_idRecordId fot the entry to be deleted.
Exceptions
InvalidKeyFormatHashIndexIf the key format of the given Key does not match that of the HashIndexFile (pointer comparison).
InvalidEntryHashIndexIf there is no matching entry.

Implements IndexFile.

◆ deleteKey()

void HashIndexFile::deleteKey ( Key  key)
virtual

Method for deleting all entires with the given key.

Precondition
A valid Key with key format matching that of the IndexFile and is provided as input.
Postcondition
All entries with the given Key are deleted. All pages pinned during the operation are released at the end or before exeption is thrown.
Parameters
keyKey of the entries to be deleted.
Exceptions
InvalidKeyFormatHashIndexIf the key format of the given Key does not match that of the HashIndexFile.

Implements IndexFile.

◆ flushHeader()

void HashIndexFile::flushHeader ( )
virtual

Flushes header Page to disk.

Precondition
There is sufficient space for the header Page in buffer pool. header_id is valid.
Postcondition
Header Page of the File is flushed to disk.
Exceptions
InsufficientSpaceBufMgrIf there is not enough space in the bufferpool for the header Page.
InvalidPageIdBufMgrIf the header_id of the File is not valid.

Implements File.

◆ getEntries()

std::vector< RecordId > HashIndexFile::getEntries ( Key  key)
virtual

Returns a list all RecordIds with the given Key.

Precondition
A valid Key with key format matching that of the IndexFile is provided as input.
Postcondition
All RecordIds with the given Key are returned. All pages pinned during the operation are released at the end or before exeption is thrown.
Parameters
keyKey of the entries to be retrieved.
Returns
std::vector of RecordId of the given Key.
Exceptions
InvalidKeyFormatHashIndexIf the key format of the given Key does not match that of the HashIndexFile.

Implements IndexFile.

◆ insertEntry()

void HashIndexFile::insertEntry ( Key  key,
RecordId  record_id 
)
virtual

Inserts an Entry into the HashIndexFile.

Precondition
A valid Key with key format matching that of the HashIndexFile is provided as input. There is some HashBucketPage into which the entry can be inserted and HashDirPage into which its index can be inserted.
Postcondition
If there is sufficent space on the bucket with the matching hash value, the pair of the Key and the RecordId are inserted. If there is not enough space on the bucket, the bucket is split and the
local level of the bucket is incremented by 1. The entries of the original bucket are rehashed and inserted into one of the two buckets per extendible hash implementation. If the incremented local level exceeds the global level of the index, the global level also rises and the number of valid entries in the directory pages double, pointing to the corresponding bucket pages. Extra directory pages may be allocated to hold more entries in this process. The
header page is updated appropriately. All pages pinned during the operation are released at the end or before exception is thrown.
Parameters
keyKey of the entry to be inserted.
record_idRecordId of the entry to be inserted.
Exceptions
InvalidKeyFormatHashIndexIf the key format of the given Key does not match that of the HashIndexFile (pointer comparison).
InsufficientSpaceHashBucketIf the given Key's data exceeds the MAXIMUM_RECORD_SIZE.
InsufficientSpaceHashIndexIf the number of pages (including the header, directory, and buckets) in the HashIndexFile exceeds MAX_PAGE_NUM or the Header Page becaomes full.

Implements IndexFile.


The documentation for this class was generated from the following file: