![]() |
mutable
A Database System for Research and Fast Prototyping
|
The optimizer interface. More...
#include <Optimizer.hpp>
Public Types | |
using | Subproblem = QueryGraph::Subproblem |
using | projection_type = QueryGraph::projection_type |
using | order_type = QueryGraph::order_type |
Public Member Functions | |
Optimizer (const pe::PlanEnumerator &pe, const CostFunction &cf) | |
auto & | plan_enumerator () const |
auto & | cost_function () const |
std::unique_ptr< Producer > | operator() (QueryGraph &G) const |
Applies this optimizer to the given query graph G to compute an optimal logical operator tree. | |
std::pair< std::unique_ptr< Producer >, PlanTableEntry > | optimize (QueryGraph &G) const |
Computes and constructs an optimal logical plan for the given query graph G . | |
template<typename PlanTable > | |
std::pair< std::unique_ptr< Producer >, PlanTable > | optimize_with_plantable (QueryGraph &G) const |
Recursively computes and constructs an optimal logical plan for the given query graph G , using the given. | |
Private Member Functions | |
template<typename PlanTable > | |
std::unique_ptr< Producer *[]> | optimize_source_plans (const QueryGraph &G, PlanTable &PT) const |
Initializes the plan table PT with the data source entries contained in G . | |
template<typename PlanTable > | |
void | optimize_join_order (const QueryGraph &G, PlanTable &PT) const |
Optimizes the join order using the plan table PT which already contains entries for all data sources of the query graph G . | |
template<typename PlanTable > | |
std::unique_ptr< Producer > | construct_join_order (const QueryGraph &G, const PlanTable &PT, const std::unique_ptr< Producer *[]> &source_plans) const |
Constructs a join operator tree given a solved plan table PT and the plans to compute the data sources source_plans of the query graph G . | |
std::unique_ptr< Producer > | optimize_plan (const QueryGraph &G, std::unique_ptr< Producer > plan, PlanTableEntry &entry) const |
Optimizes and constructs an operator tree given a join operator tree plan and the final plan table entry entry for the query graph G . | |
Static Private Member Functions | |
static std::vector< cnf::CNF > | optimize_filter (cnf::CNF filter) |
Optimizes the filter filter by splitting it into smaller filters and ordering them. | |
static std::vector< projection_type > | compute_projections_required_for_order_by (const std::vector< projection_type > &projections, const std::vector< order_type > &order_by) |
Computes and returns a std::vector of additional projections required before evaluating the ORDER BY clause. | |
Private Attributes | |
const pe::PlanEnumerator & | pe_ |
const CostFunction & | cf_ |
std::vector< std::unique_ptr< const ast::Expr > > | created_exprs_ |
additionally created expressions | |
bool | needs_projection_ = false |
flag to determine whether current query needs a projection as root | |
The optimizer interface.
The Optimizer
applies a join ordering algorithm to a query graph to compute a join order that minimizes the costs under a given logical cost function. Additionally, the optimizer may apply several semantics preserving transformations to improve performance. Such transformations include query unnesting and predicate inference.
Definition at line 18 of file Optimizer.hpp.
Definition at line 22 of file Optimizer.hpp.
Definition at line 21 of file Optimizer.hpp.
Definition at line 20 of file Optimizer.hpp.
|
inline |
Definition at line 31 of file Optimizer.hpp.
|
staticprivate |
Computes and returns a std::vector
of additional projections required before evaluating the ORDER BY clause.
The returned std::vector
may be empty, in which case no additional projection is required.
Definition at line 110 of file Optimizer.cpp.
References m::and, and m::visit().
Referenced by optimize_plan().
|
private |
Constructs a join operator tree given a solved plan table PT
and the plans to compute the data sources source_plans
of the query graph G
.
Definition at line 323 of file Optimizer.cpp.
References m::SmallBitset::All(), m::and, m::SmallBitset::begin(), m::Database::cardinality_estimator(), m::Catalog::Get(), m::Catalog::get_database_in_use(), m::SmallBitset::is_subset(), m::QueryGraph::joins(), M_insist, m::SmallBitset::size(), and m::QueryGraph::sources().
Referenced by optimize_with_plantable().
|
inline |
Definition at line 34 of file Optimizer.hpp.
Referenced by optimize_join_order().
|
inline |
Applies this optimizer to the given query graph G
to compute an optimal logical operator tree.
Definition at line 37 of file Optimizer.hpp.
std::pair< std::unique_ptr< Producer >, PlanTableEntry > Optimizer::optimize | ( | QueryGraph & | G | ) | const |
Computes and constructs an optimal logical plan for the given query graph G
.
Selects a PlanTableBase
type to represent the internal state of planning progress, then delegates to optimize_with_plantable<>()
.
Definition at line 155 of file Optimizer.cpp.
References m::Options::Get(), m::QueryGraph::num_sources(), m::Options::PT_auto, m::Options::PT_LargeAndSparse, and m::Options::PT_SmallOrDense.
Referenced by optimize_source_plans().
Optimizes the filter filter
by splitting it into smaller filters and ordering them.
Definition at line 63 of file Optimizer.cpp.
References m::and, and M_insist.
Referenced by optimize_source_plans().
|
private |
Optimizes the join order using the plan table PT
which already contains entries for all data sources of the query graph G
.
Definition at line 295 of file Optimizer.cpp.
References m::QueryGraph::adjacency_matrix(), m::SmallBitset::All(), m::Database::cardinality_estimator(), cost_function(), m::AdjacencyMatrix::for_each_CSG_pair_undirected(), m::AdjacencyMatrix::for_each_CSG_undirected(), m::Catalog::Get(), m::Options::Get(), m::Catalog::get_database_in_use(), M_TIME_EXPR, m::QueryGraph::num_sources(), plan_enumerator(), and m::Catalog::timer().
Referenced by optimize_with_plantable().
|
private |
Optimizes and constructs an operator tree given a join operator tree plan
and the final plan table entry entry
for the query graph G
.
Definition at line 377 of file Optimizer.cpp.
References m::QueryGraph::aggregates(), m::SmallBitset::All(), m::and, m::Database::cardinality_estimator(), compute_projections_required_for_order_by(), m::ast::Token::CreateArtificial(), created_exprs_, m::Catalog::Get(), m::Catalog::get_database_in_use(), m::QueryGraph::group_by(), m::QueryGraph::limit, m::PlanTableEntry::model, needs_projection_, m::QueryGraph::order_by(), m::QueryGraph::projections(), and m::QueryGraph::sources().
Referenced by optimize_with_plantable().
|
private |
Initializes the plan table PT
with the data source entries contained in G
.
Returns the (potentially recursively optimized) logical plan for each data source.
Definition at line 213 of file Optimizer.cpp.
References m::Schema::add(), m::and, m::Database::cardinality_estimator(), m::Catalog::Get(), m::Catalog::get_database_in_use(), m::Operator::info(), M_insist, needs_projection_, optimize(), optimize_filter(), m::SmallBitset::Singleton(), and m::QueryGraph::sources().
Referenced by optimize_with_plantable().
std::pair< std::unique_ptr< Producer >, PlanTable > Optimizer::optimize_with_plantable | ( | QueryGraph & | G | ) | const |
Recursively computes and constructs an optimal logical plan for the given query graph G
, using the given.
PlanTable | type to represent the state of planning progress. |
Definition at line 185 of file Optimizer.cpp.
References construct_join_order(), m::Catalog::Get(), optimize_join_order(), optimize_plan(), optimize_source_plans(), m::QueryGraph::projections(), and m::QueryGraph::sources().
Referenced by m::execute_statement().
|
inline |
Definition at line 33 of file Optimizer.hpp.
Referenced by optimize_join_order().
|
private |
Definition at line 26 of file Optimizer.hpp.
|
mutableprivate |
additionally created expressions
Definition at line 27 of file Optimizer.hpp.
Referenced by optimize_plan().
|
mutableprivate |
flag to determine whether current query needs a projection as root
Definition at line 28 of file Optimizer.hpp.
Referenced by optimize_plan(), and optimize_source_plans().
|
private |
Definition at line 25 of file Optimizer.hpp.