taco-db
0.1.0
|
Table implements a heap file over the virtual file provided by the FileManager. More...
#include <storage/Table.h>
Classes | |
class | Iterator |
The Iterator interface for scanning the heap file. More... | |
Public Member Functions | |
~Table () | |
Destructor. More... | |
const TableDesc * | GetTableDesc () const |
Returns the table descriptor of this table. More... | |
void | InsertRecord (Record &rec) |
Inserts the record into table. More... | |
void | EraseRecord (RecordId rid) |
Erases the record specified by the record ID. More... | |
void | UpdateRecord (RecordId rid, Record &rec) |
Updates the record specified by the record ID. More... | |
Iterator | StartScan () |
Starts a scan of the table from the beginning. More... | |
Iterator | StartScanFrom (RecordId rid) |
Starts a scan of the table so that the first call to Iterator::Next() will return the first record with an ID greater than or equal to rid . More... | |
Static Public Member Functions | |
static void | Initialize (const TableDesc *tabdesc) |
Inititalizes a table on a newly created virtual file. More... | |
static std::unique_ptr< Table > | Create (std::shared_ptr< const TableDesc > tabdesc) |
Constructs a table object on a heap file that was previously initialized by Table::Initialize() . More... | |
Private Member Functions | |
Table (std::shared_ptr< const TableDesc > tabdesc, std::unique_ptr< File > file) | |
Private Attributes | |
std::shared_ptr< const TableDesc > | m_tabdesc |
The descriptor of the table. More... | |
std::unique_ptr< File > | m_file |
An open file that stores the heap file for this table. More... | |
PageNumber | m_insertion_pid |
The last known page possibly with empty space. More... | |
Friends | |
class | Iterator |
Table implements a heap file over the virtual file provided by the FileManager.
A heap file manages a list of data pages, and supports inserting, deleting, updating and forward-iterating the records stored in the file. A Table object and its iterators should use the buffer manager to access its pages, rather than directly going through the File interface.
Note:
true
.
|
inlineprivate |
taco::Table::~Table | ( | ) |
Destructor.
It must not throw any error.
Constructs a table object on a heap file that was previously initialized by Table::Initialize()
.
For all user tables, the caller should pass a table descriptor returned by the catalog cache.
For bootstrapping and initialization of the catalog cache, it may pass a fake table descriptor which at minimum needs to have the following set:
tabdesc->GetTableEntry()->tabissys()
tabdesc->GetTableEntry()->tabfid()
tabdesc->GetTableEntry()->tabisvarlen
All other members may or may not be valid (nullptr), so you may only access the above members of the table descriptor in Table::Create()
.
It is undefined if the file referenced by the table descriptor was not previously initialized by Initialize()
.
void taco::Table::EraseRecord | ( | RecordId | rid | ) |
Erases the record specified by the record ID.
This function will obtain an additional page pin on the target page, even if the caller already has one in an iterator, but it must release the additional pin upon exit. If a page becomes empty, EraseRecord() must call File::FreePage() to return the page to the file manager.
It is an error if it cannot erase the record (e.g., because it's not found), or rid
does not belong to this table.
|
inline |
Returns the table descriptor of this table.
|
static |
Inititalizes a table on a newly created virtual file.
For all user tables, the file should have been inserted into the catalog cache and the caller should supply a table descriptor returned by the catalog cache.
For bootstrapping and initialization of the catalog cache, it may pass a fake table descriptor which at minimum has the following set:
tabdesc->GetTableEntry()->tabissys()
tabdesc->GetTableEntry()->tabfid()
tabdesc->GetTableEntry()->tabisvarlen
All other members may or may not be valid (nullptr), so you may only access the above members of the table descriptor in Table::Initialize()
.
It is undefined if Initialize()
is called more than once on a file, or the file has been modified since it is created.
void taco::Table::InsertRecord | ( | Record & | rec | ) |
Inserts the record into table.
It may insert a the record on an existing page or create a new page to insert the record if necessary. Upon successful return, rec.GetRecordId()
should be set to the record ID of the newly inserted record. Otherwise, rec.GetRecordId() is undefined.
Note: for the heap file project, you may always insert to the end of the file without reusing empty spaces in the middle of the file.
It is an error if the record cannot be inserted. It is undefined if the record rec
does not have its data pointer and length correctly set.
Table::Iterator taco::Table::StartScan | ( | ) |
Starts a scan of the table from the beginning.
Table::Iterator taco::Table::StartScanFrom | ( | RecordId | rid | ) |
Starts a scan of the table so that the first call to Iterator::Next()
will return the first record with an ID greater than or equal to rid
.
Updates the record specified by the record ID.
Upon return, the ‘rec.GetRecordID()’ is updated to the new record ID of the updated record (which may be different from rid
). This function will obtain an additional page pin on the target page, even if the caller already has one in an iterator, but it must release the additional pin upon exit. If a page becomes empty, UpdateRecord() must call File::FreePage()
to return the page to the file manager.
Note that the function must perform in-place update whenever the new record's length is no larger than the old record's length at rid
.
It is an error if the update cannot be completed, in which case, the old record at rid
must not be erased. It is also an error if rid
does not belong to this table.
|
friend |
|
private |
An open file that stores the heap file for this table.
|
private |
The last known page possibly with empty space.
This serves as a hint where our insertion will happen.
|
private |
The descriptor of the table.