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::PlanEnumerator Class Reference
Collaboration diagram for duckdb::PlanEnumerator:

Public Member Functions

 PlanEnumerator (QueryGraphManager &query_graph_manager, CostModel &cost_model, const QueryGraphEdges &query_graph)
void SolveJoinOrder ()
 Perform the join order solving.
void InitLeafPlans ()
const reference_map_t< JoinRelationSet, unique_ptr< DPJoinNode > > & GetPlans () const

Static Public Attributes

static constexpr idx_t THRESHOLD_TO_SWAP_TO_APPROXIMATE = 12

Private Member Functions

unique_ptr< DPJoinNode > CreateJoinTree (JoinRelationSet &set, const vector< reference< NeighborInfo > > &possible_connections, DPJoinNode &left, DPJoinNode &right)
 Create a new JoinTree node by joining together two previous JoinTree nodes.
DPJoinNode & EmitPair (JoinRelationSet &left, JoinRelationSet &right, const vector< reference< NeighborInfo > > &info)
bool TryEmitPair (JoinRelationSet &left, JoinRelationSet &right, const vector< reference< NeighborInfo > > &info)
bool EnumerateCmpRecursive (JoinRelationSet &left, JoinRelationSet &right, unordered_set< idx_t > &exclusion_set)
bool EmitCSG (JoinRelationSet &node)
 Emit a relation set node.
bool EnumerateCSGRecursive (JoinRelationSet &node, unordered_set< idx_t > &exclusion_set)
 Enumerate the possible connected subgraphs that can be joined together in the join graph.
void GenerateCrossProducts ()
 Generate cross product edges inside the side.
bool SolveJoinOrderExactly ()
void SolveJoinOrderApproximately ()
 Solve the join order approximately using a greedy algorithm.

Private Attributes

QueryGraphEdges const & query_graph
 The set of edges used in the join optimizer.
idx_t pairs = 0
 The total amount of join pairs that have been considered.
QueryGraphManager & query_graph_manager
 Grant access to the set manager and the relation manager.
CostModel & cost_model
 Cost model to evaluate cost of joins.
reference_map_t< JoinRelationSet, unique_ptr< DPJoinNode > > plans
 A map to store the optimal join plan found for a specific JoinRelationSet*.
unordered_set< string > join_nodes_in_full_plan

Constructor & Destructor Documentation

◆ PlanEnumerator()

duckdb::PlanEnumerator::PlanEnumerator ( QueryGraphManager & query_graph_manager,
CostModel & cost_model,
const QueryGraphEdges & query_graph )
inlineexplicit
311892 }
QueryGraphEdges const & query_graph
The set of edges used in the join optimizer.
Definition duckdb.cpp:311904
CostModel & cost_model
Cost model to evaluate cost of joins.
Definition duckdb.cpp:311910
QueryGraphManager & query_graph_manager
Grant access to the set manager and the relation manager.
Definition duckdb.cpp:311908

Member Function Documentation

◆ SolveJoinOrder()

void duckdb::PlanEnumerator::SolveJoinOrder ( )

Perform the join order solving.

solve the join order again, returning the final plan

312686 {
312687 bool force_no_cross_product = Settings::Get<DebugForceNoCrossProductSetting>(query_graph_manager.context);
312688 // first try to solve the join order exactly
312689 if (query_graph_manager.relation_manager.NumRelations() >= THRESHOLD_TO_SWAP_TO_APPROXIMATE) {
312691 } else if (!SolveJoinOrderExactly()) {
312692 // otherwise, if that times out we resort to a greedy algorithm
312694 }
312695
312696 // now the optimal join path should have been found
312697 // get it from the node
312698 unordered_set<idx_t> bindings;
312699 for (idx_t i = 0; i < query_graph_manager.relation_manager.NumRelations(); i++) {
312700 bindings.insert(i);
312701 }
312702 auto &total_relation = query_graph_manager.set_manager.GetJoinRelation(bindings);
312703 auto final_plan = plans.find(total_relation);
312704 if (final_plan == plans.end()) {
312705 // could not find the final plan
312706 // this should only happen in case the sets are actually disjunct
312707 // in this case we need to generate cross product to connect the disjoint sets
312708 if (force_no_cross_product) {
312709 throw InvalidInputException(
312710 "Query requires a cross-product, but 'force_no_cross_product' PRAGMA is enabled");
312711 }
312714 return SolveJoinOrder();
312715 }
312716}
void SolveJoinOrder()
Perform the join order solving.
Definition duckdb.cpp:312686
reference_map_t< JoinRelationSet, unique_ptr< DPJoinNode > > plans
A map to store the optimal join plan found for a specific JoinRelationSet*.
Definition duckdb.cpp:311912
void GenerateCrossProducts()
Generate cross product edges inside the side.
Definition duckdb.cpp:312292
bool SolveJoinOrderExactly()
Definition duckdb.cpp:312532
void SolveJoinOrderApproximately()
Solve the join order approximately using a greedy algorithm.
Definition duckdb.cpp:312555
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitLeafPlans()

void duckdb::PlanEnumerator::InitLeafPlans ( )
312660 {
312661 // First we initialize each of the single-node plans with themselves and with their cardinalities these are the leaf
312662 // nodes of the join tree NOTE: we can just use pointers to JoinRelationSet* here because the GetJoinRelation
312663 // function ensures that a unique combination of relations will have a unique JoinRelationSet object.
312664 // first initialize equivalent relations based on the filters
312665 auto relation_stats = query_graph_manager.relation_manager.GetRelationStats();
312666
312667 cost_model.cardinality_estimator.InitEquivalentRelations(query_graph_manager.GetFilterBindings());
312668 cost_model.cardinality_estimator.AddRelationNamesToRelationStats(relation_stats);
312669
312670 // then update the total domains based on the cardinalities of each relation.
312671 for (idx_t i = 0; i < relation_stats.size(); i++) {
312672 auto stats = relation_stats.at(i);
312673 auto &relation_set = query_graph_manager.set_manager.GetJoinRelation(i);
312674 auto join_node = make_uniq<DPJoinNode>(relation_set);
312675 join_node->cost = 0;
312676 join_node->cardinality = stats.cardinality;
312677 D_ASSERT(join_node->set.count == 1);
312678 plans[relation_set] = std::move(join_node);
312679 cost_model.cardinality_estimator.InitCardinalityEstimatorProps(&relation_set, stats);
312680 }
312681}

◆ GetPlans()

const reference_map_t< JoinRelationSet, unique_ptr< DPJoinNode > > & duckdb::PlanEnumerator::GetPlans ( ) const
312311 {
312312 return plans;
312313}

◆ CreateJoinTree()

unique_ptr< DPJoinNode > duckdb::PlanEnumerator::CreateJoinTree ( JoinRelationSet & set,
const vector< reference< NeighborInfo > > & possible_connections,
DPJoinNode & left,
DPJoinNode & right )
private

Create a new JoinTree node by joining together two previous JoinTree nodes.

312318 {
312319 // FIXME: should consider different join algorithms, should we pick a join algorithm here as well? (probably)
312320 optional_ptr<NeighborInfo> best_connection = possible_connections.back().get();
312321 // cross products are technically still connections, but the filter expression is a null_ptr
312322 bool found_non_cross_product_connection = false;
312323 for (auto &connection : possible_connections) {
312324 for (auto &filter : connection.get().filters) {
312325 if (filter->join_type != JoinType::INVALID) {
312326 best_connection = connection.get();
312327 found_non_cross_product_connection = true;
312328 break;
312329 }
312330 }
312331 if (found_non_cross_product_connection) {
312332 break;
312333 }
312334 }
312335 auto join_type = JoinType::INVALID;
312336 for (auto &filter_binding : best_connection->filters) {
312337 if (!filter_binding->left_set || !filter_binding->right_set) {
312338 continue;
312339 }
312340
312341 join_type = filter_binding->join_type;
312342 // prefer joining on semi and anti joins as they have a higher chance of being more
312343 // selective
312344 if (join_type == JoinType::SEMI || join_type == JoinType::ANTI) {
312345 break;
312346 }
312347 }
312348 // need the filter info from the Neighborhood info.
312349 auto cost = cost_model.ComputeCost(left, right);
312350 auto result = make_uniq<DPJoinNode>(set, best_connection, left.set, right.set, cost);
312351 result->cardinality = cost_model.cardinality_estimator.EstimateCardinalityWithSet<idx_t>(set);
312352 return result;
312353}
void filter(InputArray image, InputArray kernel, OutputArray output)
Here is the caller graph for this function:

◆ EmitPair()

DPJoinNode & duckdb::PlanEnumerator::EmitPair ( JoinRelationSet & left,
JoinRelationSet & right,
const vector< reference< NeighborInfo > > & info )
private

Emit a pair as a potential join candidate. Returns the best plan found for the (left, right) connection (either the newly created plan, or an existing plan)

312356 {
312357 // get the left and right join plans
312358 auto left_plan = plans.find(left);
312359 auto right_plan = plans.find(right);
312360 if (left_plan == plans.end() || right_plan == plans.end()) {
312361 throw InternalException("No left or right plan: internal error in join order optimizer");
312362 }
312363 auto &new_set = query_graph_manager.set_manager.Union(left, right);
312364 // create the join tree based on combining the two plans
312365 auto new_plan = CreateJoinTree(new_set, info, *left_plan->second, *right_plan->second);
312366 // check if this plan is the optimal plan we found for this set of relations
312367 auto entry = plans.find(new_set);
312368 auto new_cost = new_plan->cost;
312369 double old_cost = NumericLimits<double>::Maximum();
312370 if (entry != plans.end()) {
312371 old_cost = entry->second->cost;
312372 }
312373 if (entry == plans.end() || new_cost < old_cost) {
312374 // the new plan costs less than the old plan. Update our DP table.
312375 plans[new_set] = std::move(new_plan);
312376 return *plans[new_set];
312377 }
312378 // Create join node from the plan currently in the DP table.
312379 return *entry->second;
312380}
unique_ptr< DPJoinNode > CreateJoinTree(JoinRelationSet &set, const vector< reference< NeighborInfo > > &possible_connections, DPJoinNode &left, DPJoinNode &right)
Create a new JoinTree node by joining together two previous JoinTree nodes.
Definition duckdb.cpp:312316
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryEmitPair()

bool duckdb::PlanEnumerator::TryEmitPair ( JoinRelationSet & left,
JoinRelationSet & right,
const vector< reference< NeighborInfo > > & info )
private

Tries to emit a potential join candidate pair. Returns false if too many pairs have already been emitted, cancelling the dynamic programming step.

312383 {
312384 pairs++;
312385 // If a full plan is created, it's possible a node in the plan gets updated. When this happens, make sure you keep
312386 // emitting pairs until you emit another final plan. Another final plan is guaranteed to be produced because of
312387 // our symmetry guarantees.
312388 if (pairs >= 10000) {
312389 // when the amount of pairs gets too large we exit the dynamic programming and resort to a greedy algorithm
312390 // FIXME: simple heuristic currently
312391 // at 10K pairs stop searching exactly and switch to heuristic
312392 return false;
312393 }
312394 EmitPair(left, right, info);
312395 return true;
312396}
idx_t pairs
The total amount of join pairs that have been considered.
Definition duckdb.cpp:311906
DPJoinNode & EmitPair(JoinRelationSet &left, JoinRelationSet &right, const vector< reference< NeighborInfo > > &info)
Definition duckdb.cpp:312355
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnumerateCmpRecursive()

bool duckdb::PlanEnumerator::EnumerateCmpRecursive ( JoinRelationSet & left,
JoinRelationSet & right,
unordered_set< idx_t > & exclusion_set )
private
312451 {
312452 // get the neighbors of the second relation under the exclusion set
312453 auto neighbors = query_graph.GetNeighbors(right, exclusion_set);
312454 if (neighbors.empty()) {
312455 return true;
312456 }
312457
312458 auto all_subset = GetAllNeighborSets(neighbors);
312459 vector<reference<JoinRelationSet>> union_sets;
312460 union_sets.reserve(all_subset.size());
312461 for (const auto &rel_set : all_subset) {
312462 auto &neighbor = query_graph_manager.set_manager.GetJoinRelation(rel_set);
312463 // emit the combinations of this node and its neighbors
312464 auto &combined_set = query_graph_manager.set_manager.Union(right, neighbor);
312465 // If combined_set.count == right.count, This means we found a neighbor that has been present before
312466 // This means we didn't set exclusion_set correctly.
312467 D_ASSERT(combined_set.count > right.count);
312468 if (plans.find(combined_set) != plans.end()) {
312469 auto connections = query_graph.GetConnections(left, combined_set);
312470 if (!connections.empty()) {
312471 if (!TryEmitPair(left, combined_set, connections)) {
312472 return false;
312473 }
312474 }
312475 }
312476 union_sets.push_back(combined_set);
312477 }
312478
312479 unordered_set<idx_t> new_exclusion_set = exclusion_set;
312480 for (const auto &neighbor : neighbors) {
312481 new_exclusion_set.insert(neighbor);
312482 }
312483
312484 // recursively enumerate the sets
312485 for (idx_t i = 0; i < union_sets.size(); i++) {
312486 // updated the set of excluded entries with this neighbor
312487 if (!EnumerateCmpRecursive(left, union_sets[i], new_exclusion_set)) {
312488 return false;
312489 }
312490 }
312491 return true;
312492}
bool TryEmitPair(JoinRelationSet &left, JoinRelationSet &right, const vector< reference< NeighborInfo > > &info)
Definition duckdb.cpp:312382

◆ EmitCSG()

bool duckdb::PlanEnumerator::EmitCSG ( JoinRelationSet & node)
private

Emit a relation set node.

Neighbors should be reversed when iterating over them.

312398 {
312399 if (node.count == query_graph_manager.relation_manager.NumRelations()) {
312400 return true;
312401 }
312402 // create the exclusion set as everything inside the subgraph AND anything with members BELOW it
312403 unordered_set<idx_t> exclusion_set;
312404 for (idx_t i = 0; i < node.relations[0]; i++) {
312405 exclusion_set.insert(i);
312406 }
312407 UpdateExclusionSet(&node, exclusion_set);
312408 // find the neighbors given this exclusion set
312409 auto neighbors = query_graph.GetNeighbors(node, exclusion_set);
312410 if (neighbors.empty()) {
312411 return true;
312412 }
312413
312415 std::sort(neighbors.begin(), neighbors.end(), std::greater<idx_t>());
312416 for (idx_t i = 0; i < neighbors.size() - 1; i++) {
312417 D_ASSERT(neighbors[i] > neighbors[i + 1]);
312418 }
312419
312420 // Dphyp paper missing this.
312421 // Because we are traversing in reverse order, we need to add neighbors whose number is smaller than the current
312422 // node to exclusion_set
312423 // This avoids duplicated enumeration
312424 unordered_set<idx_t> new_exclusion_set = exclusion_set;
312425 for (idx_t i = 0; i < neighbors.size(); ++i) {
312426 D_ASSERT(new_exclusion_set.find(neighbors[i]) == new_exclusion_set.end());
312427 new_exclusion_set.insert(neighbors[i]);
312428 }
312429
312430 for (auto neighbor : neighbors) {
312431 // since the GetNeighbors only returns the smallest element in a list, the entry might not be connected to
312432 // (only!) this neighbor, hence we have to do a connectedness check before we can emit it
312433 auto &neighbor_relation = query_graph_manager.set_manager.GetJoinRelation(neighbor);
312434 auto connections = query_graph.GetConnections(node, neighbor_relation);
312435 if (!connections.empty()) {
312436 if (!TryEmitPair(node, neighbor_relation, connections)) {
312437 return false;
312438 }
312439 }
312440
312441 if (!EnumerateCmpRecursive(node, neighbor_relation, new_exclusion_set)) {
312442 return false;
312443 }
312444
312445 new_exclusion_set.erase(neighbor);
312446 }
312447 return true;
312448}
static void UpdateExclusionSet(optional_ptr< JoinRelationSet > node, unordered_set< idx_t > &exclusion_set)
Update the exclusion set with all entries in the subgraph.
Definition duckdb.cpp:312251
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnumerateCSGRecursive()

bool duckdb::PlanEnumerator::EnumerateCSGRecursive ( JoinRelationSet & node,
unordered_set< idx_t > & exclusion_set )
private

Enumerate the possible connected subgraphs that can be joined together in the join graph.

312494 {
312495 // find neighbors of S under the exclusion set
312496 auto neighbors = query_graph.GetNeighbors(node, exclusion_set);
312497 if (neighbors.empty()) {
312498 return true;
312499 }
312500
312501 auto all_subset = GetAllNeighborSets(neighbors);
312502 vector<reference<JoinRelationSet>> union_sets;
312503 union_sets.reserve(all_subset.size());
312504 for (const auto &rel_set : all_subset) {
312505 auto &neighbor = query_graph_manager.set_manager.GetJoinRelation(rel_set);
312506 // emit the combinations of this node and its neighbors
312507 auto &new_set = query_graph_manager.set_manager.Union(node, neighbor);
312508 D_ASSERT(new_set.count > node.count);
312509 if (plans.find(new_set) != plans.end()) {
312510 if (!EmitCSG(new_set)) {
312511 return false;
312512 }
312513 }
312514 union_sets.push_back(new_set);
312515 }
312516
312517 unordered_set<idx_t> new_exclusion_set = exclusion_set;
312518 for (const auto &neighbor : neighbors) {
312519 new_exclusion_set.insert(neighbor);
312520 }
312521
312522 // recursively enumerate the sets
312523 for (idx_t i = 0; i < union_sets.size(); i++) {
312524 // updated the set of excluded entries with this neighbor
312525 if (!EnumerateCSGRecursive(union_sets[i], new_exclusion_set)) {
312526 return false;
312527 }
312528 }
312529 return true;
312530}
bool EmitCSG(JoinRelationSet &node)
Emit a relation set node.
Definition duckdb.cpp:312398
bool EnumerateCSGRecursive(JoinRelationSet &node, unordered_set< idx_t > &exclusion_set)
Enumerate the possible connected subgraphs that can be joined together in the join graph.
Definition duckdb.cpp:312494
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GenerateCrossProducts()

void duckdb::PlanEnumerator::GenerateCrossProducts ( )
private

Generate cross product edges inside the side.

312292 {
312293 // generate a set of cross products to combine the currently available plans into a full join plan
312294 // we create edges between every relation with a high cost
312295 for (idx_t i = 0; i < query_graph_manager.relation_manager.NumRelations(); i++) {
312296 auto &left = query_graph_manager.set_manager.GetJoinRelation(i);
312297 for (idx_t j = 0; j < query_graph_manager.relation_manager.NumRelations(); j++) {
312298 auto cross_product_allowed = query_graph_manager.relation_manager.CrossProductWithRelationAllowed(i) &&
312299 query_graph_manager.relation_manager.CrossProductWithRelationAllowed(j);
312300 if (i != j && cross_product_allowed) {
312301 auto &right = query_graph_manager.set_manager.GetJoinRelation(j);
312302 query_graph_manager.CreateQueryGraphCrossProduct(left, right);
312303 }
312304 }
312305 }
312306 // Now that the query graph has new edges, we need to re-initialize our query graph.
312307 // TODO: do we need to initialize our qyery graph again?
312308 // query_graph = query_graph_manager.GetQueryGraph();
312309}
Here is the caller graph for this function:

◆ SolveJoinOrderExactly()

bool duckdb::PlanEnumerator::SolveJoinOrderExactly ( )
private

Solve the join order exactly using dynamic programming. Returns true if it was completed successfully (i.e. did not time-out)

312532 {
312533 // now we perform the actual dynamic programming to compute the final result
312534 // we enumerate over all the possible pairs in the neighborhood
312535 for (idx_t i = query_graph_manager.relation_manager.NumRelations(); i > 0; i--) {
312536 // for every node in the set, we consider it as the start node once
312537 auto &start_node = query_graph_manager.set_manager.GetJoinRelation(i - 1);
312538 // emit the start node
312539 if (!EmitCSG(start_node)) {
312540 return false;
312541 }
312542 // initialize the set of exclusion_set as all the nodes with a number below this
312543 unordered_set<idx_t> exclusion_set;
312544 for (idx_t j = 0; j < i; j++) {
312545 exclusion_set.insert(j);
312546 }
312547 // then we recursively search for neighbors that do not belong to the banned entries
312548 if (!EnumerateCSGRecursive(start_node, exclusion_set)) {
312549 return false;
312550 }
312551 }
312552 return true;
312553}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SolveJoinOrderApproximately()

void duckdb::PlanEnumerator::SolveJoinOrderApproximately ( )
private

Solve the join order approximately using a greedy algorithm.

312555 {
312556 // at this point, we exited the dynamic programming but did not compute the final join order because it took too
312557 // long instead, we use a greedy heuristic to obtain a join ordering now we use Greedy Operator Ordering to
312558 // construct the result tree first we start out with all the base relations (the to-be-joined relations)
312559 vector<reference<JoinRelationSet>> join_relations; // T in the paper
312560 for (idx_t i = 0; i < query_graph_manager.relation_manager.NumRelations(); i++) {
312561 join_relations.push_back(query_graph_manager.set_manager.GetJoinRelation(i));
312562 }
312563 while (join_relations.size() > 1) {
312564 // now in every step of the algorithm, we greedily pick the join between the to-be-joined relations that has the
312565 // smallest cost. This is O(r^2) per step, and every step will reduce the total amount of relations to-be-joined
312566 // by 1, so the total cost is O(r^3) in the amount of relations
312567 // long is needed to prevent clang-tidy complaints. (idx_t) cannot be added to an iterator position because it
312568 // is unsigned.
312569 idx_t best_left = 0, best_right = 0;
312570 optional_ptr<DPJoinNode> best_connection;
312571 for (idx_t i = 0; i < join_relations.size(); i++) {
312572 auto left = join_relations[i];
312573 for (idx_t j = i + 1; j < join_relations.size(); j++) {
312574 auto right = join_relations[j];
312575 // check if we can connect these two relations
312576 auto connection = query_graph.GetConnections(left, right);
312577 if (!connection.empty()) {
312578 // we can check the cost of this connection
312579 auto node = EmitPair(left, right, connection);
312580
312581 // update the DP tree in case a plan created by the DP algorithm uses the node
312582 // that was potentially just updated by EmitPair. You will get a use-after-free
312583 // error if future plans rely on the old node that was just replaced.
312584 // if node in FullPath, then updateDP tree.
312585
312586 if (!best_connection || node.cost < best_connection->cost) {
312587 // best pair found so far
312588 best_connection = &EmitPair(left, right, connection);
312589 best_left = i;
312590 best_right = j;
312591 }
312592 }
312593 }
312594 }
312595 if (!best_connection) {
312596 // could not find a connection, but we were not done with finding a completed plan
312597 // we have to add a cross product; we add it between the two smallest relations
312598 optional_ptr<DPJoinNode> smallest_plans[2];
312599 size_t smallest_index[2];
312600 D_ASSERT(join_relations.size() >= 2);
312601
312602 // first just add the first two join relations. It doesn't matter the cost as the JOO
312603 // will swap them on estimated cardinality anyway.
312604 for (idx_t i = 0; i < 2; i++) {
312605 optional_ptr<DPJoinNode> current_plan = plans[join_relations[i]];
312606 smallest_plans[i] = current_plan;
312607 smallest_index[i] = i;
312608 }
312609
312610 // if there are any other join relations that don't have connections
312611 // add them if they have lower estimated cardinality.
312612 for (idx_t i = 2; i < join_relations.size(); i++) {
312613 // get the plan for this relation
312614 optional_ptr<DPJoinNode> current_plan = plans[join_relations[i]];
312615 // check if the cardinality is smaller than the smallest two found so far
312616 for (idx_t j = 0; j < 2; j++) {
312617 if (!smallest_plans[j] || smallest_plans[j]->cost > current_plan->cost) {
312618 smallest_plans[j] = current_plan;
312619 smallest_index[j] = i;
312620 break;
312621 }
312622 }
312623 }
312624 if (!smallest_plans[0] || !smallest_plans[1]) {
312625 throw InternalException("Internal error in join order optimizer");
312626 }
312627 D_ASSERT(smallest_plans[0] && smallest_plans[1]);
312628 D_ASSERT(smallest_index[0] != smallest_index[1]);
312629 auto &left = smallest_plans[0]->set;
312630 auto &right = smallest_plans[1]->set;
312631 // create a cross product edge (i.e. edge with empty filter) between these two sets in the query graph
312632 query_graph_manager.CreateQueryGraphCrossProduct(left, right);
312633 // now emit the pair and continue with the algorithm
312634 auto connections = query_graph.GetConnections(left, right);
312635 D_ASSERT(!connections.empty());
312636
312637 best_connection = &EmitPair(left, right, connections);
312638 best_left = smallest_index[0];
312639 best_right = smallest_index[1];
312640
312641 // the code below assumes best_right > best_left
312642 if (best_left > best_right) {
312643 std::swap(best_left, best_right);
312644 }
312645 }
312646 // now update the to-be-checked pairs
312647 // remove left and right, and add the combination
312648
312649 // important to erase the biggest element first
312650 // if we erase the smallest element first the index of the biggest element changes
312651 auto &new_set = query_graph_manager.set_manager.Union(join_relations.at(best_left).get(),
312652 join_relations.at(best_right).get());
312653 D_ASSERT(best_right > best_left);
312654 join_relations.erase(join_relations.begin() + (int64_t)best_right);
312655 join_relations.erase(join_relations.begin() + (int64_t)best_left);
312656 join_relations.push_back(new_set);
312657 }
312658}
Here is the call graph for this function:
Here is the caller graph for this function:

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