taco-db
0.1.0
|
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... | |
DatumRef & | GetKey (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< NullableDatumRef > | ToNullableDatumVector () const |
Returns the IndexKey as an std::vector<NullableDatumRef>. More... | |
IndexKey (const IndexKey &)=delete | |
IndexKey (IndexKey &&)=delete | |
IndexKey & | operator= (const IndexKey &)=delete |
IndexKey & | operator= (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] |
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.
|
delete |
|
delete |
|
inlinestatic |
Computes the minimum size of an byte array to store this IndexKey that holds nkeys
.
|
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.
|
inlinestatic |
|
inlinestaticprivate |
|
inline |
Makes a copy of the index key in a newly allocated buffer.
The space is exactly enough for storing GetNumKeys()
keys.
|
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
.
|
inlinestatic |
|
inlinestatic |
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()
.
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.
|
inline |
Returns the key \keyid as a NullableDatumRef.
|
inline |
Returns the minimum size of the byte array to store this IndexKey.
Same as ComputeStructSize(this->GetNumKeys())
.
|
inline |
Returns if any of the keys is null.
|
inline |
Returns the key keyid
is null.
Note that it is ok to call IsNull with keyid >= GetNumKeys()
. Those keys are treated as NULL.
|
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.
|
inline |
Sets or clears the null bit for the key \keyid.
It is undefined if keyid >= GetNumKeys()
.
|
inline |
Returns the IndexKey as an std::vector<NullableDatumRef>.
|
private |