taco-db  0.1.0
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
taco::CatCacheBase< CatCacheCls > Class Template Reference

CatCacheBase implements the common routines and public interfaces for accessing and modifying the system catalog files. More...

#include <catalog/CatCacheBase.h>

Inheritance diagram for taco::CatCacheBase< CatCacheCls >:
taco::CatCacheInternalAccess

Classes

struct  SearchForCatalogEntry
 

Public Member Functions

 CatCacheBase ()
 
void InitializeFromExistingData ()
 Initializes the catalog cache from the existing data. More...
 
void InitializeFromInitData (const std::string &init_datafile)
 Creates the catalog from an init data file and initializes the catalog cache. More...
 
constexpr bool IsInitialized () const
 Returns if the catalog cache has been initialized. More...
 
std::shared_ptr< const SysTable_TableFindTable (Oid tabid)
 
Oid FindTableByName (absl::string_view tabname)
 
std::shared_ptr< const TableDescFindTableDesc (Oid tabid)
 
std::shared_ptr< const SysTable_TypeFindType (Oid typid)
 
std::string GetTypeName (Oid typid)
 Returns the type name of the specified type if it exists. More...
 
std::shared_ptr< const SysTable_FunctionFindFunction (Oid funcid)
 
Oid FindFunctionByName (absl::string_view funcname)
 
std::shared_ptr< const SysTable_FunctionArgsFindFunctionArgs (Oid funcid, int16_t funcargid)
 
std::shared_ptr< const SysTable_IndexFindIndex (Oid idxid)
 
Oid FindIndexByName (absl::string_view idxname)
 
std::vector< OidFindAllIndexesOfTable (Oid idxtabid)
 
std::shared_ptr< const IndexDescFindIndexDesc (Oid idxid)
 
Oid FindOperator (OpType optype, Oid oparg0typid, Oid oparg1typid)
 Returns the operator function id of the one with the specific operand types and operator type. More...
 
Oid FindCast (Oid castoprtypid, Oid castrettypid, bool must_be_implicit)
 Returns the cast function id of the one with the specific operand type and return type. More...
 
std::shared_ptr< const SysTable_AggregationFindAggregation (Oid aggid)
 Returns the aggregation systable struct for the aggregation with ID aggid. More...
 
Oid FindAggregationByNameAndOprType (absl::string_view aggname, Oid aggoprtypid)
 Returns the aggregation ID for the aggregation with the given name and aggregation operand type. More...
 
Oid FindAggregationByTidAndOprType (AggType aggtyp, Oid aggoprtypid)
 Returns the aggregation ID for the aggregation with the given type and operand type. More...
 
CCLookupTableEntrySearchForCatalogEntryByOid (Oid systabid, Oid idxid_hint, FieldId oid_colid, Oid oid)
 Searches for the systable entry with ID recid in the given systable systabid. More...
 
CCLookupTableEntrySearchForCatalogEntryByName (Oid systabid, Oid idxid_hint, FieldId name_colid, absl::string_view name)
 Searches for the systable entry with its name column at name_colid equals to name. More...
 
Oid AddTable (absl::string_view tabname, std::vector< Oid > coltypid, std::vector< uint64_t > coltypparam, std::vector< std::string > field_names, std::vector< bool > colisnullable, std::vector< bool > colisarray, FileId tabfid)
 Adds a table into the catalog. More...
 
Oid AddIndex (absl::string_view idxname, Oid idxtabid, IdxType idxtyp, bool idxunique, std::vector< FieldId > idxcoltabcolids, FileId idxfid, std::vector< Oid > idxcolltfuncids, std::vector< Oid > idxcoleqfuncids)
 Adds an index into the catalog. More...
 

Private Member Functions

void CreateDBMeta ()
 Creates and initializes the database meta file. More...
 
absl::flat_hash_map< Oid, FileIdLoadInitFile (const std::string &init_datafile, BootstrapCatCache *catcache)
 Loads the init catalog file and writes them into the catalog files. More...
 
void FinishInitCatalog (const absl::flat_hash_map< Oid, FileId > &tabid2fid, BootstrapCatCache *catcache)
 Finishes the initialization of the catalog and updates the DB meta file if necessary. More...
 
void LoadMinCache (BootstrapCatCache *catcache)
 Loads the minimum set of the required catalog entries for initializing the cache. More...
 
void CheckIndexes (bool init)
 Checks if any of the catalog indexes need to be initialized and/or rebuilt. More...
 
void BuildIndex (bool init, Oid idxid)
 
Oid AllocateOid ()
 Allocates an object ID. More...
 
template<bool no_cache>
std::conditional< no_cache, std::unique_ptr< CCLookupTableEntry >, CCLookupTableEntry * >::type GetOrCreateCachedEntry (Oid systabid, RecordId recid, const Schema *schema, const char *buf)
 Returns the catalog entry in the systable by its table id and record id. More...
 
void InsertCatalogEntries (Oid systabid, const std::vector< std::vector< Datum >> &data)
 Inserts the new catalog entries in data into the systable systabid and also update all its indexes. More...
 

Private Attributes

bool m_initialized
 
bool m_use_index
 
absl::flat_hash_map< RecordId, CCLookupTableEntrym_recid_lookup_table
 
absl::flat_hash_map< Oid, std::shared_ptr< TableDesc > > m_table_desc
 
absl::flat_hash_map< Oid, std::shared_ptr< IndexDesc > > m_index_desc
 

Friends

template<bool , size_t , bool >
struct SearchForCatalogEntry
 

Additional Inherited Members

- Protected Member Functions inherited from taco::CatCacheInternalAccess
template<class T >
std::vector< DatumGetDatumVector (const T &systable_struct)
 
- Static Protected Member Functions inherited from taco::CatCacheInternalAccess
static std::shared_ptr< void > CreateSysTableStruct (Oid tabid, const std::vector< Datum > &data)
 Creates a SysTable_xxx struct for a row stored in a record payout in the specified table. More...
 
template<class T >
static T * CreateSysTableStruct (const std::vector< Datum > &data)
 Creates a SysTable_xxx struct from a vector of data by invoking its Create() function. More...
 
template<class T >
static T * CopySysTableStruct (const T *s)
 
template<class T , class ... Args>
static T * ConstructSysTableStruct (Args &&...args)
 Constructs a SysTable_xxx struct from c++ values by invoking its constructor. More...
 

Detailed Description

template<class CatCacheCls>
class taco::CatCacheBase< CatCacheCls >

CatCacheBase implements the common routines and public interfaces for accessing and modifying the system catalog files.

Internally it maintains a few caches of the catalog entries so all other components should always access the catalog files through the global catalog cache ‘g_catcache’.

It depends on its subclass CatCacheCls to provide a fe functions for catalog file accesses. Currently we have two implementations: ‘VolatileCatCache’ which provides file accesses to virtual in-memory files, and ‘PersistentCatCache’ which provides file accsess to the regular files managed by the file manager. See these two classes for a list of required file access functions.

Constructor & Destructor Documentation

◆ CatCacheBase()

template<class CatCacheCls >
taco::CatCacheBase< CatCacheCls >::CatCacheBase ( )

Member Function Documentation

◆ AddIndex()

template<class CatCacheCls >
Oid taco::CatCacheBase< CatCacheCls >::AddIndex ( absl::string_view  idxname,
Oid  idxtabid,
IdxType  idxtyp,
bool  idxunique,
std::vector< FieldId idxcoltabcolids,
FileId  idxfid,
std::vector< Oid idxcolltfuncids,
std::vector< Oid idxcoleqfuncids 
)

Adds an index into the catalog.

The caller may optionally provide the less functions and equality functions that might be different from the default < and = operators for the type (e.g., case insensitive string comparison). Any InvalidOid or missing values in idxcolltfuncids and idxcoleqfuncids are looked up from the catalog.

◆ AddTable()

template<class CatCacheCls >
Oid taco::CatCacheBase< CatCacheCls >::AddTable ( absl::string_view  tabname,
std::vector< Oid coltypid,
std::vector< uint64_t >  coltypparam,
std::vector< std::string >  field_names,
std::vector< bool >  colisnullable,
std::vector< bool >  colisarray,
FileId  tabfid 
)

Adds a table into the catalog.

◆ AllocateOid()

template<class CatCacheCls >
Oid taco::CatCacheBase< CatCacheCls >::AllocateOid ( )
private

Allocates an object ID.

Returns a valid Oid that will never be returned again unless it is deallocated on success. Otherwise, it returns InvalidOid.

◆ BuildIndex()

template<class CatCacheCls >
void taco::CatCacheBase< CatCacheCls >::BuildIndex ( bool  init,
Oid  idxid 
)
private

◆ CheckIndexes()

template<class CatCacheCls >
void taco::CatCacheBase< CatCacheCls >::CheckIndexes ( bool  init)
private

Checks if any of the catalog indexes need to be initialized and/or rebuilt.

If init is true, it will go over all the entries in the Index systable; update them; initialize and load the new indexes.

Its behavior is also affected by g_test_no_index and g_test_catcache_use_volatiletree. See documents for those two global variables for details.

◆ CreateDBMeta()

template<class CatCacheCls >
void taco::CatCacheBase< CatCacheCls >::CreateDBMeta ( )
private

Creates and initializes the database meta file.

This must be called first when creating a new database.

◆ FindAggregation()

template<class CatCacheCls >
std::shared_ptr<const SysTable_Aggregation> taco::CatCacheBase< CatCacheCls >::FindAggregation ( Oid  aggid)
inline

Returns the aggregation systable struct for the aggregation with ID aggid.

Returns nullptr if not found.

◆ FindAggregationByNameAndOprType()

template<class CatCacheCls >
Oid taco::CatCacheBase< CatCacheCls >::FindAggregationByNameAndOprType ( absl::string_view  aggname,
Oid  aggoprtypid 
)

Returns the aggregation ID for the aggregation with the given name and aggregation operand type.

If there is no aggregation exactly match the name and operand type specified, this function will also search for an aggregation with the specified name but works on any operand types (one notable example is COUNT which only has a single implementation that works on all types).

Returns InvalidOid if no aggregation is found with the given name and may be applied to the specified operand type.

◆ FindAggregationByTidAndOprType()

template<class CatCacheCls >
Oid taco::CatCacheBase< CatCacheCls >::FindAggregationByTidAndOprType ( AggType  aggtyp,
Oid  aggoprtypid 
)

Returns the aggregation ID for the aggregation with the given type and operand type.

If there is no aggregation exactly match the aggregation type and operand type specified, this function will also search for an aggregation with the specified name but works on any types (one notable example is COUNT which only has a single implementation that works on all types).

Note that aggtyp must not be AGGTYPE_OTHER, in which case the caller should use FindAggregationByNameAndOprType instead. On the other hand, any aggregation that may be returned here can also be uniquely found by FindAggregationByNameAndOprType. The only difference is that this is fast path where we can avoid case-insensitive string comparison here for those hard-coded aggregations.

Returns InvalidOid if no aggregation may be uniquely identified with the given aggregation type and operand type, or aggtyp == AGGTYPE_OTHER even if there is only one such aggregation.

◆ FindAllIndexesOfTable()

template<class CatCacheCls >
std::vector<Oid> taco::CatCacheBase< CatCacheCls >::FindAllIndexesOfTable ( Oid  idxtabid)

◆ FindCast()

template<class CatCacheCls >
Oid taco::CatCacheBase< CatCacheCls >::FindCast ( Oid  castoprtypid,
Oid  castrettypid,
bool  must_be_implicit 
)

Returns the cast function id of the one with the specific operand type and return type.

The third argument must_be_implicit indicates whether the returned cast function must be implicit cast or not. If it is set to true and the found cast function is not an implicit cast, this function returns InvalidOid instead. If it is set to false, the returned cast function may be implicit or explicit.

It returns InvalidOid if there is no cast function from the operand type to the return type.

◆ FindFunction()

template<class CatCacheCls >
std::shared_ptr<const SysTable_Function> taco::CatCacheBase< CatCacheCls >::FindFunction ( Oid  funcid)
inline

◆ FindFunctionArgs()

template<class CatCacheCls >
std::shared_ptr<const SysTable_FunctionArgs> taco::CatCacheBase< CatCacheCls >::FindFunctionArgs ( Oid  funcid,
int16_t  funcargid 
)

◆ FindFunctionByName()

template<class CatCacheCls >
Oid taco::CatCacheBase< CatCacheCls >::FindFunctionByName ( absl::string_view  funcname)
inline

◆ FindIndex()

template<class CatCacheCls >
std::shared_ptr<const SysTable_Index> taco::CatCacheBase< CatCacheCls >::FindIndex ( Oid  idxid)
inline

◆ FindIndexByName()

template<class CatCacheCls >
Oid taco::CatCacheBase< CatCacheCls >::FindIndexByName ( absl::string_view  idxname)
inline

◆ FindIndexDesc()

template<class CatCacheCls >
std::shared_ptr<const IndexDesc> taco::CatCacheBase< CatCacheCls >::FindIndexDesc ( Oid  idxid)

◆ FindOperator()

template<class CatCacheCls >
Oid taco::CatCacheBase< CatCacheCls >::FindOperator ( OpType  optype,
Oid  oparg0typid,
Oid  oparg1typid 
)

Returns the operator function id of the one with the specific operand types and operator type.

It is an error if the operand types are not fully specified (e.g., only one side specified for a binary operator).

◆ FindTable()

template<class CatCacheCls >
std::shared_ptr<const SysTable_Table> taco::CatCacheBase< CatCacheCls >::FindTable ( Oid  tabid)
inline

◆ FindTableByName()

template<class CatCacheCls >
Oid taco::CatCacheBase< CatCacheCls >::FindTableByName ( absl::string_view  tabname)
inline

◆ FindTableDesc()

template<class CatCacheCls >
std::shared_ptr<const TableDesc> taco::CatCacheBase< CatCacheCls >::FindTableDesc ( Oid  tabid)

◆ FindType()

template<class CatCacheCls >
std::shared_ptr<const SysTable_Type> taco::CatCacheBase< CatCacheCls >::FindType ( Oid  typid)
inline

◆ FinishInitCatalog()

template<class CatCacheCls >
void taco::CatCacheBase< CatCacheCls >::FinishInitCatalog ( const absl::flat_hash_map< Oid, FileId > &  tabid2fid,
BootstrapCatCache catcache 
)
private

Finishes the initialization of the catalog and updates the DB meta file if necessary.

◆ GetOrCreateCachedEntry()

template<class CatCacheCls >
template<bool no_cache>
std::conditional<no_cache, std::unique_ptr<CCLookupTableEntry>, CCLookupTableEntry*>::type taco::CatCacheBase< CatCacheCls >::GetOrCreateCachedEntry ( Oid  systabid,
RecordId  recid,
const Schema schema,
const char *  buf 
)
private

Returns the catalog entry in the systable by its table id and record id.

It searches in the cache first, returns that if found. Otherwise, it reads the entry into the cache. Currently we do not evict any cached catalog entry.

◆ GetTypeName()

template<class CatCacheCls >
std::string taco::CatCacheBase< CatCacheCls >::GetTypeName ( Oid  typid)
inline

Returns the type name of the specified type if it exists.

If the type does not exists, returns the string "INVALID_TYPE".

◆ InitializeFromExistingData()

template<class CatCacheCls >
void taco::CatCacheBase< CatCacheCls >::InitializeFromExistingData ( )

Initializes the catalog cache from the existing data.

◆ InitializeFromInitData()

template<class CatCacheCls >
void taco::CatCacheBase< CatCacheCls >::InitializeFromInitData ( const std::string &  init_datafile)

Creates the catalog from an init data file and initializes the catalog cache.

◆ InsertCatalogEntries()

template<class CatCacheCls >
void taco::CatCacheBase< CatCacheCls >::InsertCatalogEntries ( Oid  systabid,
const std::vector< std::vector< Datum >> &  data 
)
private

Inserts the new catalog entries in data into the systable systabid and also update all its indexes.

◆ IsInitialized()

template<class CatCacheCls >
constexpr bool taco::CatCacheBase< CatCacheCls >::IsInitialized ( ) const
inlineconstexpr

Returns if the catalog cache has been initialized.

◆ LoadInitFile()

template<class CatCacheCls >
absl::flat_hash_map<Oid, FileId> taco::CatCacheBase< CatCacheCls >::LoadInitFile ( const std::string &  init_datafile,
BootstrapCatCache catcache 
)
private

Loads the init catalog file and writes them into the catalog files.

Returns a map from catalog table ID to its file ID.

◆ LoadMinCache()

template<class CatCacheCls >
void taco::CatCacheBase< CatCacheCls >::LoadMinCache ( BootstrapCatCache catcache)
private

Loads the minimum set of the required catalog entries for initializing the cache.

This function completes the initialization of the catalog cache.

◆ SearchForCatalogEntryByName()

template<class CatCacheCls >
CCLookupTableEntry* taco::CatCacheBase< CatCacheCls >::SearchForCatalogEntryByName ( Oid  systabid,
Oid  idxid_hint,
FieldId  name_colid,
absl::string_view  name 
)

Searches for the systable entry with its name column at name_colid equals to name.

This assumes there is only one record matching the name. Otherwise, it will return the first one it finds.

◆ SearchForCatalogEntryByOid()

template<class CatCacheCls >
CCLookupTableEntry* taco::CatCacheBase< CatCacheCls >::SearchForCatalogEntryByOid ( Oid  systabid,
Oid  idxid_hint,
FieldId  oid_colid,
Oid  oid 
)

Searches for the systable entry with ID recid in the given systable systabid.

This assumes that there is only one record matching the oid. Otherwise, it will return the first one it finds.

Friends And Related Function Documentation

◆ SearchForCatalogEntry

template<class CatCacheCls >
template<bool , size_t , bool >
friend struct SearchForCatalogEntry
friend

Member Data Documentation

◆ m_index_desc

template<class CatCacheCls >
absl::flat_hash_map<Oid, std::shared_ptr<IndexDesc> > taco::CatCacheBase< CatCacheCls >::m_index_desc
private

◆ m_initialized

template<class CatCacheCls >
bool taco::CatCacheBase< CatCacheCls >::m_initialized
private

◆ m_recid_lookup_table

template<class CatCacheCls >
absl::flat_hash_map<RecordId, CCLookupTableEntry> taco::CatCacheBase< CatCacheCls >::m_recid_lookup_table
private

◆ m_table_desc

template<class CatCacheCls >
absl::flat_hash_map<Oid, std::shared_ptr<TableDesc> > taco::CatCacheBase< CatCacheCls >::m_table_desc
private

◆ m_use_index

template<class CatCacheCls >
bool taco::CatCacheBase< CatCacheCls >::m_use_index
private

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