1 #ifndef CATALOG_CATCACHEBASE_H
2 #define CATALOG_CATCACHEBASE_H
6 #include <absl/container/flat_hash_map.h>
51 Oid tabid,
const std::vector<Datum> &data);
62 return T::Create(data);
76 template<
class T,
class ...Args>
79 return new T(std::forward<Args>(args)...);
85 return systable_struct->GetDatumVector();
102 template<
class CatCacheCls>
126 inline std::shared_ptr<const SysTable_Table>
136 return static_pointer_cast<const SysTable_Table>(
137 entry->m_systable_struct);
156 inline std::shared_ptr<const SysTable_Type>
166 return static_pointer_cast<const SysTable_Type>(
167 entry->m_systable_struct);
178 return "INVALID_TYPE";
180 return typ->typname();
183 inline std::shared_ptr<const SysTable_Function>
193 return static_pointer_cast<const SysTable_Function>(
194 entry->m_systable_struct);
212 Oid funcid, int16_t funcargid);
214 inline std::shared_ptr<const SysTable_Index>
224 return static_pointer_cast<const SysTable_Index>(
225 entry->m_systable_struct);
274 inline std::shared_ptr<const SysTable_Aggregation>
284 return static_pointer_cast<const SysTable_Aggregation>(
285 entry->m_systable_struct);
348 absl::string_view name);
350 template<
bool expect_unique,
size_t NPreds,
bool no_cache>
354 std::unique_ptr<CCLookupTableEntry>,
359 std::vector<EntryPtr>>::type;
361 template<
class RHS0,
class ...RemRHS>
363 typename std::enable_if<std::is_same<RHS0, RHS0>::value
364 && expect_unique,
RetType>::type
368 const std::array<FieldId, NPreds> &fieldid,
369 const std::array<Oid, NPreds> &eq_funcid,
371 RemRHS&& ...remrhs) {
372 return Impl(_this, systabid, idxid_hint, 0, fieldid, eq_funcid,
373 std::forward<RHS0>(rhs0), std::forward<RemRHS>(remrhs)...);
376 template<
class RHS0,
class ...RemRHS>
378 typename std::enable_if<std::is_same<RHS0, RHS0>::value
379 && !expect_unique,
RetType>::type
384 const std::array<FieldId, NPreds> &fieldid,
385 const std::array<Oid, NPreds> &eq_funcid,
387 RemRHS&& ...remrhs) {
388 return Impl(_this, systabid, idxid_hint, expect_n, fieldid,
389 eq_funcid, std::forward<RHS0>(rhs0),
390 std::forward<RemRHS>(remrhs)...);
394 template<
class ...RHS>
400 const std::array<FieldId, NPreds> &fieldid,
401 const std::array<Oid, NPreds> &eq_funcid,
411 std::vector<Oid> coltypid,
412 std::vector<uint64_t> coltypparam,
413 std::vector<std::string> field_names,
414 std::vector<bool> colisnullable,
415 std::vector<bool> colisarray,
431 std::vector<FieldId> idxcoltabcolids,
433 std::vector<Oid> idxcolltfuncids,
434 std::vector<Oid> idxcoleqfuncids);
447 const std::string &init_datafile,
490 template<
bool no_cache>
491 typename std::conditional<no_cache,
492 std::unique_ptr<CCLookupTableEntry>,
504 const std::vector<std::vector<Datum>> &data);
BootstrapCatCache stores hard-coded data needed to bootstrap the entire database catalog.
Definition: BootstrapCatCache.h:21
CatCacheBase implements the common routines and public interfaces for accessing and modifying the sys...
Definition: CatCacheBase.h:103
absl::flat_hash_map< Oid, std::shared_ptr< TableDesc > > m_table_desc
Definition: CatCacheBase.h:510
Oid FindAggregationByTidAndOprType(AggType aggtyp, Oid aggoprtypid)
Returns the aggregation ID for the aggregation with the given type and operand type.
std::shared_ptr< const IndexDesc > FindIndexDesc(Oid idxid)
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.
std::shared_ptr< const SysTable_Index > FindIndex(Oid idxid)
Definition: CatCacheBase.h:215
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.
std::shared_ptr< const SysTable_FunctionArgs > FindFunctionArgs(Oid funcid, int16_t funcargid)
bool m_use_index
Definition: CatCacheBase.h:507
CCLookupTableEntry * 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.
std::vector< Oid > FindAllIndexesOfTable(Oid idxtabid)
Oid AllocateOid()
Allocates an object ID.
Oid FindOperator(OpType optype, Oid oparg0typid, Oid oparg1typid)
Returns the operator function id of the one with the specific operand types and operator type.
void InitializeFromInitData(const std::string &init_datafile)
Creates the catalog from an init data file and initializes the catalog cache.
absl::flat_hash_map< Oid, std::shared_ptr< IndexDesc > > m_index_desc
Definition: CatCacheBase.h:511
std::shared_ptr< const SysTable_Function > FindFunction(Oid funcid)
Definition: CatCacheBase.h:184
Oid FindIndexByName(absl::string_view idxname)
Definition: CatCacheBase.h:229
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.
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.
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.
bool m_initialized
Definition: CatCacheBase.h:506
void InitializeFromExistingData()
Initializes the catalog cache from the existing data.
void CreateDBMeta()
Creates and initializes the database meta file.
void LoadMinCache(BootstrapCatCache *catcache)
Loads the minimum set of the required catalog entries for initializing the cache.
std::shared_ptr< const SysTable_Aggregation > FindAggregation(Oid aggid)
Returns the aggregation systable struct for the aggregation with ID aggid.
Definition: CatCacheBase.h:275
absl::flat_hash_map< Oid, FileId > LoadInitFile(const std::string &init_datafile, BootstrapCatCache *catcache)
Loads the init catalog file and writes them into the catalog files.
std::shared_ptr< const SysTable_Type > FindType(Oid typid)
Definition: CatCacheBase.h:157
Oid FindAggregationByNameAndOprType(absl::string_view aggname, Oid aggoprtypid)
Returns the aggregation ID for the aggregation with the given name and aggregation operand type.
std::shared_ptr< const SysTable_Table > FindTable(Oid tabid)
Definition: CatCacheBase.h:127
CCLookupTableEntry * SearchForCatalogEntryByOid(Oid systabid, Oid idxid_hint, FieldId oid_colid, Oid oid)
Searches for the systable entry with ID recid in the given systable systabid.
absl::flat_hash_map< RecordId, CCLookupTableEntry > m_recid_lookup_table
Definition: CatCacheBase.h:509
constexpr bool IsInitialized() const
Returns if the catalog cache has been initialized.
Definition: CatCacheBase.h:122
void CheckIndexes(bool init)
Checks if any of the catalog indexes need to be initialized and/or rebuilt.
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.
std::shared_ptr< const TableDesc > FindTableDesc(Oid tabid)
Oid FindTableByName(absl::string_view tabname)
Definition: CatCacheBase.h:141
void BuildIndex(bool init, Oid idxid)
Oid FindFunctionByName(absl::string_view funcname)
Definition: CatCacheBase.h:198
std::string GetTypeName(Oid typid)
Returns the type name of the specified type if it exists.
Definition: CatCacheBase.h:175
Some internal functions of catalog cache implementations.
Definition: CatCacheBase.h:38
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.
Definition: CatCacheBase_gen.cpp:8
static T * CopySysTableStruct(const T *s)
Definition: CatCacheBase.h:67
static T * ConstructSysTableStruct(Args &&...args)
Constructs a SysTable_xxx struct from c++ values by invoking its constructor.
Definition: CatCacheBase.h:78
static T * CreateSysTableStruct(const std::vector< Datum > &data)
Creates a SysTable_xxx struct from a vector of data by invoking its Create() function.
Definition: CatCacheBase.h:61
std::vector< Datum > GetDatumVector(const T &systable_struct)
Definition: CatCacheBase.h:84
A Schema object stores the information for accessing an ordered set of typed fields either from a dis...
Definition: Schema.h:39
static constexpr FieldId aggid_colid()
Definition: Aggregation.h:143
SysTable_Function is an in-memory cached record in the system catalog SysTable_Function.
Definition: Function.h:16
static constexpr FieldId funcid_colid()
Definition: Function.h:99
static constexpr FieldId funcname_colid()
Definition: Function.h:114
SysTable_Index is an in-memory cached record in the system catalog SysTable_Index.
Definition: Index.h:16
static constexpr FieldId idxname_colid()
Definition: Index.h:162
static constexpr FieldId idxid_colid()
Definition: Index.h:132
SysTable_Table is an in-memory cached record in the system catalog SysTable_Table.
Definition: Table.h:16
static constexpr FieldId tabid_colid()
Definition: Table.h:121
static constexpr FieldId tabname_colid()
Definition: Table.h:146
static constexpr FieldId typid_colid()
Definition: Type.h:154
constexpr const Oid IDX_Index_idxid
Definition: initoids.h:20
constexpr const Oid IDX_Function_funcid
Definition: initoids.h:29
constexpr const Oid IDX_Type_typid
Definition: initoids.h:38
constexpr const Oid TAB_Aggregation
Definition: initoids.h:18
constexpr const Oid IDX_Function_funcname
Definition: initoids.h:30
constexpr const Oid IDX_Table_tabname
Definition: initoids.h:37
constexpr const Oid TAB_Function
Definition: initoids.h:16
constexpr const Oid TAB_Table
Definition: initoids.h:12
constexpr const Oid TAB_Index
Definition: initoids.h:13
constexpr const Oid TAB_Type
Definition: initoids.h:19
constexpr const Oid IDX_Aggregation_aggid
Definition: initoids.h:22
constexpr const Oid IDX_Table_tabid
Definition: initoids.h:36
constexpr Oid InvalidOid
Definition: tdb_base.h:224
uint8_t OpType
The operator type, see expr/optypes.h.
Definition: tdb_base.h:287
uint32_t Oid
Definition: tdb_base.h:210
uint8_t IdxType
The index type, see index/idxtyps.h.
Definition: tdb_base.h:284
int16_t FieldId
Definition: tdb_base.h:212
uint32_t FileId
The file ID.
Definition: tdb_base.h:221
uint8_t AggType
The aggregation type, see catalog/aggtyp.h.
Definition: tdb_base.h:295
This is an internal data structure of the catalog cache for storing an in-memory catalog table entry.
Definition: CatCacheBase.h:19
CCLookupTableEntry(RecordId recid, std::shared_ptr< void > systable_struct)
Definition: CatCacheBase.h:20
CCLookupTableEntry(CCLookupTableEntry &&e)=default
std::shared_ptr< void > m_systable_struct
Definition: CatCacheBase.h:30
CCLookupTableEntry & operator=(const CCLookupTableEntry &)=delete
RecordId m_recid
Definition: CatCacheBase.h:29
CCLookupTableEntry(const CCLookupTableEntry &)=delete
CCLookupTableEntry & operator=(CCLookupTableEntry &&e)=default
Definition: CatCacheBase.h:351
static std::enable_if< std::is_same< RHS0, RHS0 >::value &&expect_unique, RetType >::type Call(CatCacheBase *_this, Oid systabid, Oid idxid_hint, const std::array< FieldId, NPreds > &fieldid, const std::array< Oid, NPreds > &eq_funcid, RHS0 &&rhs0, RemRHS &&...remrhs)
Definition: CatCacheBase.h:365
typename std::conditional< expect_unique, EntryPtr, std::vector< EntryPtr > >::type RetType
Definition: CatCacheBase.h:359
static std::enable_if< std::is_same< RHS0, RHS0 >::value &&!expect_unique, RetType >::type Call(CatCacheBase *_this, Oid systabid, Oid idxid_hint, size_t expect_n, const std::array< FieldId, NPreds > &fieldid, const std::array< Oid, NPreds > &eq_funcid, RHS0 &&rhs0, RemRHS &&...remrhs)
Definition: CatCacheBase.h:380
static RetType Impl(CatCacheBase *_this, Oid systabid, Oid idxid_hint, size_t expect_n, const std::array< FieldId, NPreds > &fieldid, const std::array< Oid, NPreds > &eq_funcid, RHS &&...rhs)
typename std::conditional< no_cache, std::unique_ptr< CCLookupTableEntry >, CCLookupTableEntry * >::type EntryPtr
Definition: CatCacheBase.h:355
The record ID of a record on a page is a pair of ‘(PageNumber, SlotId)’.
Definition: Record.h:17
This header file includes all internal struct representation of system catalog records.