36 if (
auto d = cast<const ast::Designator>(&expr)) {
37 prefix = d->table_name.text;
40 std::ostringstream oss;
50void Schema::dump(std::ostream &out)
const { out << *
this << std::endl; }
60 auto primary_key = table.primary_key();
61 auto pred = [
this](
const auto &ref){
return *
this == ref.get(); };
62 return unique or (primary_key.size() == 1
and
63 std::find_if(primary_key.cbegin(), primary_key.cend(), pred) != primary_key.cend());
69 out <<
"Attribute `" << table.name() <<
"`.`" << name <<
"`, "
70 <<
"id " <<
id <<
", "
86 for (
auto attr = this->begin_all(); attr != this->end_all(); ++attr) {
88 if (attr->not_nullable)
90 if (attr->is_unique())
92 if (attr->reference
and attr->reference->is_unique())
96 S.
add({alias.
has_value() ? alias : this->name(), attr->name}, attr->type, constraints);
102 view v(cbegin_all(), cend_all(), [](
auto it) ->
auto & {
return it->type; });
103 layout_ = factory.
make(v.begin(), v.end());
109 out <<
"Table `" << name_ <<
'`';
110 for (
const auto &attr : attrs_)
111 out <<
"\n` " << attr.id <<
": `" << attr.name <<
"` " << *attr.type;
130 auto ts_begin = C.pool(
"$ts_begin");
131 auto ts_end = C.pool(
"$ts_end");
132 table_->push_back(ts_begin, i8);
133 table_->push_back(ts_end, i8);
134 (*table_)[ts_begin].is_hidden =
true;
135 (*table_)[ts_begin].not_nullable =
true;
136 (*table_)[ts_end].is_hidden =
true;
137 (*table_)[ts_end].not_nullable =
true;
143 out <<
"MultiVersioningTable Decorator" << std::endl;
163 if (
auto bt = cast<const BaseTable>(ds.get())) {
165 auto it = std::find_if(bt->table().cbegin_hidden(),
166 bt->table().end_hidden(),
168 return attr.name == C.pool(
"$ts_begin");
171 if (it != bt->table().end_hidden()) {
172 ast::Token table_name(pos, bt->table().name(), TK_EOF);
175 std::unique_ptr<ast::Expr> ts_begin_designator = std::make_unique<ast::Designator>(
184 std::unique_ptr<ast::Expr> ts_begin_transaction_constant = std::make_unique<ast::Constant>(
ast::Token(
192 std::unique_ptr<ast::Expr> ts_begin_filter_clause = std::make_unique<ast::BinaryExpr>(
194 std::move(ts_begin_designator),
195 std::move(ts_begin_transaction_constant)
200 std::unique_ptr<ast::Expr> ts_end_designator = std::make_unique<ast::Designator>(
205 &bt->table()[C.
pool(
"$ts_end")]
209 std::unique_ptr<ast::Expr> ts_end_transaction_constant = std::make_unique<ast::Constant>(
ast::Token(
217 std::unique_ptr<ast::Expr> ts_end_greater_transaction_expr = std::make_unique<ast::BinaryExpr>(
219 std::move(ts_end_designator),
220 std::move(ts_end_transaction_constant)
225 std::unique_ptr<ast::Expr> ts_end_designator_2 = std::make_unique<ast::Designator>(
230 &bt->table()[C.
pool(
"$ts_end")]
234 std::unique_ptr<ast::Expr> neg_one_constant = std::make_unique<ast::Constant>(
ast::Token(
242 std::unique_ptr<ast::Expr> ts_end_eq_zero = std::make_unique<ast::BinaryExpr>(
244 std::move(ts_end_designator_2),
245 std::move(neg_one_constant)
250 std::unique_ptr<ast::Expr> ts_end_filter_clause = std::make_unique<ast::BinaryExpr>(
252 std::move(ts_end_greater_transaction_expr),
253 std::move(ts_end_eq_zero)
258 std::unique_ptr<ast::Expr> filter_expr = std::make_unique<ast::BinaryExpr>(
260 std::move(ts_begin_filter_clause),
261 std::move(ts_end_filter_clause)
272void register_pre_optimization()
277 "adds timestamp filters to the QueryGraph");
318 if (it !=
tables_.end())
throw std::invalid_argument(
"table with that name already exists");
327 }
catch (std::out_of_range) {
__attribute__((constructor(202))) static void register_interpreter()
void apply_timestamp_filter(QueryGraph &G)
ThreadSafeStringPool::proxy_type ThreadSafePooledString
ThreadSafeStringPool::proxy_optional_type ThreadSafePooledOptionalString
bool is_unique() const
Returns true iff this Attribute is unique, i.e.
The catalog contains all Databases and keeps track of all meta information of the database system.
ThreadSafePooledString pool(const char *str) const
Creates an internalized copy of the string str by adding it to the internal StringPool.
static Catalog & Get()
Return a reference to the single Catalog instance.
std::unique_ptr< CardinalityEstimator > create_cardinality_estimator(ThreadSafePooledString database) const
Creates a new CardinalityEstimator.
void register_pre_optimization(ThreadSafePooledString name, PreOptimizationCallback optimization, const char *description=nullptr)
Registers a new pre-optimization with the given name.
const Function * get_function(const ThreadSafePooledString &name) const
Returns a reference to the Function with the given name.
const storage::DataLayout & layout() const override
Returns a reference to the physical data layout.
virtual void dump() const override
Schema schema(const ThreadSafePooledOptionalString &alias={}) const override
Returns a Schema for this Table given the alias alias.
Database(ThreadSafePooledString name)
std::unordered_map< ThreadSafePooledString, Function * > functions_
functions defined in this database
std::unordered_map< ThreadSafePooledString, std::unique_ptr< Table > > tables_
the tables of this database
const Function * get_function(const ThreadSafePooledString &name) const
Returns a reference to the Function with the given name.
Table & add_table(ThreadSafePooledString name)
Adds a new Table to this Database.
std::unique_ptr< CardinalityEstimator > cardinality_estimator_
the CardinalityEstimator of this Database
ThreadSafePooledString name
the name of the database
static constexpr const char * FNID_TO_STR_[]
static constexpr const char * KIND_TO_STR_[]
fnid_t fnid
the function id
ThreadSafePooledString name
the name of the function
void dump() const override
MultiVersioningTable(std::unique_ptr< Table > table)
Pooled< T, Pool, false > assert_not_none() const
The query graph represents all data sources and joins in a graph structure.
void add_custom_filter(std::unique_ptr< ast::Expr > filter_expr, DataSource &ds)
Creates a cnf::CNF from filter_expr and adds it to the current filter of the given DataSource ds by l...
const auto & sources() const
void transaction(Scheduler::Transaction *t)
Set the transaction ID.
An Identifier is composed of a name and an optional prefix.
static Identifier GetConstant()
Identifier(ThreadSafePooledString name)
ThreadSafePooledOptionalString prefix
optional prefix of this Identifier, may not have a value
ThreadSafePooledString name
the name of this Identifier
@ NOT_NULLABLE
entry must not be NULL
@ IS_HIDDEN
entry is hidden to the user
@ REFERENCES_UNIQUE
entry references unique values
@ UNIQUE
entry has unique values
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.
Abstract Decorator class that concrete TableDecorator inherit from.
std::unique_ptr< Table > table_
A table is a sorted set of attributes.
static Pooled< Boolean > Get_Boolean(category_t category)
Returns a Boolean type of the given category.
static Pooled< Numeric > Get_Integer(category_t category, unsigned num_bytes)
Returns a Numeric type for integrals of given category and num_bytes bytes.
This is an interface for factories that compute particular DataLayouts for a given sequence of Types,...
DataLayout make(const Schema &schema, std::size_t num_tuples=0) const
Returns a DataLayout for the given Types contained in schema and length num_tuples.