![]() |
mutable
A Database System for Research and Fast Prototyping
|
The query graph represents all data sources and joins in a graph structure. More...
#include <QueryGraph.hpp>
Public Types | |
using | Subproblem = SmallBitset |
encode QueryGraph::Subproblem s as SmallBitset s | |
using | projection_type = std::pair< std::reference_wrapper< const ast::Expr >, ThreadSafePooledOptionalString > |
using | order_type = std::pair< std::reference_wrapper< const ast::Expr >, bool > |
true means ascending, false means descending | |
using | group_type = std::pair< std::reference_wrapper< const ast::Expr >, ThreadSafePooledOptionalString > |
Public Member Functions | |
QueryGraph () | |
~QueryGraph () | |
QueryGraph (const QueryGraph &)=delete | |
QueryGraph (QueryGraph &&other) | |
QueryGraph & | operator= (QueryGraph &&other) |
std::size_t | num_sources () const |
Returns the number of DataSource s in this graph. | |
std::size_t | num_joins () const |
Returns the number of Join s in this graph. | |
void | add_source (std::unique_ptr< DataSource > source) |
BaseTable & | add_source (ThreadSafePooledOptionalString alias, const Table &table) |
Query & | add_source (ThreadSafePooledOptionalString alias, std::unique_ptr< QueryGraph > query_graph) |
std::unique_ptr< DataSource > | remove_source (std::size_t id) |
const auto & | sources () const |
const auto & | joins () const |
const auto & | group_by () const |
const auto & | aggregates () const |
const std::vector< projection_type > & | projections () const |
const auto & | order_by () const |
auto | limit () const |
const DataSource & | operator[] (uint64_t id) const |
Returns a data souce given its id. | |
bool | grouping () const |
Returns true iff the graph contains a grouping. | |
bool | is_correlated () const |
Returns true iff the graph is correlated, i.e. | |
AdjacencyMatrix & | adjacency_matrix () |
const AdjacencyMatrix & | adjacency_matrix () const |
void | dot (std::ostream &out) const |
Translates the query graph to dot. | |
void | sql (std::ostream &out) const |
Translates the query graph to SQL. | |
void | transaction (Scheduler::Transaction *t) |
Set the transaction ID. | |
Scheduler::Transaction * | transaction () const |
Returns the transaction ID. | |
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 logical conjunction. | |
void | dump (std::ostream &out) const |
void | dump () const |
Static Public Member Functions | |
static std::unique_ptr< QueryGraph > | Build (const ast::Stmt &stmt) |
Private Member Functions | |
void | compute_adjacency_matrix () const |
void | dot_recursive (std::ostream &out) const |
void | remove_join (Join &join) |
Private Attributes | |
std::vector< std::unique_ptr< DataSource > > | sources_ |
collection of all data sources in this query graph | |
std::vector< std::unique_ptr< Join > > | joins_ |
collection of all joins in this query graph | |
std::vector< group_type > | group_by_ |
the grouping keys | |
std::vector< std::reference_wrapper< const ast::FnApplicationExpr > > | aggregates_ |
the aggregates to compute | |
std::vector< projection_type > | projections_ |
the data to compute | |
std::vector< order_type > | order_by_ |
the order | |
struct { | |
uint64_t limit = 0 | |
uint64_t offset = 0 | |
} | limit_ |
limit: limit and offset | |
std::unique_ptr< AdjacencyMatrix > | adjacency_matrix_ |
Scheduler::Transaction * | t_ = nullptr |
the transaction this query graph belongs to | |
std::vector< std::unique_ptr< ast::Expr > > | custom_filter_exprs_ |
| |
Friends | |
struct | GraphBuilder |
struct | Decorrelation |
struct | GetPrimaryKey |
void | swap (QueryGraph &first, QueryGraph &second) |
The query graph represents all data sources and joins in a graph structure.
It is used as an intermediate representation of a query.
Definition at line 171 of file QueryGraph.hpp.
using m::QueryGraph::group_type = std::pair<std::reference_wrapper<const ast::Expr>, ThreadSafePooledOptionalString> |
Definition at line 180 of file QueryGraph.hpp.
using m::QueryGraph::order_type = std::pair<std::reference_wrapper<const ast::Expr>, bool> |
true means ascending, false means descending
Definition at line 179 of file QueryGraph.hpp.
using m::QueryGraph::projection_type = std::pair<std::reference_wrapper<const ast::Expr>, ThreadSafePooledOptionalString> |
Definition at line 178 of file QueryGraph.hpp.
using m::QueryGraph::Subproblem = SmallBitset |
encode QueryGraph::Subproblem
s as SmallBitset
s
Definition at line 177 of file QueryGraph.hpp.
QueryGraph::QueryGraph | ( | ) |
Definition at line 1894 of file QueryGraph.cpp.
QueryGraph::~QueryGraph | ( | ) |
Definition at line 1896 of file QueryGraph.cpp.
|
delete |
|
inline |
Definition at line 217 of file QueryGraph.hpp.
References m::swap().
|
inline |
Creates a cnf::CNF
from filter_expr
and adds it to the current filter of the given DataSource
ds
by logical conjunction.
Definition at line 308 of file QueryGraph.hpp.
References M_insist, and m::DataSource::update_filter().
Referenced by M_LCOV_EXCL_STOP::apply_timestamp_filter().
|
inline |
Definition at line 229 of file QueryGraph.hpp.
|
inline |
Definition at line 233 of file QueryGraph.hpp.
|
inline |
Definition at line 238 of file QueryGraph.hpp.
|
inline |
Definition at line 277 of file QueryGraph.hpp.
Referenced by generate_correlated_cardinalities(), generate_uncorrelated_cardinalities(), m::pe::hs::HeuristicSearch::operator()(), m::pe::DPccp::operator()(), m::pe::GOO::operator()(), m::pe::TDGOO::operator()(), DPsize::operator()(), DPsizeOpt::operator()(), DPsizeSub::operator()(), DPsub::operator()(), DPsubOpt::operator()(), IKKBZ::operator()(), LinearizedDP::operator()(), TDbasic::operator()(), TDMinCutAGaT::operator()(), and m::Optimizer::optimize_join_order().
|
inline |
Definition at line 283 of file QueryGraph.hpp.
|
inline |
Definition at line 260 of file QueryGraph.hpp.
Referenced by dump(), and m::Optimizer::optimize_plan().
|
static |
Definition at line 1898 of file QueryGraph.cpp.
References m::GraphBuilder::get().
Referenced by m::QueryDatabase::execute(), m::execute_statement(), m::logical_plan_from_statement(), and main().
|
private |
Definition at line 1915 of file QueryGraph.cpp.
References adjacency_matrix_, joins(), and num_sources().
void QueryGraph::dot | ( | std::ostream & | out | ) | const |
Translates the query graph to dot.
Definition at line 1930 of file QueryGraph.cpp.
References dot_recursive().
|
private |
Definition at line 1946 of file QueryGraph.cpp.
References aggregates_, m::and, group_by_, m::html_escape(), id, joins(), limit_, order_by_, projections_, q, sources(), and m::to_string().
Referenced by dot().
void QueryGraph::dump | ( | ) | const |
M_LCOV_EXCL_START void QueryGraph::dump | ( | std::ostream & | out | ) | const |
Definition at line 2050 of file QueryGraph.cpp.
References aggregates(), m::and, group_by(), joins(), order_by(), projections(), q, and sources().
|
inline |
Definition at line 259 of file QueryGraph.hpp.
Referenced by dump(), m::Optimizer::optimize_plan(), and m::QueryGraph2SQL::translate().
|
inline |
Returns true
iff the graph contains a grouping.
Definition at line 273 of file QueryGraph.hpp.
bool QueryGraph::is_correlated | ( | ) | const |
Returns true
iff the graph is correlated, i.e.
it contains a correlated source.
Definition at line 1905 of file QueryGraph.cpp.
|
inline |
Definition at line 258 of file QueryGraph.hpp.
Referenced by compute_adjacency_matrix(), m::pe::hs::search_states::EdgesBottomUp::compute_datasource_to_subproblem_index(), m::pe::hs::search_states::EdgePtrBottomUp::compute_datasource_to_subproblem_index(), m::Optimizer::construct_join_order(), dot_recursive(), dump(), emit_query_slice(), generate_uncorrelated_cardinalities(), m::pe::hs::expansions::BottomUpComplete::operator()(), and m::QueryGraph2SQL::translate().
|
inline |
Definition at line 263 of file QueryGraph.hpp.
|
inline |
Returns the number of Join
s in this graph.
Definition at line 227 of file QueryGraph.hpp.
Referenced by generate_uncorrelated_cardinalities(), and m::pe::hs::expansions::BottomUpComplete::operator()().
|
inline |
Returns the number of DataSource
s in this graph.
Definition at line 224 of file QueryGraph.hpp.
Referenced by m::pe::hs::search_states::SubproblemsArray::Bottom(), compute_adjacency_matrix(), m::pe::hs::search_states::EdgesBottomUp::compute_datasource_to_subproblem_index(), m::pe::hs::search_states::EdgePtrBottomUp::compute_datasource_to_subproblem_index(), m::pe::hs::search_states::EdgesBottomUp::CreateInitial(), m::pe::TDGOO::for_each_join(), m::pe::hs::search_states::EdgesBottomUp::for_each_subproblem(), m::pe::hs::search_states::EdgePtrBottomUp::for_each_subproblem(), generate_correlated_cardinalities(), generate_uncorrelated_cardinalities(), m::pe::hs::goo_path_completion(), m::pe::hs::heuristic_search(), m::pe::hs::search_states::SubproblemsArray::is_bottom(), m::pe::hs::search_states::EdgePtrBottomUp::is_goal(), IKKBZ::linearize(), m::pe::hs::search_states::EdgePtrBottomUp::num_joins_remaining(), m::pe::hs::search_states::SubproblemsArray::num_partitions(), m::pe::hs::search_states::SubproblemTableBottomUp::num_partitions(), m::pe::hs::search_states::EdgesBottomUp::num_subproblems(), m::pe::hs::heuristics::avg_sel< PlanTable, State, BottomUp >::operator()(), m::pe::hs::heuristics::scaled_sum< PlanTable, State, BottomUp >::operator()(), m::pe::hs::heuristics::GOO< PlanTable, State, BottomUp >::operator()(), m::pe::hs::heuristics::GOO< PlanTable, State, TopDown >::operator()(), m::pe::hs::expansions::BottomUpComplete::operator()(), m::pe::hs::expansions::TopDownComplete::operator()(), m::pe::DPccp::operator()(), m::pe::GOO::operator()(), m::pe::TDGOO::operator()(), IKKBZ::operator()(), LinearizedDP::operator()(), TDMinCutAGaT::operator()(), m::Optimizer::optimize(), m::Optimizer::optimize_join_order(), m::pe::hs::expansions::TopDown::reset_marked(), m::pe::hs::search_states::SubproblemsArray::SubproblemsArray(), m::pe::hs::search_states::SubproblemTableBottomUp::SubproblemTableBottomUp(), and m::pe::hs::search_states::SubproblemsArray::Top().
|
inline |
Definition at line 219 of file QueryGraph.hpp.
References m::swap().
|
inline |
Returns a data souce given its id.
Definition at line 266 of file QueryGraph.hpp.
|
inline |
Definition at line 262 of file QueryGraph.hpp.
Referenced by dump(), m::Optimizer::optimize_plan(), and m::QueryGraph2SQL::translate().
|
inline |
Definition at line 261 of file QueryGraph.hpp.
Referenced by dump(), m::Optimizer::optimize_plan(), m::Optimizer::optimize_with_plantable(), and m::QueryGraph2SQL::translate().
|
inlineprivate |
Definition at line 326 of file QueryGraph.hpp.
|
inline |
Definition at line 244 of file QueryGraph.hpp.
References M_insist.
|
inline |
Definition at line 257 of file QueryGraph.hpp.
Referenced by M_LCOV_EXCL_STOP::apply_timestamp_filter(), m::Optimizer::construct_join_order(), dot_recursive(), dump(), emit_cardinalities(), emit_query_slice(), m::CartesianProductEstimator::estimate_scan(), m::InjectionCardinalityEstimator::estimate_scan(), m::SpnEstimator::estimate_scan(), m::InjectionCardinalityEstimator::make_identifier(), PEall::operator()(), DPsize::operator()(), DPsizeOpt::operator()(), DPsizeSub::operator()(), DPsub::operator()(), DPsubOpt::operator()(), TDbasic::operator()(), m::Optimizer::optimize_plan(), m::Optimizer::optimize_source_plans(), m::Optimizer::optimize_with_plantable(), m::QueryGraph2SQL::translate(), and m::PartialPlanGenerator::write_partial_plans_JSON().
void QueryGraph::sql | ( | std::ostream & | out | ) | const |
Translates the query graph to SQL.
Definition at line 2042 of file QueryGraph.cpp.
|
inline |
Returns the transaction ID.
Definition at line 305 of file QueryGraph.hpp.
|
inline |
Set the transaction ID.
Definition at line 296 of file QueryGraph.hpp.
References M_insist.
Referenced by M_LCOV_EXCL_STOP::apply_timestamp_filter().
|
friend |
Definition at line 174 of file QueryGraph.hpp.
|
friend |
Definition at line 175 of file QueryGraph.hpp.
|
friend |
Definition at line 173 of file QueryGraph.hpp.
|
friend |
Definition at line 199 of file QueryGraph.hpp.
|
mutableprivate |
Definition at line 192 of file QueryGraph.hpp.
Referenced by compute_adjacency_matrix().
|
private |
the aggregates to compute
Definition at line 187 of file QueryGraph.hpp.
Referenced by dot_recursive().
|
private |
Stores the expressions of custom filters that have been added to the
DataSource
s after semantic analysis.
Definition at line 196 of file QueryGraph.hpp.
|
private |
|
private |
collection of all joins in this query graph
Definition at line 184 of file QueryGraph.hpp.
uint64_t m::QueryGraph::limit = 0 |
Definition at line 190 of file QueryGraph.hpp.
Referenced by m::Optimizer::optimize_plan(), and m::QueryGraph2SQL::translate().
struct { ... } m::QueryGraph::limit_ |
limit: limit and offset
Referenced by dot_recursive().
uint64_t m::QueryGraph::offset = 0 |
Definition at line 190 of file QueryGraph.hpp.
|
private |
|
private |
|
private |
collection of all data sources in this query graph
Definition at line 183 of file QueryGraph.hpp.
|
private |
the transaction this query graph belongs to
Definition at line 194 of file QueryGraph.hpp.