mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Catalog.cpp
Go to the documentation of this file.
2
8
9
10using namespace m;
11
12
13/*======================================================================================================================
14 * Catalog
15 *====================================================================================================================*/
16
18
20 : allocator_(new memory::LinearAllocator())
21{
22 /*----- Initialize standard functions. ---------------------------------------------------------------------------*/
23#define M_FUNCTION(NAME, KIND) { \
24 auto name = pool(#NAME); \
25 auto res = standard_functions_.emplace(name, new Function(name, Function::FN_ ## NAME, Function::KIND)); \
26 M_insist(res.second, "function already defined"); \
27}
28#include <mutable/tables/Functions.tbl>
29#undef M_FUNCTION
30}
31
32
34{
35 for (auto db : databases_)
36 delete db.second;
37 for (auto fn : standard_functions_)
38 delete fn.second;
39}
40
41__attribute__((constructor(200)))
42Catalog & Catalog::Get()
43{
44 if (not the_catalog_)
45 the_catalog_ = new Catalog();
46 return *the_catalog_;
47}
48
49__attribute__((destructor(200)))
50void Catalog::Destroy()
51{
53 Catalog::the_catalog_ = nullptr;
54}
55
56/*===== Databases ====================================================================================================*/
57
59{
60 auto it = databases_.find(name);
61 if (it != databases_.end()) throw std::invalid_argument("database with that name already exist");
62 it = databases_.emplace_hint(it, std::move(name), new Database(name));
63 return *it->second;
64}
65
67{
68 if (has_database_in_use() and get_database_in_use().name == name)
69 throw std::invalid_argument("Cannot drop database; currently in use.");
70 auto it = databases_.find(name);
71 if (it == databases_.end())
72 throw std::invalid_argument("Database of that name does not exist.");
73 delete it->second;
74 databases_.erase(it);
75}
76
77__attribute__((constructor(201)))
78static void add_catalog_args()
79{
80 Catalog &C = Catalog::Get();
81
82 /*----- Command-line arguments -----------------------------------------------------------------------------------*/
83 C.arg_parser().add<const char*>(
84 /* group= */ "Catalog",
85 /* short= */ nullptr,
86 /* long= */ "--data-layout",
87 /* description= */ "data layout to use",
88 [&C] (const char *str) {
89 try {
90 C.default_data_layout(C.pool(str));
91 } catch (std::invalid_argument) {
92 std::cerr << "There is no data layout with the name \"" << str << "\".\n";
93 std::exit(EXIT_FAILURE);
94 }
95 }
96 );
97 C.arg_parser().add<const char*>(
98 /* group= */ "Catalog",
99 /* short= */ nullptr,
100 /* long= */ "--cardinality-estimator",
101 /* description= */ "cardinality estimator to use",
102 [&C] (const char *str) {
103 try {
105 } catch (std::invalid_argument) {
106 std::cerr << "There is no cardinality estimator with the name \"" << str << "\".\n";
107 std::exit(EXIT_FAILURE);
108 }
109 }
110 );
111 C.arg_parser().add<const char*>(
112 /* group= */ "Catalog",
113 /* short= */ nullptr,
114 /* long= */ "--plan-enumerator",
115 /* description= */ "plan enumerator to use",
116 [&C] (const char *str) {
117 try {
119 } catch (std::invalid_argument) {
120 std::cerr << "There is no plan enumerator with the name \"" << str << "\".\n";
121 std::exit(EXIT_FAILURE);
122 }
123 }
124 );
125 C.arg_parser().add<const char*>(
126 /* group= */ "Catalog",
127 /* short= */ nullptr,
128 /* long= */ "--backend",
129 /* description= */ "execution backend to use",
130 [&C] (const char *str) {
131 try {
132 C.default_backend(C.pool(str));
133 } catch (std::invalid_argument) {
134 std::cerr << "There is no execution backend with the name \"" << str << "\".\n";
135 std::exit(EXIT_FAILURE);
136 }
137 }
138 );
139 C.arg_parser().add<const char*>(
140 /* group= */ "Catalog",
141 /* short= */ nullptr,
142 /* long= */ "--scheduler",
143 /* description= */ "query scheduler to use",
144 [&C] (const char *str) {
145 try {
146 C.default_scheduler(C.pool(str));
147 } catch (std::invalid_argument) {
148 std::cerr << "There is no query scheduler with the name \"" << str << "\".\n";
149 std::exit(EXIT_FAILURE);
150 }
151 }
152 );
153}
__attribute__((constructor(202))) static void register_interpreter()
void add(const char *group_name, const char *short_name, const char *long_name, const char *description, Callback &&callback)
Adds a new group option to the ArgParser.
Definition: ArgParser.hpp:84
‍mutable namespace
Definition: Backend.hpp:10
ThreadSafeStringPool::proxy_type ThreadSafePooledString
Definition: Pool.hpp:464
and
Definition: enum_ops.hpp:12
A simple linear allocator which keeps a global pointer to the next free memory address and advances i...
Definition: WasmDSL.cpp:218
The catalog contains all Databases and keeps track of all meta information of the database system.
Definition: Catalog.hpp:215
void default_cardinality_estimator(const ThreadSafePooledString &name)
Sets the default CardinalityEstimator to use.
Definition: Catalog.hpp:405
std::unordered_map< ThreadSafePooledString, Function * > standard_functions_
functions defined by the SQL standard
Definition: Catalog.hpp:226
Database & get_database_in_use()
Returns a reference to the Database that is currently in use, if any.
Definition: Catalog.hpp:295
void default_data_layout(const ThreadSafePooledString &name)
Sets the default DataLayoutFactory to use.
Definition: Catalog.hpp:375
bool has_database_in_use() const
Returns true if any Database is currently in use.
Definition: Catalog.hpp:293
Database & add_database(ThreadSafePooledString name)
Creates a new Database with the given name.
Definition: Catalog.cpp:58
ThreadSafePooledString pool(const char *str) const
Creates an internalized copy of the string str by adding it to the internal StringPool.
Definition: Catalog.hpp:274
static Catalog & Get()
Return a reference to the single Catalog instance.
void drop_database(const ThreadSafePooledString &name)
Drops the Database with the name.
Definition: Catalog.cpp:66
void default_scheduler(const ThreadSafePooledString &name)
Sets the default Scheduler to use.
Definition: Catalog.hpp:549
void default_plan_enumerator(const ThreadSafePooledString &name)
Sets the default PlanEnumerator to use.
Definition: Catalog.hpp:437
static Catalog * the_catalog_
Singleton Catalog instance.
Definition: Catalog.hpp:218
m::ArgParser & arg_parser()
Definition: Catalog.hpp:253
std::unordered_map< ThreadSafePooledString, Database * > databases_
the databases
Definition: Catalog.hpp:224
void default_backend(const ThreadSafePooledString &name)
Sets the default Backend to use.
Definition: Catalog.hpp:473
A Database is a set of Tables, Functions, and Statistics.
Definition: Schema.hpp:870