mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
m::Optimizer Struct Reference

The optimizer interface. More...

#include <Optimizer.hpp>

Collaboration diagram for m::Optimizer:
[legend]

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< Produceroperator() (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 >, PlanTableEntryoptimize (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< Producerconstruct_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< Produceroptimize_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::CNFoptimize_filter (cnf::CNF filter)
 Optimizes the filter filter by splitting it into smaller filters and ordering them.
 
static std::vector< projection_typecompute_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::PlanEnumeratorpe_
 
const CostFunctioncf_
 
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
 

Detailed Description

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.

Member Typedef Documentation

◆ order_type

Definition at line 22 of file Optimizer.hpp.

◆ projection_type

Definition at line 21 of file Optimizer.hpp.

◆ Subproblem

Definition at line 20 of file Optimizer.hpp.

Constructor & Destructor Documentation

◆ Optimizer()

m::Optimizer::Optimizer ( const pe::PlanEnumerator pe,
const CostFunction cf 
)
inline

Definition at line 31 of file Optimizer.hpp.

Member Function Documentation

◆ compute_projections_required_for_order_by()

std::vector< Optimizer::projection_type > Optimizer::compute_projections_required_for_order_by ( const std::vector< projection_type > &  projections,
const std::vector< order_type > &  order_by 
)
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().

◆ construct_join_order()

template<typename PlanTable >
std::unique_ptr< Producer > Optimizer::construct_join_order ( const QueryGraph G,
const PlanTable &  PT,
const std::unique_ptr< Producer *[]> &  source_plans 
) const
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().

◆ cost_function()

auto & m::Optimizer::cost_function ( ) const
inline

Definition at line 34 of file Optimizer.hpp.

Referenced by optimize_join_order().

◆ operator()()

std::unique_ptr< Producer > m::Optimizer::operator() ( QueryGraph G) const
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.

◆ optimize()

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().

◆ optimize_filter()

std::vector< cnf::CNF > Optimizer::optimize_filter ( cnf::CNF  filter)
staticprivate

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().

◆ optimize_join_order()

template<typename PlanTable >
void Optimizer::optimize_join_order ( const QueryGraph G,
PlanTable &  PT 
) const
private

◆ optimize_plan()

std::unique_ptr< Producer > Optimizer::optimize_plan ( const QueryGraph G,
std::unique_ptr< Producer plan,
PlanTableEntry entry 
) const
private

◆ optimize_source_plans()

template<typename PlanTable >
std::unique_ptr< Producer *[]> Optimizer::optimize_source_plans ( const QueryGraph G,
PlanTable &  PT 
) const
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().

◆ optimize_with_plantable()

template<typename 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.

Template Parameters
PlanTabletype 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().

◆ plan_enumerator()

auto & m::Optimizer::plan_enumerator ( ) const
inline

Definition at line 33 of file Optimizer.hpp.

Referenced by optimize_join_order().

Field Documentation

◆ cf_

const CostFunction& m::Optimizer::cf_
private

Definition at line 26 of file Optimizer.hpp.

◆ created_exprs_

std::vector<std::unique_ptr<const ast::Expr> > m::Optimizer::created_exprs_
mutableprivate

additionally created expressions

Definition at line 27 of file Optimizer.hpp.

Referenced by optimize_plan().

◆ needs_projection_

bool m::Optimizer::needs_projection_ = false
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().

◆ pe_

const pe::PlanEnumerator& m::Optimizer::pe_
private

Definition at line 25 of file Optimizer.hpp.


The documentation for this struct was generated from the following files: