mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
QueryGraph.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "util/hash.hpp"
6#include <unordered_map>
7#include <unordered_set>
8#include <utility>
9
10
11namespace m {
12
13struct GraphBuilder;
14
18{
20 std::unique_ptr<GraphBuilder> builder;
22
23 SubqueryInfo(const ast::QueryExpr &expr, std::unique_ptr<GraphBuilder> builder, ThreadSafePooledString alias)
24 : expr(expr)
25 , builder(std::move(builder))
26 , alias(std::move(alias))
27 { }
28};
29
32{
33 unsigned binding_depth = 0;
34
35 std::unordered_set<ThreadSafePooledString> data_sources;
36 std::vector<SubqueryInfo> nested_queries;
37
38 ClauseInfo(const cnf::Clause &clause);
39
40 bool is_constant() const { return data_sources.empty(); }
41 bool is_selection() const { return data_sources.size() == 1; }
42};
43
44struct GraphBuilder : ast::ConstASTCommandVisitor
45{
47 using clause_map = std::unordered_map<cnf::Clause, ClauseInfo>;
48
49 private:
50 /*----- Fields tracking correlation information -----*/
52 std::vector<std::reference_wrapper<const ast::Expr>> existing_grouping_keys_;
54 std::unordered_set<std::reference_wrapper<const ast::Expr>> additional_grouping_keys_;
55
60
62 std::unique_ptr<QueryGraph> graph_;
64 std::unordered_map<ThreadSafePooledString, std::reference_wrapper<DataSource>> named_sources_;
66 bool needs_grouping_ = false;
67
68 public:
70
72 std::unique_ptr<QueryGraph> get() { return std::move(graph_); }
73
74 /*----- Visitor methods -----*/
75 using ConstASTCommandVisitor::operator();
76 void operator()(Const<ast::Stmt> &s) { s.accept(*this); }
77 void operator()(Const<ast::ErrorStmt>&) { M_unreachable("graph must not contain errors"); }
78 void operator()(Const<ast::EmptyStmt>&) { /* nothing to be done */ }
79 void operator()(Const<ast::CreateDatabaseStmt>&) { M_unreachable("not implemented"); }
80 void operator()(Const<ast::DropDatabaseStmt>&) { M_unreachable("not implemented"); }
81 void operator()(Const<ast::UseDatabaseStmt>&) { M_unreachable("not implemented"); }
82 void operator()(Const<ast::CreateTableStmt>&) { M_unreachable("not implemented"); }
83 void operator()(Const<ast::DropTableStmt>&) { M_unreachable("not implemented"); }
84 void operator()(Const<ast::SelectStmt> &s);
85 void operator()(Const<ast::InsertStmt>&) { M_unreachable("not implemented"); }
86 void operator()(Const<ast::UpdateStmt>&) { M_unreachable("not implemented"); }
87 void operator()(Const<ast::DeleteStmt>&) { M_unreachable("not implemented"); }
88 void operator()(Const<ast::DSVImportStmt>&) { M_unreachable("not implemented"); }
89
107 void process_selection(cnf::Clause &clause);
108};
109
110}
#define M_unreachable(MSG)
Definition: macro.hpp:146
‍mutable namespace
Definition: Backend.hpp:10
ThreadSafeStringPool::proxy_type ThreadSafePooledString
Definition: Pool.hpp:464
STL namespace.
Collects information of a cnf::Clause.
Definition: QueryGraph.hpp:32
std::unordered_set< ThreadSafePooledString > data_sources
Definition: QueryGraph.hpp:35
bool is_selection() const
Definition: QueryGraph.hpp:41
std::vector< SubqueryInfo > nested_queries
Definition: QueryGraph.hpp:36
bool is_constant() const
Definition: QueryGraph.hpp:40
unsigned binding_depth
Definition: QueryGraph.hpp:33
void operator()(Const< ast::UseDatabaseStmt > &)
Definition: QueryGraph.hpp:81
void operator()(Const< ast::UpdateStmt > &)
Definition: QueryGraph.hpp:86
void operator()(Const< ast::EmptyStmt > &)
Definition: QueryGraph.hpp:78
std::unique_ptr< QueryGraph > graph_
‍the query graph that is being constructed
Definition: QueryGraph.hpp:62
void operator()(Const< ast::CreateTableStmt > &)
Definition: QueryGraph.hpp:82
std::unordered_map< ThreadSafePooledString, std::reference_wrapper< DataSource > > named_sources_
‍maps DataSource names/aliases to the DataSource instance
Definition: QueryGraph.hpp:64
void operator()(Const< ast::CreateDatabaseStmt > &)
Definition: QueryGraph.hpp:79
void operator()(Const< ast::DeleteStmt > &)
Definition: QueryGraph.hpp:87
void operator()(Const< ast::InsertStmt > &)
Definition: QueryGraph.hpp:85
clause_map deferred_clauses_
‍to be handled by an outer query
Definition: QueryGraph.hpp:59
void operator()(Const< ast::ErrorStmt > &)
Definition: QueryGraph.hpp:77
std::vector< std::reference_wrapper< const ast::Expr > > existing_grouping_keys_
‍the grouping keys of the statement
Definition: QueryGraph.hpp:52
void operator()(Const< ast::Stmt > &s)
Definition: QueryGraph.hpp:76
std::unordered_set< std::reference_wrapper< const ast::Expr > > additional_grouping_keys_
‍additionally required grouping keys to perform decorrelation
Definition: QueryGraph.hpp:54
void operator()(Const< ast::DropDatabaseStmt > &)
Definition: QueryGraph.hpp:80
clause_map bound_clauses_
‍to be handled by the current query
Definition: QueryGraph.hpp:57
bool needs_grouping_
‍whether this graph needs grouping; either by explicily grouping or implicitly by using aggregations
Definition: QueryGraph.hpp:66
void operator()(Const< ast::DSVImportStmt > &)
Definition: QueryGraph.hpp:88
std::unordered_map< cnf::Clause, ClauseInfo > clause_map
‍maps a cnf::Clause to its ClauseInfo
Definition: QueryGraph.hpp:47
std::unique_ptr< QueryGraph > get()
‍returns the constructed QueryGraph
Definition: QueryGraph.hpp:72
void operator()(Const< ast::DropTableStmt > &)
Definition: QueryGraph.hpp:83
void operator()(Const< ast::SelectStmt > &s)
void process_selection(cnf::Clause &clause)
Computes correlation information of clause.
Definition: QueryGraph.cpp:440
Collects info of a subquery, i.e.
Definition: QueryGraph.hpp:18
const ast::QueryExpr & expr
Definition: QueryGraph.hpp:19
ThreadSafePooledString alias
Definition: QueryGraph.hpp:21
std::unique_ptr< GraphBuilder > builder
Definition: QueryGraph.hpp:20
SubqueryInfo(const ast::QueryExpr &expr, std::unique_ptr< GraphBuilder > builder, ThreadSafePooledString alias)
Definition: QueryGraph.hpp:23
A query expression for nested queries.
Definition: AST.hpp:389
A cnf::Clause represents a disjunction of Predicates.
Definition: CNF.hpp:87