26 if (not C.has_database_in_use()) { diag.
err() <<
"No database selected.\n";
return; }
28 auto &DB = C.get_database_in_use();
29 if (DB.size() == 0) { diag.
err() <<
"There are no tables in the database.\n";
return; }
31 auto CE = C.create_cardinality_estimator(C.pool(
"Spn"), DB.name);
32 auto spn_estimator = cast<SpnEstimator>(CE.get());
33 spn_estimator->learn_spns();
34 DB.cardinality_estimator(std::move(CE));
36 if (not
Options::Get().quiet) { diag.
out() <<
"Learned SPN on every table in " << DB.name <<
".\n"; }
40static
void register_instructions()
43#define REGISTER(NAME, DESCRIPTION) \
44 C.register_instruction<NAME>(C.pool(#NAME), DESCRIPTION)
57 if (
auto stmt = cast<ast::Stmt>(&
ast())) {
59 stmt->dump(diag.
out());
63 dot.
show(
"ast",
false,
"dot");
71 (*pre_opt.second).
operator()(*graph_);
72 graph_construction.stop();
79 dot.
show(
"graph",
false,
"fdp");
86 auto logical_plan_computation = C.
timer().
create_timing(
"Compute the logical query plan");
91 logical_plan_computation.stop();
99 dot.
show(
"logical_plan",
false,
"dot");
108 static thread_local std::unique_ptr<Backend> backend;
112 auto physical_plan_computation = C.
timer().
create_timing(
"Compute the physical query plan");
114 backend->register_operators(PhysOpt);
119 physical_plan_computation.stop();
133 auto &I = ast<ast::InsertStmt>();
134 auto &
T = DB.get_table(I.table_name.text.assert_not_none());
135 auto &store =
T.store();
141 auto ts_begin = std::find_if(
T.cbegin_hidden(),
T.end_hidden(),
143 return attr.name == C.pool(
"$ts_begin");
145 auto ts_end = std::find_if(
T.cbegin_hidden(),
T.end_hidden(),
147 return attr.name == C.pool(
"$ts_end");
151 for (
auto &t : I.tuples) {
153 for (std::size_t i = 0; i != t.size(); ++i) {
154 auto attr_id =
T.convert_id(i);
158 get_tuple.emit_St_Tup_Null(0, i);
166 get_tuple.emit(*v.second);
167 get_tuple.emit_Cast(S[attr_id].type, v.second->type());
168 get_tuple.emit_St_Tup(0, attr_id, S[attr_id].type);
176 if (ts_begin !=
T.end_hidden()) {
186 DB.invalidate_indexes(
T.name());
206 std::ifstream file(
path_);
208 const auto errsv = errno;
209 diag.
err() <<
"Could not open file " <<
path_;
211 diag.
err() <<
": " << strerror(errsv);
212 diag.
err() << std::endl;
217 diag.
err() <<
"Error reading DSV file: " << e.
what() <<
"\n";
231 diag.
out() <<
"Created database " <<
db_name_ <<
".\n";
232 }
catch (std::invalid_argument) {
233 diag.
err() <<
"Database " <<
db_name_ <<
" already exists.\n";
242 diag.
out() <<
"Dropped database " <<
db_name_ <<
".\n";
243 }
catch (std::invalid_argument) {
244 diag.
err() <<
"Database " <<
db_name_ <<
" does not exist.\n";
252 auto &DB = C.get_database(
db_name_);
253 C.set_database_in_use(DB);
255 diag.
out() <<
"Using database " <<
db_name_ <<
".\n";
256 }
catch (std::out_of_range) {
257 diag.
err() <<
"Database " <<
db_name_ <<
" does not exist.\n";
264 auto &DB = C.get_database_in_use();
266 Table *table =
nullptr;
268 table = &DB.add(std::move(
table_));
269 }
catch (std::invalid_argument) {
270 diag.
err() <<
"Table " << table_name <<
" already exists in database " << DB.name <<
".\n";
273 table->
layout(C.data_layout());
274 table->
store(C.create_store(*table));
277 diag.
out() <<
"Created table " << table->
name() <<
".\n";
283 auto &DB = C.get_database_in_use();
287 DB.drop_table(table_name);
289 diag.
out() <<
"Dropped table " << table_name <<
".\n";
290 }
catch (std::invalid_argument) {
291 diag.
err() <<
"Table " << table_name <<
" does not exist in Database " << DB.name <<
".\n";
299 auto &DB = C.get_database_in_use();
304 for (
auto &entry : table.schema()) {
315 diag.
err() <<
"Could not bulkload index." <<
'\n';
323 }
catch (std::out_of_range) {
327 diag.
err() <<
"Index " <<
index_name_ <<
" already exists in Database " << DB.name <<
".\n";
334 auto &DB = C.get_database_in_use();
338 DB.drop_index(index_name);
340 diag.
out() <<
"Dropped index " << index_name <<
".\n";
342 diag.
err() <<
"Index " << index_name <<
" does not exist in Database " << DB.name <<
".\n";
347#define ACCEPT(CLASS) \
348 void CLASS::accept(DatabaseCommandVisitor &v) { v(*this); } \
349 void CLASS::accept(ConstDatabaseCommandVisitor &v) const { v(*this); }
#define M_DATABASE_COMMAND_LIST(X)
__attribute__((constructor(202))) static void register_interpreter()
#define M_TIME_EXPR(EXPR, DESCR, TIMER)
#define M_unreachable(MSG)
The catalog contains all Databases and keeps track of all meta information of the database system.
CostFunction & cost_function() const
Returns a reference to the default CostFunction.
auto logical_post_optimizations()
Database & get_database_in_use()
Returns a reference to the Database that is currently in use, if any.
Database & add_database(ThreadSafePooledString name)
Creates a new Database with the given name.
static Catalog & Get()
Return a reference to the single Catalog instance.
void drop_database(const ThreadSafePooledString &name)
Drops the Database with the name.
Timer & timer()
Returns the global Timer instance.
auto physical_post_optimizations()
pe::PlanEnumerator & plan_enumerator() const
Returns a reference to the default PlanEnumerator.
std::unique_ptr< Backend > create_backend() const
Returns a new Backend.
void execute(Diagnostic &diag) override
Executes the command.
ThreadSafePooledString db_name_
ThreadSafePooledString table_name_
ThreadSafePooledString index_name_
void execute(Diagnostic &diag) override
Executes the command.
ThreadSafePooledString attribute_name_
std::unique_ptr< idx::IndexBase > index_
void execute(Diagnostic &diag) override
Executes the command.
std::unique_ptr< Table > table_
A reader for delimiter separated value (DSV) files.
Scheduler::Transaction * transaction()
void execute(Diagnostic &diag) override
Executes the command.
std::ostream & out() const
void execute(Diagnostic &diag) override
Executes the command.
ThreadSafePooledString db_name_
std::vector< ThreadSafePooledString > index_names_
void execute(Diagnostic &diag) override
Executes the command.
void execute(Diagnostic &diag) override
Executes the command.
std::vector< ThreadSafePooledString > table_names_
void execute(Diagnostic &diag) override
Executes the command.
std::filesystem::path path_
void execute(Diagnostic &diag) override
Executes the command.
void execute(Diagnostic &diag) override
Executes the command.
bool dryrun
If true, do not pass the query to the backend for execution.
static Options & Get()
Return a reference to the single Options instance.
Concrete PhysicalOptimizer implementation using a concrete statically-typed.
void cover(const Operator &plan) override
Finds an optimal physical operator covering for the logical plan rooted in plan.
std::unique_ptr< MatchBase > extract_plan() override
Extracts the found physical operator covering by moving it out of the underlying physical plan table.
A data type representing a pooled (or internalized) object.
std::unique_ptr< Consumer > logical_plan_
std::unique_ptr< MatchBase > physical_plan_
std::unique_ptr< QueryGraph > graph_
void execute(Diagnostic &diag) override
Executes the command.
static std::unique_ptr< QueryGraph > Build(const ast::Stmt &stmt)
A Schema represents a sequence of identifiers, optionally with a prefix, and their associated types.
void add(entry_type e)
Adds the entry e to this Schema.
A stack machine that evaluates an expression.
This class provides direct write access to the contents of a Store.
void append(const Tuple &tup) const
Appends tup to the store.
const Schema & schema() const
Returns the Schema of Tuples to write.
A table is a sorted set of attributes.
virtual const storage::DataLayout & layout() const =0
Returns a reference to the physical data layout.
virtual const ThreadSafePooledString & name() const =0
Returns the name of the Table.
virtual Store & store() const =0
Returns a reference to the backing store.
TimingProcess create_timing(std::string name)
Creates a new TimingProcess with the given name.
void set(std::size_t idx, Value val)
Assigns the Value val to this Tuple at index idx and clears the respective NULL bit.
void execute(Diagnostic &diag) override
Executes the command.
void execute(Diagnostic &diag) override
Executes the command.
ThreadSafePooledString db_name_
This class holds a SQL attribute value.
const char * what() const noexcept override
Signals that an argument to a function of method was invalid.
Learn an SPN on every table in the database that is currently in use.
void execute(Diagnostic &diag) override
Executes the command.