taco-db  0.1.0
Database.h
Go to the documentation of this file.
1 
10 #ifndef DBMAIN_DATABASE_H
11 #define DBMAIN_DATABASE_H
12 
13 #include "base/tdb_base.h"
14 
15 namespace taco {
16 
17 // Always use forward declaration of other classes instead of including the
18 // headers to avoid cyclic references. Don't use the class members in the
19 // Database.h header!!
20 class FileManager;
21 class CatCache;
22 class BufferManager;
23 class Table;
24 class Schema;
25 
31 extern bool g_test_no_bufman;
32 
38 extern bool g_test_no_catcache;
39 
45 extern bool g_test_no_index;
46 
55 
65 class Database {
66 public:
69  m_initialized(false) {}
70 
75  close();
76  }
77 
83  static void init_global();
84 
93  void open(const std::string& path, size_t bpool_size, bool create,
94  bool allow_overwrite = false);
95 
96  constexpr bool
97  is_open() const {
98  return m_initialized;
99  }
100 
105  void close();
106 
107  FileManager*
108  file_manager() const {
109  return m_file_manager;
110  }
111 
113  buf_manager() const {
114  return m_buf_manager;
115  }
116 
117  CatCache*
118  catcache() const {
119  return m_catcache;
120  }
121 
122  Schema* actres_schema() const;
123 
133  void CreateTable(absl::string_view tabname,
134  std::vector<Oid> coltypid,
135  std::vector<uint64_t> coltypparam = {},
136  const std::vector<absl::string_view> &field_names = {},
137  std::vector<bool> colisnullable = {},
138  std::vector<bool> colisarray = {});
139 
150  void CreateIndex(absl::string_view idxname,
151  Oid idxtabid,
152  IdxType idxtyp,
153  bool idxunique,
154  std::vector<FieldId> idxcoltabcolids,
155  std::vector<Oid> idxcolltfuncids = {},
156  std::vector<Oid> idxcoleqfuncids = {});
157 
158  const std::string&
159  GetLastDBPath() const {
160  return m_db_path;
161  }
162 
163 private:
165  std::string m_db_path;
170 };
171 
173 extern Database * const g_db;
174 
176 #define g_bufman g_db->buf_manager()
177 
179 #define g_fileman g_db->file_manager()
180 
182 #define g_catcache g_db->catcache()
183 
185 #define g_actsch g_db->actres_schema()
186 
187 } // namespace taco
188 
189 #endif // DBMAIN_DATABSE_H
BufferManager implements a steal and no-force buffer pool with a fixed number of page frames to buffe...
Definition: BufferManager.h:77
Catcache is the catalog cache class as configured in the top-level CMakeLists.txt.
Definition: CatCache.h:18
The class for a database instance.
Definition: Database.h:65
std::string m_db_path
Definition: Database.h:165
constexpr bool is_open() const
Definition: Database.h:97
BufferManager * buf_manager() const
Definition: Database.h:113
Schema * actres_schema() const
Definition: Database.cpp:104
FileManager * m_file_manager
Definition: Database.h:166
Schema * m_actres_schema
Definition: Database.h:169
bool m_initialized
Definition: Database.h:164
~Database()
Automatically closes the database if not closed.
Definition: Database.h:74
FileManager * file_manager() const
Definition: Database.h:108
const std::string & GetLastDBPath() const
Definition: Database.h:159
BufferManager * m_buf_manager
Definition: Database.h:167
void CreateTable(absl::string_view tabname, std::vector< Oid > coltypid, std::vector< uint64_t > coltypparam={}, const std::vector< absl::string_view > &field_names={}, std::vector< bool > colisnullable={}, std::vector< bool > colisarray={})
Creates a table named tabname'', withcoltypid.size()'' columns.
Definition: Database.cpp:143
CatCache * m_catcache
Definition: Database.h:168
void close()
Closes the database.
Definition: Database.cpp:111
void CreateIndex(absl::string_view idxname, Oid idxtabid, IdxType idxtyp, bool idxunique, std::vector< FieldId > idxcoltabcolids, std::vector< Oid > idxcolltfuncids={}, std::vector< Oid > idxcoleqfuncids={})
Createa an index named idxname'' and inserts into the catalog.
Definition: Database.cpp:173
CatCache * catcache() const
Definition: Database.h:118
static void init_global()
Initializes all the global objects that are not associated with a particular database.
Definition: Database.cpp:38
Database()
A trivial constructor.
Definition: Database.h:68
void open(const std::string &path, size_t bpool_size, bool create, bool allow_overwrite=false)
Initializes the database components and opens or creates the database at the specified path.
Definition: Database.cpp:50
FileManager exposes a virtual file interface based on FSFile.
Definition: FileManager.h:174
A Schema object stores the information for accessing an ordered set of typed fields either from a dis...
Definition: Schema.h:39
Definition: datum.h:28
bool g_test_no_index
Set this to true if you don't want the Database to disallow building any index (including the catalog...
Definition: Database.cpp:33
uint32_t Oid
Definition: tdb_base.h:210
uint8_t IdxType
The index type, see index/idxtyps.h.
Definition: tdb_base.h:284
bool g_test_no_catcache
Set this to true if you don't want Database to create and initialize the catalog and its cache.
Definition: Database.cpp:31
bool g_test_catcache_use_volatiletree
Set this to true if you want the catalog cache to build volatile tree index over the catalog tables.
Definition: Database.cpp:35
bool g_test_no_bufman
Set this to true if you don't want Database to create and initialize the buffer manager.
Definition: Database.cpp:30
Database *const g_db
The global instance of Database.
Definition: Database.cpp:27
This file contains all the basic definitions in TDB.