Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::JoinOrderOptimizer Class Reference
Collaboration diagram for duckdb::JoinOrderOptimizer:

Public Member Functions

 JoinOrderOptimizer (ClientContext &context)
JoinOrderOptimizer CreateChildOptimizer ()
unique_ptr< LogicalOperator > Optimize (unique_ptr< LogicalOperator > plan, optional_ptr< RelationStats > stats=nullptr)
 Perform join reordering inside a plan.
void AddMaterializedCTEStats (idx_t index, RelationStats &&stats)
 Adds/gets materialized CTE stats.
RelationStats GetMaterializedCTEStats (idx_t index)
void AddDelimScanStats (RelationStats &stats)
 Adds/gets delim scan stats.
RelationStats GetDelimScanStats ()

Public Attributes

unordered_set< idx_t > recursive_cte_indexes

Private Attributes

ClientContext & context
QueryGraphManager query_graph_manager
 manages the query graph, relations, and edges between relations
vector< unique_ptr< Expression > > filters
 The set of filters extracted from the query graph.
vector< unique_ptr< FilterInfo > > filter_infos
 The set of filter infos created from the extracted filters.
expression_map_t< vector< FilterInfo * > > equivalence_sets
CardinalityEstimator cardinality_estimator
unordered_set< std::string > join_nodes_in_full_plan
unordered_map< idx_t, RelationStats > materialized_cte_stats
 Mapping from materialized CTE index to stats.
optional_ptr< RelationStats > delim_scan_stats
 Stats of Delim Scans of the Delim Join that is currently being optimized.
idx_t depth

Constructor & Destructor Documentation

◆ JoinOrderOptimizer()

duckdb::JoinOrderOptimizer::JoinOrderOptimizer ( ClientContext & context)
explicit
311951 : context(context), query_graph_manager(context), depth(1) {
311952}
QueryGraphManager query_graph_manager
manages the query graph, relations, and edges between relations
Definition duckdb.cpp:311754

Member Function Documentation

◆ CreateChildOptimizer()

JoinOrderOptimizer duckdb::JoinOrderOptimizer::CreateChildOptimizer ( )
311954 {
311955 JoinOrderOptimizer child_optimizer(context);
311956 child_optimizer.materialized_cte_stats = materialized_cte_stats;
311957 child_optimizer.delim_scan_stats = delim_scan_stats;
311958 child_optimizer.depth = depth + 1;
311959 child_optimizer.recursive_cte_indexes = recursive_cte_indexes;
311960 return child_optimizer;
311961}
optional_ptr< RelationStats > delim_scan_stats
Stats of Delim Scans of the Delim Join that is currently being optimized.
Definition duckdb.cpp:311771
unordered_map< idx_t, RelationStats > materialized_cte_stats
Mapping from materialized CTE index to stats.
Definition duckdb.cpp:311769

◆ Optimize()

unique_ptr< LogicalOperator > duckdb::JoinOrderOptimizer::Optimize ( unique_ptr< LogicalOperator > plan,
optional_ptr< RelationStats > stats = nullptr )

Perform join reordering inside a plan.

311964 {
311965 auto max_expression_depth = Settings::Get<MaxExpressionDepthSetting>(query_graph_manager.context);
311966 if (depth > max_expression_depth) {
311967 // Very deep plans will eventually consume quite some stack space
311968 // Returning the current plan is always a valid choice
311969 return plan;
311970 }
311971
311972 // make sure query graph manager has not extracted a relation graph already
311973 LogicalOperator *op = plan.get();
311974
311975 // extract the relations that go into the hyper graph.
311976 // We optimize the children of any non-reorderable operations we come across.
311977 bool reorderable = query_graph_manager.Build(*this, *op);
311978
311979 // get relation_stats here since the reconstruction process will move all relations.
311980 auto relation_stats = query_graph_manager.relation_manager.GetRelationStats();
311981 unique_ptr<LogicalOperator> new_logical_plan = nullptr;
311982
311983 if (reorderable) {
311984 // query graph now has filters and relations
311985 auto cost_model = CostModel(query_graph_manager);
311986
311987 // Initialize a plan enumerator.
311988 auto plan_enumerator =
311989 PlanEnumerator(query_graph_manager, cost_model, query_graph_manager.GetQueryGraphEdges());
311990
311991 // Initialize the leaf/single node plans
311992 plan_enumerator.InitLeafPlans();
311993 plan_enumerator.SolveJoinOrder();
311994 // now reconstruct a logical plan from the query graph plan
311995 query_graph_manager.plans = &plan_enumerator.GetPlans();
311996
311997 new_logical_plan = query_graph_manager.Reconstruct(std::move(plan));
311998 } else {
311999 new_logical_plan = std::move(plan);
312000 if (relation_stats.size() == 1) {
312001 new_logical_plan->estimated_cardinality = relation_stats.at(0).cardinality;
312002 new_logical_plan->has_estimated_cardinality = true;
312003 }
312004 }
312005
312006 // Propagate up a stats object from the top of the new_logical_plan if stats exist.
312007 if (stats) {
312008 auto cardinality = new_logical_plan->EstimateCardinality(context);
312009 auto bindings = new_logical_plan->GetColumnBindings();
312010 auto new_stats = RelationStatisticsHelper::CombineStatsOfReorderableOperator(bindings, relation_stats);
312011 new_stats.cardinality = cardinality;
312012 RelationStatisticsHelper::CopyRelationStats(*stats, new_stats);
312013 } else {
312014 // starts recursively setting cardinality
312015 new_logical_plan->EstimateCardinality(context);
312016 }
312017
312018 if (new_logical_plan->type == LogicalOperatorType::LOGICAL_EXPLAIN) {
312019 new_logical_plan->SetEstimatedCardinality(3);
312020 }
312021
312022 return new_logical_plan;
312023}
static RelationStats CombineStatsOfReorderableOperator(vector< ColumnBinding > &bindings, vector< RelationStats > relation_stats)
Called after reordering a query plan with potentially 2+ relations.
Definition duckdb.cpp:314183
Here is the call graph for this function:

◆ AddMaterializedCTEStats()

void duckdb::JoinOrderOptimizer::AddMaterializedCTEStats ( idx_t index,
RelationStats && stats )

Adds/gets materialized CTE stats.

312025 {
312026 materialized_cte_stats.emplace(index, std::move(stats));
312027}

◆ GetMaterializedCTEStats()

RelationStats duckdb::JoinOrderOptimizer::GetMaterializedCTEStats ( idx_t index)
312029 {
312030 auto it = materialized_cte_stats.find(index);
312031 if (it == materialized_cte_stats.end()) {
312032 throw InternalException("Unable to find materialized CTE stats with index %llu", index);
312033 }
312034 return it->second;
312035}

◆ AddDelimScanStats()

void duckdb::JoinOrderOptimizer::AddDelimScanStats ( RelationStats & stats)

Adds/gets delim scan stats.

312037 {
312038 delim_scan_stats = &stats;
312039}

◆ GetDelimScanStats()

RelationStats duckdb::JoinOrderOptimizer::GetDelimScanStats ( )
312041 {
312042 if (!delim_scan_stats) {
312043 throw InternalException("Unable to find delim scan stats!");
312044 }
312045 return *delim_scan_stats;
312046}

Member Data Documentation

◆ equivalence_sets

expression_map_t<vector<FilterInfo *> > duckdb::JoinOrderOptimizer::equivalence_sets
private

A map of all expressions a given expression has to be equivalent to. This is used to add "implied join edges". i.e. in the join A=B AND B=C, the equivalence set of {B} is {A, C}, thus we can add an implied join edge {A = C}


The documentation for this class was generated from the following file: