mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Optimizer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <mutable/mutable-config.hpp>
7
8
9namespace m {
10
18struct M_EXPORT Optimizer
19{
23
24 private:
27 mutable std::vector<std::unique_ptr<const ast::Expr>> created_exprs_;
28 mutable bool needs_projection_ = false;
29
30 public:
31 Optimizer(const pe::PlanEnumerator &pe, const CostFunction &cf) : pe_(pe), cf_(cf) { }
32
33 auto & plan_enumerator() const { return pe_; }
34 auto & cost_function() const { return cf_; }
35
37 std::unique_ptr<Producer> operator()(QueryGraph &G) const { return optimize(G).first; }
38
41 std::pair<std::unique_ptr<Producer>, PlanTableEntry> optimize(QueryGraph &G) const;
42
45 template<typename PlanTable>
46 std::pair<std::unique_ptr<Producer>, PlanTable> optimize_with_plantable(QueryGraph &G) const;
47
48 private:
51 template<typename PlanTable>
52 std::unique_ptr<Producer*[]> optimize_source_plans(const QueryGraph &G, PlanTable &PT) const;
53
56 template<typename PlanTable>
57 void optimize_join_order(const QueryGraph &G, PlanTable &PT) const;
58
61 template<typename PlanTable>
62 std::unique_ptr<Producer> construct_join_order(const QueryGraph &G, const PlanTable &PT,
63 const std::unique_ptr<Producer*[]> &source_plans) const;
64
67 std::unique_ptr<Producer> optimize_plan(const QueryGraph &G, std::unique_ptr<Producer> plan,
68 PlanTableEntry &entry) const;
69
71 static std::vector<cnf::CNF> optimize_filter(cnf::CNF filter);
72
75 static std::vector<projection_type>
76 compute_projections_required_for_order_by(const std::vector<projection_type> &projections,
77 const std::vector<order_type> &order_by);
78};
79
80}
‍mutable namespace
Definition: Backend.hpp:10
The optimizer interface.
Definition: Optimizer.hpp:19
QueryGraph::order_type order_type
Definition: Optimizer.hpp:22
Optimizer(const pe::PlanEnumerator &pe, const CostFunction &cf)
Definition: Optimizer.hpp:31
const CostFunction & cf_
Definition: Optimizer.hpp:26
auto & plan_enumerator() const
Definition: Optimizer.hpp:33
std::unique_ptr< Producer > operator()(QueryGraph &G) const
Applies this optimizer to the given query graph G to compute an optimal logical operator tree.
Definition: Optimizer.hpp:37
auto & cost_function() const
Definition: Optimizer.hpp:34
QueryGraph::projection_type projection_type
Definition: Optimizer.hpp:21
std::vector< std::unique_ptr< const ast::Expr > > created_exprs_
additionally created expressions
Definition: Optimizer.hpp:27
const pe::PlanEnumerator & pe_
Definition: Optimizer.hpp:25
A Producer is an Operator that can be evaluated to a sequence of tuples.
Definition: Operator.hpp:120
The query graph represents all data sources and joins in a graph structure.
Definition: QueryGraph.hpp:172
std::pair< std::reference_wrapper< const ast::Expr >, ThreadSafePooledOptionalString > projection_type
Definition: QueryGraph.hpp:178
std::pair< std::reference_wrapper< const ast::Expr >, bool > order_type
true means ascending, false means descending
Definition: QueryGraph.hpp:179
Implements a small and efficient set over integers in the range of 0 to 63 (including).
Definition: ADT.hpp:26
A CNF represents a conjunction of cnf::Clauses.
Definition: CNF.hpp:134
An interface for all plan enumerators.