Go to the documentation of this file. 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);
275 inline std::shared_ptr<const SysTable_Aggregation>
285 return static_pointer_cast<const SysTable_Aggregation>(
286 entry->m_systable_struct);
349 absl::string_view name);
351 template<
bool expect_unique,
size_t NPreds,
bool no_cache>
353 using EntryPtr =
typename std::conditional<
355 std::unique_ptr<CCLookupTableEntry>,
357 using RetType =
typename std::conditional<
360 std::vector<EntryPtr>>::type;
362 template<
class RHS0,
class ...RemRHS>
364 typename std::enable_if<std::is_same<RHS0, RHS0>::value
365 && expect_unique,
RetType>::type
369 const std::array<FieldId, NPreds> &fieldid,
370 const std::array<Oid, NPreds> &eq_funcid,
372 RemRHS&& ...remrhs) {
373 return Impl(_this, systabid, idxid_hint, 0, fieldid, eq_funcid,
374 std::forward<RHS0>(rhs0), std::forward<RemRHS>(remrhs)...);
377 template<
class RHS0,
class ...RemRHS>
379 typename std::enable_if<std::is_same<RHS0, RHS0>::value
380 && !expect_unique,
RetType>::type
385 const std::array<FieldId, NPreds> &fieldid,
386 const std::array<Oid, NPreds> &eq_funcid,
388 RemRHS&& ...remrhs) {
389 return Impl(_this, systabid, idxid_hint, expect_n, fieldid,
390 eq_funcid, std::forward<RHS0>(rhs0),
391 std::forward<RemRHS>(remrhs)...);
395 template<
class ...RHS>
401 const std::array<FieldId, NPreds> &fieldid,
402 const std::array<Oid, NPreds> &eq_funcid,
412 std::vector<Oid> coltypid,
413 std::vector<uint64_t> coltypparam,
414 std::vector<std::string> field_names,
415 std::vector<bool> colisnullable,
416 std::vector<bool> colisarray,
432 std::vector<FieldId> idxcoltabcolids,
434 std::vector<Oid> idxcolltfuncids,
435 std::vector<Oid> idxcoleqfuncids);
448 const std::string &init_datafile,
491 template<
bool no_cache>
492 typename std::conditional<no_cache,
493 std::unique_ptr<CCLookupTableEntry>,
505 const std::vector<std::vector<Datum>> &data);
517 #endif // CATALOG_CATCACHEBASE_H
constexpr const Oid TAB_Type
Definition: initoids.h:19
SysTable_Function is an in-memory cached record in the system catalog SysTable_Function.
Definition: Function.h:16
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
uint8_t OpType
The operator type, see expr/optypes.h.
Definition: tdb_base.h:288
uint8_t IdxType
The index type, see index/idxtyps.h.
Definition: tdb_base.h:285
constexpr const Oid IDX_Table_tabid
Definition: initoids.h:36
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.
Oid FindOperator(OpType optype, Oid oparg0typid, Oid oparg1typid)
Returns the operator function id of the one with the specific operand types and operator type.
constexpr bool IsInitialized() const
Returns if the catalog cache has been initialized.
Definition: CatCacheBase.h:122
static constexpr FieldId tabid_colid()
Definition: Table.h:121
bool m_initialized
Definition: CatCacheBase.h:507
CCLookupTableEntry & operator=(const CCLookupTableEntry &)=delete
static T * CopySysTableStruct(const T *s)
Definition: CatCacheBase.h:67
static constexpr FieldId funcname_colid()
Definition: Function.h:114
constexpr const Oid IDX_Table_tabname
Definition: initoids.h:37
bool m_use_index
Definition: CatCacheBase.h:508
std::string GetTypeName(Oid typid)
Returns the type name of the specified type if it exists.
Definition: CatCacheBase.h:175
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:381
constexpr const Oid IDX_Index_idxid
Definition: initoids.h:20
static T * ConstructSysTableStruct(Args &&...args)
Constructs a SysTable_xxx struct from c++ values by invoking its constructor.
Definition: CatCacheBase.h:78
constexpr const Oid IDX_Type_typid
Definition: initoids.h:38
Oid AllocateOid()
Allocates an object ID.
std::shared_ptr< const SysTable_Function > FindFunction(Oid funcid)
Definition: CatCacheBase.h:184
static constexpr FieldId funcid_colid()
Definition: Function.h:99
SysTable_Index is an in-memory cached record in the system catalog SysTable_Index.
Definition: Index.h:16
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.
constexpr const Oid TAB_Index
Definition: initoids.h:13
std::shared_ptr< const IndexDesc > FindIndexDesc(Oid idxid)
Definition: CatCacheBase.h:352
friend struct SearchForCatalogEntry
Definition: CatCacheBase.h:406
CCLookupTableEntry(RecordId recid, std::shared_ptr< void > systable_struct)
Definition: CatCacheBase.h:20
absl::flat_hash_map< RecordId, CCLookupTableEntry > m_recid_lookup_table
Definition: CatCacheBase.h:510
constexpr const Oid TAB_Function
Definition: initoids.h:16
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)
int16_t FieldId
Definition: tdb_base.h:213
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.
Some internal functions of catalog cache implementations.
Definition: CatCacheBase.h:38
std::shared_ptr< const TableDesc > FindTableDesc(Oid tabid)
static constexpr FieldId idxname_colid()
Definition: Index.h:162
A Schema object stores the information for accessing an ordered set of typed fields either from a dis...
Definition: Schema.h:39
The record ID of a record on a page is a pair of ‘(PageNumber, SlotId)’.
Definition: Record.h:17
void BuildIndex(bool init, Oid idxid)
constexpr const Oid IDX_Aggregation_aggid
Definition: initoids.h:22
typename std::conditional< no_cache, std::unique_ptr< CCLookupTableEntry >, CCLookupTableEntry * >::type EntryPtr
Definition: CatCacheBase.h:356
constexpr const Oid TAB_Aggregation
Definition: initoids.h:18
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.
static constexpr FieldId tabname_colid()
Definition: Table.h:146
std::shared_ptr< const SysTable_Type > FindType(Oid typid)
Definition: CatCacheBase.h:157
static constexpr FieldId typid_colid()
Definition: Type.h:154
constexpr const Oid IDX_Function_funcid
Definition: initoids.h:29
void CheckIndexes(bool init)
Checks if any of the catalog indexes need to be initialized and/or rebuilt.
std::shared_ptr< void > m_systable_struct
Definition: CatCacheBase.h:30
absl::flat_hash_map< Oid, std::shared_ptr< IndexDesc > > m_index_desc
Definition: CatCacheBase.h:512
uint32_t FileId
The file ID.
Definition: tdb_base.h:222
Oid FindIndexByName(absl::string_view idxname)
Definition: CatCacheBase.h:229
SysTable_Table is an in-memory cached record in the system catalog SysTable_Table.
Definition: Table.h:16
void InitializeFromInitData(const std::string &init_datafile)
Creates the catalog from an init data file and initializes the catalog cache.
BootstrapCatCache stores hard-coded data needed to bootstrap the entire database catalog.
Definition: BootstrapCatCache.h:21
std::shared_ptr< const SysTable_Aggregation > FindAggregation(Oid aggid)
Returns the aggregation systable struct for the aggregation with ID aggid.
Definition: CatCacheBase.h:276
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< Oid, std::shared_ptr< TableDesc > > m_table_desc
Definition: CatCacheBase.h:511
uint8_t AggType
The aggregation type, see catalog/aggtyp.h.
Definition: tdb_base.h:296
Oid FindFunctionByName(absl::string_view funcname)
Definition: CatCacheBase.h:198
uint32_t Oid
Definition: tdb_base.h:211
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.
Oid FindTableByName(absl::string_view tabname)
Definition: CatCacheBase.h:141
RecordId m_recid
Definition: CatCacheBase.h:29
Oid FindAggregationByTidAndOprType(AggType aggtyp, Oid aggoprtypid)
Returns the aggregation ID for the aggregation with the given type and operand type.
std::shared_ptr< const SysTable_Index > FindIndex(Oid idxid)
Definition: CatCacheBase.h:215
std::shared_ptr< const SysTable_FunctionArgs > FindFunctionArgs(Oid funcid, int16_t funcargid)
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.
constexpr Oid InvalidOid
Definition: tdb_base.h:225
typename std::conditional< expect_unique, EntryPtr, std::vector< EntryPtr > >::type RetType
Definition: CatCacheBase.h:360
Oid FindAggregationByNameAndOprType(absl::string_view aggname, Oid aggoprtypid)
Returns the aggregation ID for the aggregation with the given name and aggregation operand type.
void LoadMinCache(BootstrapCatCache *catcache)
Loads the minimum set of the required catalog entries for initializing the cache.
constexpr const Oid TAB_Table
Definition: initoids.h:12
static constexpr FieldId idxid_colid()
Definition: Index.h:132
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.
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
constexpr const Oid IDX_Function_funcname
Definition: initoids.h:30
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.
static constexpr FieldId aggid_colid()
Definition: Aggregation.h:143
This is an internal data structure of the catalog cache for storing an in-memory catalog table entry.
Definition: CatCacheBase.h:19
std::vector< Oid > FindAllIndexesOfTable(Oid idxtabid)
CatCacheBase implements the common routines and public interfaces for accessing and modifying the sys...
Definition: CatCacheBase.h:103
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:366
void InitializeFromExistingData()
Initializes the catalog cache from the existing data.
void CreateDBMeta()
Creates and initializes the database meta file.
std::shared_ptr< const SysTable_Table > FindTable(Oid tabid)
Definition: CatCacheBase.h:127
std::vector< Datum > GetDatumVector(const T &systable_struct)
Definition: CatCacheBase.h:84