taco-db  0.1.0
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
taco::IndexKey Struct Reference

An IndexKey stores references to a few data (Datum objects) that comprise a key tuple to in an index. More...

#include <index/IndexKey.h>

Public Member Functions

UniqueIndexKey Copy () const
 Makes a copy of the index key in a newly allocated buffer. More...
 
void CopyTo (IndexKey *key2) const
 Makes a copy of the index key to an existing index key. More...
 
void DeepCopy (const Schema *sch, std::vector< Datum > &data_buffer)
 Makes a deep copy of all the variable-length Datum the key is refernecing in a newly allocated memory space and append any deep copied Datum into the data_buffer. More...
 
FieldId GetNumKeys () const
 Returns the number of keys in this IndexKey. More...
 
DatumRefGetKey (FieldId keyid) const
 Returns the key keyid. More...
 
template<class SomeDatum >
void SetKey (FieldId keyid, const SomeDatum &key)
 Sets the keyid-th field in this index key. More...
 
bool IsNull (FieldId keyid) const
 Returns the key keyid is null. More...
 
void SetNullBit (FieldId keyid, bool isnull) const
 Sets or clears the null bit for the key \keyid. More...
 
bool HasAnyNull () const
 Returns if any of the keys is null. More...
 
size_t GetStructSize () const
 Returns the minimum size of the byte array to store this IndexKey. More...
 
NullableDatumRef GetNullableKey (FieldId keyid) const
 Returns the key \keyid as a NullableDatumRef. More...
 
std::vector< NullableDatumRefToNullableDatumVector () const
 Returns the IndexKey as an std::vector<NullableDatumRef>. More...
 
 IndexKey (const IndexKey &)=delete
 
 IndexKey (IndexKey &&)=delete
 
IndexKeyoperator= (const IndexKey &)=delete
 
IndexKeyoperator= (IndexKey &&)=delete
 

Static Public Member Functions

template<class SomeDatum >
static UniqueIndexKey Create (const std::vector< SomeDatum > &data)
 Allocates and constructs a new IndexKey that references the data. More...
 
template<class SomeDatum >
static UniqueIndexKey Create (SomeDatum *data, FieldId nkeys)
 
template<class SomeDatum >
static void Construct (void *key, const std::vector< SomeDatum > &data)
 Constructs a new IndexKey that references the data on a preallocated key. More...
 
template<class SomeDatum >
static void Construct (void *key, SomeDatum *data, FieldId nkeys)
 
static size_t ComputeStructSize (FieldId nkeys)
 Computes the minimum size of an byte array to store this IndexKey that holds nkeys. More...
 

Static Private Member Functions

template<class SomeDatum >
static void ConstructImpl (void *key, SomeDatum *data, FieldId nkeys, size_t sz)
 

Private Attributes

uint64_t m_data [1]
 

Detailed Description

An IndexKey stores references to a few data (Datum objects) that comprise a key tuple to in an index.

It is a plain byte array and may be trivially destructed. When the IndexKey is used, any Datum it references must remain alive.

IndexKey provides both a creation function Create() and an inplace construction function Construct(), which are analogous to c++ new and in place new expressions. See the function docs for details.

One may also use IndexKey to construct a partial search key, where the number of fields is smaller than the key schema does in an index. Any key after the last key in this IndexKey is treated as NULL.

Under the hood, IndexKey stores a 2-byte FieldId as a header, and a null bitmap that immediately follows. Following that is some padding to 8-byte address and an array of 8-byte DatumRef. The main benefit of using IndexKey instead of std::vector<NullableDatumRef> is that it is more compact in space and is likely to be more efficient to access.

Constructor & Destructor Documentation

◆ IndexKey() [1/2]

taco::IndexKey::IndexKey ( const IndexKey )
delete

◆ IndexKey() [2/2]

taco::IndexKey::IndexKey ( IndexKey &&  )
delete

Member Function Documentation

◆ ComputeStructSize()

static size_t taco::IndexKey::ComputeStructSize ( FieldId  nkeys)
inlinestatic

Computes the minimum size of an byte array to store this IndexKey that holds nkeys.

◆ Construct() [1/2]

template<class SomeDatum >
static void taco::IndexKey::Construct ( void *  key,
const std::vector< SomeDatum > &  data 
)
inlinestatic

Constructs a new IndexKey that references the data on a preallocated key.

The key pointer must be aligned to 8-byte address and it is undefined if the size of key is smaller than IndexKey::GetStructSize(data.size()). However, it is safe to construct an IndexKey with fewer keys than allocated.

This is useful for reusing the same space for different keys during iteration in an index.

◆ Construct() [2/2]

template<class SomeDatum >
static void taco::IndexKey::Construct ( void *  key,
SomeDatum *  data,
FieldId  nkeys 
)
inlinestatic

◆ ConstructImpl()

template<class SomeDatum >
static void taco::IndexKey::ConstructImpl ( void *  key,
SomeDatum *  data,
FieldId  nkeys,
size_t  sz 
)
inlinestaticprivate

◆ Copy()

UniqueIndexKey taco::IndexKey::Copy ( ) const
inline

Makes a copy of the index key in a newly allocated buffer.

The space is exactly enough for storing GetNumKeys() keys.

◆ CopyTo()

void taco::IndexKey::CopyTo ( IndexKey key2) const
inline

Makes a copy of the index key to an existing index key.

The existing index key must be large enough to hold at least as many fields as this index key object. This function does not allocate new space.

It is undefined if the buffer pointed by key2 is not large enough and it is undefined if key2 == this.

◆ Create() [1/2]

template<class SomeDatum >
static UniqueIndexKey taco::IndexKey::Create ( const std::vector< SomeDatum > &  data)
inlinestatic

Allocates and constructs a new IndexKey that references the data.

The key has exactly enough space to hold data.size() Datum references.

◆ Create() [2/2]

template<class SomeDatum >
static UniqueIndexKey taco::IndexKey::Create ( SomeDatum *  data,
FieldId  nkeys 
)
inlinestatic

◆ DeepCopy()

void taco::IndexKey::DeepCopy ( const Schema sch,
std::vector< Datum > &  data_buffer 
)
inline

Makes a deep copy of all the variable-length Datum the key is refernecing in a newly allocated memory space and append any deep copied Datum into the data_buffer.

Then it replaces the old DataRef with the new ones that references the new Datum in data_buffer in this IndexKey. The caller should ensure data_buffer is alive when the returned IndexKey is accessed.

It is undefined if GetNumKeys() > sch->GetNumFields().

◆ GetKey()

DatumRef& taco::IndexKey::GetKey ( FieldId  keyid) const
inline

Returns the key keyid.

It is undefined if keyid >= GetNumKeys().

Note that it is possible to set the returned reference provided that it does not change the nullness of the field. Use IndexKey::SetKey() instead if the nullness of the field can change.

◆ GetNullableKey()

NullableDatumRef taco::IndexKey::GetNullableKey ( FieldId  keyid) const
inline

Returns the key \keyid as a NullableDatumRef.

◆ GetNumKeys()

FieldId taco::IndexKey::GetNumKeys ( ) const
inline

Returns the number of keys in this IndexKey.

◆ GetStructSize()

size_t taco::IndexKey::GetStructSize ( ) const
inline

Returns the minimum size of the byte array to store this IndexKey.

Same as ComputeStructSize(this->GetNumKeys()).

◆ HasAnyNull()

bool taco::IndexKey::HasAnyNull ( ) const
inline

Returns if any of the keys is null.

◆ IsNull()

bool taco::IndexKey::IsNull ( FieldId  keyid) const
inline

Returns the key keyid is null.

Note that it is ok to call IsNull with keyid >= GetNumKeys(). Those keys are treated as NULL.

◆ operator=() [1/2]

IndexKey& taco::IndexKey::operator= ( const IndexKey )
delete

◆ operator=() [2/2]

IndexKey& taco::IndexKey::operator= ( IndexKey &&  )
delete

◆ SetKey()

template<class SomeDatum >
void taco::IndexKey::SetKey ( FieldId  keyid,
const SomeDatum &  key 
)
inline

Sets the keyid-th field in this index key.

Note that this function cannot be used to increase the number of fields in the index key was allocated with enough space. Use IndexKey::Construct instead for changing the number of fields.

It is undefined if keyid is out of bound.

◆ SetNullBit()

void taco::IndexKey::SetNullBit ( FieldId  keyid,
bool  isnull 
) const
inline

Sets or clears the null bit for the key \keyid.

It is undefined if keyid >= GetNumKeys().

◆ ToNullableDatumVector()

std::vector<NullableDatumRef> taco::IndexKey::ToNullableDatumVector ( ) const
inline

Returns the IndexKey as an std::vector<NullableDatumRef>.

Member Data Documentation

◆ m_data

uint64_t taco::IndexKey::m_data[1]
private

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