taco-db  0.1.0
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
taco::Index Class Referenceabstract

An interface class for index implementations. More...

#include <index/Index.h>

Inheritance diagram for taco::Index:
taco::BTree taco::VolatileTree

Classes

class  Iterator
 A forward-iterator for the items in the index. More...
 

Public Member Functions

virtual ~Index ()
 Index object destructor. More...
 
const IndexDescGetIndexDesc () const
 Returns the index descriptor of this index. More...
 
const SchemaGetKeySchema () const
 Returns the key schema of this index. More...
 
virtual void BulkLoad (BulkLoadIterator &iter)
 Loads all the (key, record id) pairs provided by the iterator iter into an empty index. More...
 
virtual bool InsertKey (const IndexKey *key, RecordId rid)=0
 Inserts the (key, rid) pair into the index. More...
 
bool InsertRecord (const Record &rec, const Schema *tabschema=nullptr)
 Inserts the (key, rid) extracted from the table record into the index. More...
 
virtual bool DeleteKey (const IndexKey *key, RecordId &rid)=0
 Deletes an arbitrary data entry with matching key if rid is invalid. More...
 
bool DeleteRecord (Record &rec, const Schema *tabschema=nullptr)
 Deletes the (key, rid) extracted from the table record from the index. More...
 
virtual std::unique_ptr< IteratorStartScan (const IndexKey *lower, bool lower_isstrict, const IndexKey *upper, bool upper_isstrict)=0
 Returns a forward-iterator for all the indexed items in the specified range defined by the arguments. More...
 

Static Public Member Functions

static void Initialize (const IndexDesc *idxdesc)
 Initializes an index described by an index descriptor. More...
 
static std::unique_ptr< IndexCreate (std::shared_ptr< const IndexDesc > idxdesc)
 Creates an index object over an index file described by the index descriptor, which has already been initialized. More...
 

Protected Member Functions

 Index (std::shared_ptr< const IndexDesc > idxdesc)
 

Private Member Functions

void PrepareKey (std::vector< Datum > &data, const char *recbuf, const Schema *tabschema)
 Extract the keys from recbuf into m_key. More...
 

Private Attributes

std::shared_ptr< const IndexDescm_idxdesc
 
unique_malloced_ptr m_key
 A buffer enough for holding an Indexkey for the number of fields in the key schema. More...
 

Detailed Description

An interface class for index implementations.

In Taco-DB, we only implement secondary indexes, where each indexed item consists of a key of some specified schema, and a record ID value.

Constructor & Destructor Documentation

◆ ~Index()

taco::Index::~Index ( )
virtual

Index object destructor.

◆ Index()

taco::Index::Index ( std::shared_ptr< const IndexDesc idxdesc)
protected

Member Function Documentation

◆ BulkLoad()

void taco::Index::BulkLoad ( BulkLoadIterator iter)
virtual

Loads all the (key, record id) pairs provided by the iterator iter into an empty index.

It is undefined if the index is not empty, and the specific index implementation is allowed to (but not required to) throw an error when called on an non-empty index.

Upon successful return, the iterator \iter is ended by calling iter->EndScan().

The default implementation calls the InsertKey() function over all the pairs returned by iter. The specific index implementation should override it with a more efficient way if there's any.

Reimplemented in taco::BTree.

◆ Create()

std::unique_ptr< Index > taco::Index::Create ( std::shared_ptr< const IndexDesc idxdesc)
static

Creates an index object over an index file described by the index descriptor, which has already been initialized.

◆ DeleteKey()

virtual bool taco::Index::DeleteKey ( const IndexKey key,
RecordId rid 
)
pure virtual

Deletes an arbitrary data entry with matching key if rid is invalid.

Deletes the data entry with matching (key, rid) pair if rid is valid.

Returns true if the deletion succeeds. Upon successful return, update rid to the deleted indexed item's record id. Returns false if the key (if rid is invalid) or (key, rid) pair (if rid is valid) is not found in the index, in which case, rid should be set to invalid.

Implemented in taco::VolatileTree, and taco::BTree.

◆ DeleteRecord()

bool taco::Index::DeleteRecord ( Record rec,
const Schema tabschema = nullptr 
)

Deletes the (key, rid) extracted from the table record from the index.

The data in rec must be valid but rec.GetRecordId() may be invalid. The table schema tabschema (not index key schema) may be null and this function will look for it from the catalog. The caller may also provide a non-null table schema to avoid that lookup.

See DeleteKey() for specification.

◆ GetIndexDesc()

const IndexDesc* taco::Index::GetIndexDesc ( ) const
inline

Returns the index descriptor of this index.

◆ GetKeySchema()

const Schema* taco::Index::GetKeySchema ( ) const
inline

Returns the key schema of this index.

◆ Initialize()

void taco::Index::Initialize ( const IndexDesc idxdesc)
static

Initializes an index described by an index descriptor.

Currently we support a in-memory volatile tree index (based on std::multimap), and a B-tree index. This function will call the Initialize() function of the specified index type (idxdesc->GetIndexEntry()->idxtyp()). Except for the in-memory volatile tree index, the index should be stored entirely in the file as specified by the index file id (idxdesc->GetIndexDesc()->idxfid()).

Different from the Table class, the index descriptor passed to this function is always complete (even during catalog initialization). Hence, we can use any information stored in the index descriptor.

◆ InsertKey()

virtual bool taco::Index::InsertKey ( const IndexKey key,
RecordId  rid 
)
pure virtual

Inserts the (key, rid) pair into the index.

Returns true if the insertion succeeds. Returns false if the index was declared as a unique index and a duplicate key is found, or for a non-unique index, the (key, rid) pair already exists in the index.

Implemented in taco::VolatileTree, and taco::BTree.

◆ InsertRecord()

bool taco::Index::InsertRecord ( const Record rec,
const Schema tabschema = nullptr 
)

Inserts the (key, rid) extracted from the table record into the index.

All fields in the rec must be valid. The table schema tabschema (not index key schema) may be null and this function will look for it from the catalog. The caller may also provide a non-null table schema to avoid that lookup.

See InsertKey() for specification.

◆ PrepareKey()

void taco::Index::PrepareKey ( std::vector< Datum > &  data,
const char *  recbuf,
const Schema tabschema 
)
private

Extract the keys from recbuf into m_key.

The fetched datum are stored in data. If tabschema is non-null, it will be used to get the fields. Otherwise, we will find one from the catalog cache.

data must empty upon entry.

◆ StartScan()

virtual std::unique_ptr<Iterator> taco::Index::StartScan ( const IndexKey lower,
bool  lower_isstrict,
const IndexKey upper,
bool  upper_isstrict 
)
pure virtual

Returns a forward-iterator for all the indexed items in the specified range defined by the arguments.

A non-null lower defines the lower bound and the iterator should return the indexed items with keys that are >= (lower_isstrict == false), or > (lower_isstrict == true) lower. A non-null upper defines the upper bound, and the iterator should not return the indexed items whose keys are >= (upper_isstrict == true), or > (upper_isstrict = false). If lower (and/or upper) is null, there is no lower (upper resp.) bound for the returned indexed items, in which case, lower_isstrict and upper_isstrict are ignored.

lower and upper are allowed to have fewer keys than the index schema does, the comparison between the key of an indexed item and lower or upper should be done only on the prefix of lower->GetNumKeys() or upper->GetNumKeys() keys.

Not all combinations of arguments can be supported by the underlying index and it should throw an error if the underlying index cannot reasonably support that. Tree indexes (e.g., B-tree) should support range search and prefix searches, while hash indexes may just support equality searches.

Implemented in taco::VolatileTree, and taco::BTree.

Member Data Documentation

◆ m_idxdesc

std::shared_ptr<const IndexDesc> taco::Index::m_idxdesc
private

◆ m_key

unique_malloced_ptr taco::Index::m_key
private

A buffer enough for holding an Indexkey for the number of fields in the key schema.

This might be nullptr and will only be allocated in the first call to InsertRecord() or DeleteRecord().


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