31 virtual ~StoreFactory() { }
33 virtual std::unique_ptr<m::Store> make(
const m::Table&)
const = 0;
37requires std::derived_from<T, m::Store>
38struct ConcreteStoreFactory : StoreFactory
40 std::unique_ptr<m::Store> make(
const m::Table &tbl)
const override {
return std::make_unique<T>(tbl); }
43struct CardinalityEstimatorFactory
45 virtual ~CardinalityEstimatorFactory() { }
51requires std::derived_from<T, m::CardinalityEstimator>
52struct ConcreteCardinalityEstimatorFactory : CardinalityEstimatorFactory
55 return std::make_unique<T>(std::move(database));
59struct WasmEngineFactory
61 virtual ~WasmEngineFactory() { }
63 virtual std::unique_ptr<m::WasmEngine> make()
const = 0;
67requires std::derived_from<T, m::WasmEngine>
68struct ConcreteWasmEngineFactory : WasmEngineFactory
70 std::unique_ptr<m::WasmEngine> make()
const override {
return std::make_unique<T>(); }
75 virtual ~BackendFactory() { }
77 virtual std::unique_ptr<m::Backend> make()
const = 0;
81requires std::derived_from<T, m::Backend>
82struct ConcreteBackendFactory : BackendFactory
84 std::unique_ptr<m::Backend> make()
const override {
return std::make_unique<T>(); }
87struct ConcreteWasmBackendFactory : BackendFactory
90 std::unique_ptr<WasmEngineFactory> platform_factory_;
93 ConcreteWasmBackendFactory(std::unique_ptr<WasmEngineFactory> platform_factory)
94 : platform_factory_(
std::
move(platform_factory))
97 std::unique_ptr<m::Backend> make()
const override {
98 return std::make_unique<m::WasmBackend>(platform_factory_->make());
102struct DatabaseInstructionFactory
104 virtual ~DatabaseInstructionFactory() { }
106 virtual std::unique_ptr<m::DatabaseInstruction> make(std::vector<std::string>
args)
const = 0;
110requires std::derived_from<T, m::DatabaseInstruction>
111struct ConcreteDatabaseInstructionFactory : DatabaseInstructionFactory
113 std::unique_ptr<m::DatabaseInstruction> make(std::vector<std::string>
args)
const override {
114 return std::make_unique<T>(std::move(
args));
129 const char *description_;
130 std::unique_ptr<T> instance_;
133 Component(
const char *description, std::unique_ptr<T> instance)
134 : description_(description), instance_(
std::
move(instance))
137 Component(
const char *description, T *instance)
138 : description_(description), instance_(instance)
141 const char * description()
const {
return description_; }
151 using map_t = std::unordered_map<m::ThreadSafePooledString, Component<T>>;
155 typename map_t::iterator default_;
159 auto it = components_.find(name);
160 if (it != components_.end())
161 throw std::invalid_argument(
"component with that name already exists");
162 it = components_.emplace_hint(it, std::move(name), std::move(component));
163 if (default_ == components_.end())
168 auto it = components_.find(name);
169 if (it == components_.end())
170 throw std::invalid_argument(
"component does not exist");
174 bool has_default()
const {
return default_ != components_.end(); }
177 const char * get_default_description()
const {
return default_->second.description; }
178 T & get_default()
const {
M_insist(has_default());
return *default_->second; }
181 auto it = components_.find(name);
182 if (it == components_.end())
183 throw std::invalid_argument(
"component does not exist");
184 return it->second.description;
190 auto it = components_.find(name);
191 if (it == components_.end())
192 throw std::invalid_argument(
"component does not exist");
196 typename map_t::iterator begin() {
return components_.begin(); }
197 typename map_t::iterator end() {
return components_.end(); }
198 typename map_t::const_iterator begin()
const {
return components_.begin(); }
199 typename map_t::const_iterator end()
const {
return components_.end(); }
200 typename map_t::const_iterator cbegin()
const {
return components_.begin(); }
201 typename map_t::const_iterator cend()
const {
return components_.end(); }
224 std::unordered_map<ThreadSafePooledString, Database*>
databases_;
296 if (not has_database_in_use())
297 throw std::logic_error(
"no database currently in use");
298 return *database_in_use_;
342 requires std::derived_from<T, m::Store>
344 auto c = Component<StoreFactory>(description, std::make_unique<ConcreteStoreFactory<T>>());
345 stores_.add(std::move(name), std::move(c));
352 std::unique_ptr<Store>
create_store(
const Table &tbl)
const {
return stores_.get_default().make(tbl); }
355 return stores_.get(name).make(tbl);
370 const char *description =
nullptr)
372 data_layouts_.add(std::move(name), Component<storage::DataLayoutFactory>(description, std::move(data_layout)));
395 requires std::derived_from<T, m::CardinalityEstimator>
397 auto c = Component<CardinalityEstimatorFactory>(
399 std::make_unique<ConcreteCardinalityEstimatorFactory<T>>()
401 cardinality_estimators_.add(std::move(name), std::move(c));
410 return cardinality_estimators_.get_default().make(std::move(database));
415 return cardinality_estimators_.get(name).make(std::move(database));
419 return cardinality_estimators_.get_default_name();
432 const char *description =
nullptr)
434 plan_enumerators_.add(std::move(name), Component<pe::PlanEnumerator>(description, std::move(PE)));
457 requires std::derived_from<T, m::Backend>
459 auto c = Component<BackendFactory>(description, std::make_unique<ConcreteBackendFactory<T>>());
460 backends_.add(std::move(name), std::move(c));
464 requires std::derived_from<T, m::WasmEngine>
466 auto c = Component<BackendFactory>(
468 std::make_unique<ConcreteWasmBackendFactory>(std::make_unique<ConcreteWasmEngineFactory<T>>())
470 backends_.add(std::move(name), std::move(c));
477 std::unique_ptr<Backend>
create_backend()
const {
return backends_.get_default().make(); }
493 const char *description =
nullptr)
495 cost_functions_.add(std::move(name), Component<CostFunction>(description, std::move(CF)));
518 requires std::derived_from<T, m::DatabaseInstruction>
520 auto I = Component<DatabaseInstructionFactory>(
522 std::make_unique<ConcreteDatabaseInstructionFactory<T>>()
524 instructions_.add(std::move(name), std::move(I));
529 const std::vector<std::string> &
args)
const
531 return instructions_.get(name).make(
args);
544 const char *description =
nullptr)
546 schedulers_.add(std::move(name), Component<Scheduler>(description, std::move(scheduler)));
572 std::unique_ptr<TableFactory>
table_factory(std::unique_ptr<TableFactory> table_factory) {
573 return std::exchange(table_factory_, std::move(table_factory));
581 requires std::derived_from<T, TableFactoryDecorator>
583 table_properties_.add(
585 Component<TableFactoryDecoratorCallback>(
587 std::make_unique<TableFactoryDecoratorCallback>([](std::unique_ptr<TableFactory> table_factory){
588 return std::make_unique<T>(std::move(table_factory));
596 std::unique_ptr<TableFactory> table_factory)
const
598 return table_properties_.get(name).operator()(std::move(table_factory));
611 const char *description =
nullptr)
613 pre_optimizations_.add(
615 Component<PreOptimizationCallback>(
617 std::make_unique<PreOptimizationCallback>(std::move(optimization))
633 const char *description =
nullptr)
635 logical_post_optimizations_.add(
637 Component<LogicalPostOptimizationCallback>(
639 std::make_unique<LogicalPostOptimizationCallback>(std::move(optimization))
645 return range(logical_post_optimizations_.begin(), logical_post_optimizations_.end());
657 const char *description =
nullptr)
659 physical_post_optimizations_.add(
661 Component<PhysicalPostOptimizationCallback>(
663 std::make_unique<PhysicalPostOptimizationCallback>(std::move(optimization))
669 return range(physical_post_optimizations_.begin(), physical_post_optimizations_.end());
A parser for command line arguments.
M_EXPORT const version_info & get()
auto operator*(PrimitiveExpr< U, L > other) -> PrimitiveExpr< common_type_t< T, U >, L >
Multiplies this and other.
std::pair<::wasm::Expression *, std::list< std::shared_ptr< Bit > > > move()
Moves the underlying Binaryen ::wasm::Expression and the referenced bits out of this.
ThreadSafeStringPool::proxy_type ThreadSafePooledString
The catalog contains all Databases and keeps track of all meta information of the database system.
void register_plan_enumerator(ThreadSafePooledString name, std::unique_ptr< pe::PlanEnumerator > PE, const char *description=nullptr)
Registers a new PlanEnumerator with the given name.
CostFunction & cost_function() const
Returns a reference to the default CostFunction.
std::unique_ptr< CardinalityEstimator > create_cardinality_estimator(const ThreadSafePooledString &name, ThreadSafePooledString database) const
Creates a new CardinalityEstimator of name name.
void register_cardinality_estimator(ThreadSafePooledString name, const char *description=nullptr)
Registers a new CardinalityEstimator with the given name.
auto plan_enumerators_cend() const
auto table_properties_end() const
auto schedulers_end() const
std::function< void(QueryGraph &)> PreOptimizationCallback
auto backends_begin() const
const memory::Allocator & allocator() const
Returns a reference to the memory::Allocator.
const Timer & timer() const
Returns the global Timer instance.
ThreadSafePooledString pool(std::string_view str) const
Creates an internalized copy of the string str by adding it to the internal StringPool.
auto logical_post_optimizations()
auto cost_functions_end() const
auto schedulers_cbegin() const
ComponentSet< CardinalityEstimatorFactory > cardinality_estimators_
void register_logical_post_optimization(ThreadSafePooledString name, LogicalPostOptimizationCallback optimization, const char *description=nullptr)
Registers a new logical post-optimization with the given name.
const ThreadSafeStringPool & get_pool() const
Returns a reference to the StringPool.
auto cost_functions_begin() const
auto plan_enumerators_begin() const
auto cost_functions_cbegin() const
void default_cardinality_estimator(const ThreadSafePooledString &name)
Sets the default CardinalityEstimator to use.
std::unordered_map< ThreadSafePooledString, Function * > standard_functions_
functions defined by the SQL standard
auto physical_post_optimizations_cbegin() const
auto cardinality_estimators_cend() const
void drop_database(const Database &db)
Drops the Database db.
auto data_layouts_cbegin() const
void default_store(const ThreadSafePooledString &name)
Sets the default Store to use.
auto backends_end() const
ComponentSet< DatabaseInstructionFactory > instructions_
ThreadSafeStringPool & get_pool()
Returns a reference to the StringPool.
ComponentSet< StoreFactory > stores_
const ThreadSafePooledString & default_cardinality_estimator_name() const
Returns the name of the default CardinalityEstimator.
Scheduler & scheduler(const ThreadSafePooledString &name) const
Returns a reference to the Scheduler with the given name.
ComponentSet< BackendFactory > backends_
ComponentSet< TableFactoryDecoratorCallback > table_properties_
auto schedulers_begin() const
auto plan_enumerators_begin()
auto stores_cbegin() const
Database & get_database_in_use()
Returns a reference to the Database that is currently in use, if any.
ComponentSet< PhysicalPostOptimizationCallback > physical_post_optimizations_
pe::PlanEnumerator & plan_enumerator(const ThreadSafePooledString &name) const
Returns a reference to the PlanEnumerator with the given name.
void default_cost_function(const ThreadSafePooledString &name)
Sets the default CostFunction to use.
auto physical_post_optimizations_begin()
const ThreadSafePooledString & default_cost_function_name() const
Returns the name of the default CostFunction.
void register_wasm_backend(ThreadSafePooledString name, const char *description=nullptr)
Registers a new WasmBackend using the given WasmEngine with the given name.
Database & get_database(const ThreadSafePooledString &name) const
Returns the Database with the given name.
memory::Allocator & allocator()
Returns a reference to the memory::Allocator.
const m::ThreadSafePooledString & default_data_layout_name() const
Returns the name of the default DataLayoutFactory.
ComponentSet< CostFunction > cost_functions_
Catalog & operator=(const Catalog &)=delete
storage::DataLayoutFactory & data_layout(const ThreadSafePooledString &name) const
Returns a reference to the DataLayoutFactory with the given name.
auto plan_enumerators_end()
std::unique_ptr< Store > create_store(const Table &tbl) const
Creates a new Store for the given Table tbl.
bool has_default_cardinality_estimator() const
Returns true iff the Catalog has a default CardinalityEstimator.
ThreadSafeStringPool pool_
pool of strings
auto cardinality_estimators_end() const
Database * database_in_use_
the currently used database
auto physical_post_optimizations_cend() const
void register_scheduler(ThreadSafePooledString name, std::unique_ptr< Scheduler > scheduler, const char *description=nullptr)
Registers a new Scheduler with the given name.
void default_data_layout(const ThreadSafePooledString &name)
Sets the default DataLayoutFactory to use.
std::unique_ptr< TableFactory > apply_table_property(const ThreadSafePooledString &name, std::unique_ptr< TableFactory > table_factory) const
Applies the TableFactoryDecorator corresponding to name to table_factory.
bool has_database_in_use() const
Returns true if any Database is currently in use.
void register_instruction(ThreadSafePooledString name, const char *description=nullptr)
Registers a new DatabaseInstruction with the given name.
ThreadSafePooledString pool(const char *str) const
Creates an internalized copy of the string str by adding it to the internal StringPool.
bool has_default_data_layout() const
Returns true iff the Catalog has a default DataLayoutFactory.
auto pre_optimizations_cend() const
ComponentSet< pe::PlanEnumerator > plan_enumerators_
void register_table_property(ThreadSafePooledString name, const char *description=nullptr)
Registers a new TableFactoryDecorator with the given name.
static Catalog & Get()
Return a reference to the single Catalog instance.
bool has_database(const ThreadSafePooledString &name) const
Returns true iff a Database with the given name exists.
auto cardinality_estimators_cbegin() const
auto data_layouts_end() const
std::function< std::unique_ptr< Producer >(std::unique_ptr< Producer >)> LogicalPostOptimizationCallback
auto plan_enumerators_end() const
void register_backend(ThreadSafePooledString name, const char *description=nullptr)
Registers a new Backend with the given name.
auto table_properties_end()
std::unique_ptr< memory::Allocator > allocator_
our custom allocator
bool has_default_plan_enumerator() const
Returns true iff the Catalog has a default PlanEnumerator.
auto cardinality_estimators_begin() const
auto stores_begin() const
auto instructions_cbegin() const
auto cost_functions_end()
bool has_default_scheduler() const
Returns true iff the Catalog has a default Scheduler.
std::size_t num_databases() const
Returns the number of Databases.
auto physical_post_optimizations_begin() const
auto physical_post_optimizations_end()
const ThreadSafePooledString & default_store_name() const
Returns the name of the default Store.
std::unique_ptr< DatabaseInstruction > create_instruction(const ThreadSafePooledString &name, const std::vector< std::string > &args) const
Returns a reference to the DatabaseInstruction with the given name.
auto pre_optimizations_begin()
auto data_layouts_cend() const
std::function< std::unique_ptr< MatchBase >(std::unique_ptr< MatchBase >)> PhysicalPostOptimizationCallback
std::unique_ptr< CardinalityEstimator > create_cardinality_estimator(ThreadSafePooledString database) const
Creates a new CardinalityEstimator.
void register_store(ThreadSafePooledString name, const char *description=nullptr)
Registers a new Store with the given name.
auto backends_cend() const
const ThreadSafePooledString & default_plan_enumerator_name() const
Returns the name of the default PlanEnumerator.
auto plan_enumerators_cbegin() const
CostFunction & cost_function(const ThreadSafePooledString &name) const
Returns a reference to the CostFunction with the given name.
void default_scheduler(const ThreadSafePooledString &name)
Sets the default Scheduler to use.
void register_physical_post_optimization(const char *name, PhysicalPostOptimizationCallback optimization, const char *description=nullptr)
Registers a new physical post-optimization with the given name.
Timer & timer()
Returns the global Timer instance.
auto logical_post_optimizations_cbegin() const
Scheduler & scheduler() const
Returns a reference to the default Scheduler.
bool has_default_backend() const
Returns true iff the Catalog has a default Backend.
const ThreadSafePooledString & default_backend_name() const
Returns the name of the default Backend.
void default_plan_enumerator(const ThreadSafePooledString &name)
Sets the default PlanEnumerator to use.
auto pre_optimizations_begin() const
static void Clear()
Removes all content from the Catalog instance.
auto instructions_begin() const
auto schedulers_cend() const
auto instructions_cend() const
auto backends_cbegin() const
static Catalog * the_catalog_
Singleton Catalog instance.
auto logical_post_optimizations_end() const
void register_pre_optimization(ThreadSafePooledString name, PreOptimizationCallback optimization, const char *description=nullptr)
Registers a new pre-optimization with the given name.
auto pre_optimizations_end()
auto physical_post_optimizations_end() const
auto logical_post_optimizations_cend() const
auto cardinality_estimators_begin()
std::unique_ptr< Backend > create_backend(const ThreadSafePooledString &name) const
Returns a new Backend of name name.
bool has_default_store() const
Returns true iff the Catalog has a default Store.
void set_database_in_use(Database &db)
Sets the Database db as the Database that is currently in use.
auto table_properties_begin()
storage::DataLayoutFactory & data_layout() const
Returns a reference to the default DataLayoutFactory.
const Function * get_function(const ThreadSafePooledString &name) const
Returns a reference to the Function with the given name.
Catalog(const Catalog &)=delete
const ThreadSafePooledString & default_scheduler_name() const
Returns the name of the default Scheduler.
const Database & get_database_in_use() const
Returns a reference to the Database that is currently in use, if any.
auto table_properties_cend() const
ComponentSet< LogicalPostOptimizationCallback > logical_post_optimizations_
ComponentSet< storage::DataLayoutFactory > data_layouts_
auto cost_functions_cend() const
auto physical_post_optimizations()
bool has_default_cost_function() const
Returns true iff the Catalog has a default CostFunction.
auto cardinality_estimators_end()
pe::PlanEnumerator & plan_enumerator() const
Returns a reference to the default PlanEnumerator.
std::unique_ptr< Backend > create_backend() const
Returns a new Backend.
auto data_layouts_begin() const
static void Destroy()
Destroys the current Catalog instance.
void unset_database_in_use()
Unsets the Database that is currenly in use.
ComponentSet< Scheduler > schedulers_
std::unique_ptr< TableFactory > table_factory_
The TableFactory used to construct Tables.
void register_cost_function(ThreadSafePooledString name, std::unique_ptr< CostFunction > CF, const char *description=nullptr)
Registers a new CostFunction with the given name.
auto pre_optimizations_end() const
auto data_layouts_begin()
TableFactory & table_factory() const
Returns a reference to the stored TableFactory.
std::function< std::unique_ptr< TableFactory >(std::unique_ptr< TableFactory >)> TableFactoryDecoratorCallback
auto table_properties_cbegin() const
void register_data_layout(ThreadSafePooledString name, std::unique_ptr< storage::DataLayoutFactory > data_layout, const char *description=nullptr)
Registers a new DataLayoutFactory with the given name.
auto instructions_end() const
ComponentSet< PreOptimizationCallback > pre_optimizations_
auto table_properties_begin() const
auto cost_functions_begin()
auto logical_post_optimizations_begin() const
m::ArgParser & arg_parser()
auto logical_post_optimizations_end()
Timer timer_
a global timer
std::unordered_map< ThreadSafePooledString, Database * > databases_
the databases
std::unique_ptr< Store > create_store(const ThreadSafePooledString &name, const Table &tbl) const
Creates a new Store of name name for the given Table tbl.
void default_backend(const ThreadSafePooledString &name)
Sets the default Backend to use.
auto instructions_begin()
std::unique_ptr< TableFactory > table_factory(std::unique_ptr< TableFactory > table_factory)
Replaces the stored TableFactory with table_factory and returns the old TableFactory.
auto pre_optimizations_cbegin() const
auto logical_post_optimizations_begin()
A Database is a set of Tables, Functions, and Statistics.
ThreadSafePooledString name
the name of the database
The query graph represents all data sources and joins in a graph structure.
The Scheduler handles the execution of all incoming queries.
The table factory creates Tables with all enabled decorators.
A table is a sorted set of attributes.
Collect timings of events.
This is the common interface for all memory allocators that support rewiring.
An interface for all plan enumerators.
This is an interface for factories that compute particular DataLayouts for a given sequence of Types,...