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

Public Member Functions

void RemoveEmptyTotalDomains ()
void UpdateTotalDomains (optional_ptr< JoinRelationSet > set, RelationStats &stats)
void InitEquivalentRelations (const vector< unique_ptr< FilterInfo > > &filter_infos)
void InitCardinalityEstimatorProps (optional_ptr< JoinRelationSet > set, RelationStats &stats)
template<class T>
T EstimateCardinalityWithSet (JoinRelationSet &new_set)
void AddRelationNamesToRelationStats (vector< RelationStats > &stats)
 used for debugging.
void PrintRelationStats ()
template<>
double EstimateCardinalityWithSet (JoinRelationSet &new_set)
template<>
idx_t EstimateCardinalityWithSet (JoinRelationSet &new_set)

Static Public Attributes

static constexpr double DEFAULT_SEMI_ANTI_SELECTIVITY = 5

Private Member Functions

double GetNumerator (JoinRelationSet &set)
DenomInfo GetDenominator (JoinRelationSet &set)
bool SingleColumnFilter (FilterInfo &filter_info)
vector< idx_t > DetermineMatchingEquivalentSets (optional_ptr< FilterInfo > filter_info)
void AddToEquivalenceSets (optional_ptr< FilterInfo > filter_info, vector< idx_t > matching_equivalent_sets)
double CalculateUpdatedDenom (Subgraph2Denominator left, Subgraph2Denominator right, FilterInfoWithTotalDomains &filter)
JoinRelationSet & UpdateNumeratorRelations (Subgraph2Denominator left, Subgraph2Denominator right, FilterInfoWithTotalDomains &filter)
void AddRelationStats (FilterInfo &filter_info)
bool EmptyFilter (FilterInfo &filter_info)

Private Attributes

vector< RelationsSetToStats > relation_set_stats
unordered_map< string, CardinalityHelper > relation_set_2_cardinality
JoinRelationSetManager set_manager
vector< RelationStats > relation_stats

Constructor & Destructor Documentation

◆ CardinalityEstimator()

duckdb::CardinalityEstimator::CardinalityEstimator ( )
inlineexplicit
21496{};

Member Function Documentation

◆ RemoveEmptyTotalDomains()

void duckdb::CardinalityEstimator::RemoveEmptyTotalDomains ( )
311302 {
311303 auto remove_start =
311304 std::remove_if(relation_set_stats.begin(), relation_set_stats.end(),
311305 [](RelationsSetToStats &r_2_tdom) { return r_2_tdom.equivalent_relations.empty(); });
311306 relation_set_stats.erase(remove_start, relation_set_stats.end());
311307}

◆ UpdateTotalDomains()

void duckdb::CardinalityEstimator::UpdateTotalDomains ( optional_ptr< JoinRelationSet > set,
RelationStats & stats )

Initialize the distinct count for all columns used in joins with the current relation.

for every column used in a filter in the relation, get the distinct count via HLL, or assume it to be the cardinality

311642 {
311643 D_ASSERT(set->count == 1);
311644 auto relation_id = set->relations[0];
311646 // D_ASSERT(stats.column_distinct_count.size() >= 1);
311647
311648 for (idx_t i = 0; i < stats.column_distinct_count.size(); i++) {
311651 // Update the relation_to_tdom set with the estimated distinct count (or tdom) calculated above
311652 auto key = ColumnBinding(relation_id, i);
311653 for (auto &relation_to_tdom : relation_set_stats) {
311654 column_binding_set_t i_set = relation_to_tdom.equivalent_relations;
311655 if (i_set.find(key) == i_set.end()) {
311656 continue;
311657 }
311658 auto distinct_count = stats.column_distinct_count.at(i);
311659 if (distinct_count.from_hll && relation_to_tdom.has_distinct_count_hll) {
311660 relation_to_tdom.distinct_count_hll =
311661 MaxValue(relation_to_tdom.distinct_count_hll, distinct_count.distinct_count);
311662 } else if (distinct_count.from_hll && !relation_to_tdom.has_distinct_count_hll) {
311663 relation_to_tdom.has_distinct_count_hll = true;
311664 relation_to_tdom.distinct_count_hll = distinct_count.distinct_count;
311665 } else {
311666 relation_to_tdom.distinct_count_no_hll =
311667 MinValue(distinct_count.distinct_count, relation_to_tdom.distinct_count_no_hll);
311668 }
311669 break;
311670 }
311671 }
311672}
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:

◆ InitEquivalentRelations()

void duckdb::CardinalityEstimator::InitEquivalentRelations ( const vector< unique_ptr< FilterInfo > > & filter_infos)
311281 {
311282 // For each filter, we fill keep track of the index of the equivalent relation set
311283 // the left and right relation needs to be added to.
311284 for (auto &filter : filter_infos) {
311285 if (SingleColumnFilter(*filter)) {
311286 // Filter on one relation, (i.e. string or range filter on a column).
311287 // Grab the first relation and add it to the equivalence_relations
311288 AddRelationStats(*filter);
311289 continue;
311290 } else if (EmptyFilter(*filter)) {
311291 continue;
311292 }
311293 D_ASSERT(filter->left_set->count >= 1);
311294 D_ASSERT(filter->right_set->count >= 1);
311295
311296 auto matching_equivalent_sets = DetermineMatchingEquivalentSets(filter.get());
311297 AddToEquivalenceSets(filter.get(), matching_equivalent_sets);
311298 }
311299 RemoveEmptyTotalDomains();
311300}
void AddToEquivalenceSets(optional_ptr< FilterInfo > filter_info, vector< idx_t > matching_equivalent_sets)
Definition duckdb.cpp:311250
void filter(InputArray image, InputArray kernel, OutputArray output)

◆ InitCardinalityEstimatorProps()

void duckdb::CardinalityEstimator::InitCardinalityEstimatorProps ( optional_ptr< JoinRelationSet > set,
RelationStats & stats )
311628 {
311629 // Get the join relation set
311630 D_ASSERT(stats.stats_initialized);
311631 auto relation_cardinality = stats.cardinality;
311632
311633 auto card_helper = CardinalityHelper((double)relation_cardinality);
311634 relation_set_2_cardinality[set->ToString()] = card_helper;
311635
311636 UpdateTotalDomains(set, stats);
311637
311638 // sort relations from greatest tdom to lowest tdom.
311639 std::sort(relation_set_stats.begin(), relation_set_stats.end(), SortTdoms);
311640}
void UpdateTotalDomains(optional_ptr< JoinRelationSet > set, RelationStats &stats)
Definition duckdb.cpp:311642

◆ EstimateCardinalityWithSet() [1/3]

template<class T>
T duckdb::CardinalityEstimator::EstimateCardinalityWithSet ( JoinRelationSet & new_set)

cost model needs estimated cardinalities to the fraction since the formula captures distinct count selectivities and multiplicities. Hence the template

◆ AddRelationNamesToRelationStats()

void duckdb::CardinalityEstimator::AddRelationNamesToRelationStats ( vector< RelationStats > & stats)

used for debugging.

311676 {
311677#ifdef DEBUG
311678 for (auto &total_domain : relation_set_stats) {
311679 for (auto &binding : total_domain.equivalent_relations) {
311680 D_ASSERT(binding.table_index < stats.size());
311681 string column_name;
311682 if (binding.column_index < stats[binding.table_index].column_names.size()) {
311683 column_name = stats[binding.table_index].column_names[binding.column_index];
311684 } else {
311685 column_name = "[unknown]";
311686 }
311687 total_domain.column_names.push_back(column_name);
311688 }
311689 }
311690#endif
311691}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrintRelationStats()

void duckdb::CardinalityEstimator::PrintRelationStats ( )
311693 {
311694 for (auto &total_domain : relation_set_stats) {
311695 string domain = "Following columns have the same distinct count: ";
311696 for (auto &column_name : total_domain.column_names) {
311697 domain += column_name + ", ";
311698 }
311699 bool have_hll = total_domain.has_distinct_count_hll;
311700 domain += "\n TOTAL DOMAIN = " +
311701 to_string(have_hll ? total_domain.distinct_count_hll : total_domain.distinct_count_no_hll);
311702 Printer::Print(domain);
311703 }
311704}
static DUCKDB_API void Print(OutputStream stream, const string &str)
Print the object to the stream.
Definition duckdb.cpp:92556
std::string to_string(const T &value)
Definition duckdb.cpp:19425

◆ GetNumerator()

double duckdb::CardinalityEstimator::GetNumerator ( JoinRelationSet & set)
private
311309 {
311310 double numerator = 1;
311311 for (idx_t i = 0; i < set.count; i++) {
311312 auto &single_node_set = set_manager.GetJoinRelation(set.relations[i]);
311313 auto card_helper = relation_set_2_cardinality[single_node_set.ToString()];
311314 numerator *= card_helper.cardinality_before_filters == 0 ? 1 : card_helper.cardinality_before_filters;
311315 }
311316 return numerator;
311317}

◆ GetDenominator()

DenomInfo duckdb::CardinalityEstimator::GetDenominator ( JoinRelationSet & set)
private
311457 {
311458 vector<Subgraph2Denominator> subgraphs;
311459
311460 // Finding the denominator is tricky. You need to go through the tdoms in decreasing order
311461 // Then loop through all filters in the equivalence set of the tdom to see if both the
311462 // left and right relations are in the new set, if so you can use that filter.
311463 // You must also make sure that the filters all relations in the given set, so we use subgraphs
311464 // that should eventually merge into one connected graph that joins all the relations
311465 // TODO: Implement a method to cache subgraphs so you don't have to build them up every
311466 // time the cardinality of a new set is requested
311467
311468 // relations_to_tdoms has already been sorted by largest to smallest total domain
311469 // then we look through the filters for the relations_to_tdoms,
311470 // and we start to choose the filters that join relations in the set.
311471
311472 // edges are guaranteed to be in order of largest tdom to smallest tdom.
311473 unordered_set<idx_t> unused_edge_tdoms;
311474 auto edges = GetEdges(relation_set_stats, set);
311475 for (auto &edge : edges) {
311476 if (subgraphs.size() == 1 && subgraphs.at(0).relations->ToString() == set.ToString()) {
311477 // the first subgraph has connected all the desired relations, just skip the rest of the edges
311478 if (edge.has_distinct_count_hll) {
311479 unused_edge_tdoms.insert(edge.distinct_count_hll);
311480 }
311481 continue;
311482 }
311483
311484 auto subgraph_connections = SubgraphsConnectedByEdge(edge, subgraphs);
311485 if (subgraph_connections.empty()) {
311486 // create a subgraph out of left and right, then merge right into left and add left to subgraphs.
311487 // this helps cover a case where there are no subgraphs yet, and the only join filter is a SEMI JOIN
311488 auto left_subgraph = Subgraph2Denominator();
311489 auto right_subgraph = Subgraph2Denominator();
311490 left_subgraph.relations = edge.filter_info->left_set;
311491 left_subgraph.numerator_relations = edge.filter_info->left_set;
311492 right_subgraph.relations = edge.filter_info->right_set;
311493 right_subgraph.numerator_relations = edge.filter_info->right_set;
311494 left_subgraph.numerator_relations = &UpdateNumeratorRelations(left_subgraph, right_subgraph, edge);
311495 left_subgraph.relations = edge.filter_info->set.get();
311496 left_subgraph.denom = CalculateUpdatedDenom(left_subgraph, right_subgraph, edge);
311497 subgraphs.push_back(left_subgraph);
311498 } else if (subgraph_connections.size() == 1) {
311499 auto left_subgraph = &subgraphs.at(subgraph_connections.at(0));
311500 auto right_subgraph = Subgraph2Denominator();
311501 right_subgraph.relations = edge.filter_info->right_set;
311502 right_subgraph.numerator_relations = edge.filter_info->right_set;
311503 if (JoinRelationSet::IsSubset(*left_subgraph->relations, *right_subgraph.relations)) {
311504 right_subgraph.relations = edge.filter_info->left_set;
311505 right_subgraph.numerator_relations = edge.filter_info->left_set;
311506 }
311507
311508 if (JoinRelationSet::IsSubset(*left_subgraph->relations, *edge.filter_info->left_set) &&
311509 JoinRelationSet::IsSubset(*left_subgraph->relations, *edge.filter_info->right_set)) {
311510 // here we have an edge that connects the same subgraph to the same subgraph. Just continue. no need to
311511 // update the denom
311512 continue;
311513 }
311514 left_subgraph->numerator_relations = &UpdateNumeratorRelations(*left_subgraph, right_subgraph, edge);
311515 left_subgraph->relations = &set_manager.Union(*left_subgraph->relations, *right_subgraph.relations);
311516 left_subgraph->denom = CalculateUpdatedDenom(*left_subgraph, right_subgraph, edge);
311517 } else if (subgraph_connections.size() == 2) {
311518 // The two subgraphs in the subgraph_connections can be merged by this edge.
311519 D_ASSERT(subgraph_connections.at(0) < subgraph_connections.at(1));
311520 auto subgraph_to_merge_into = &subgraphs.at(subgraph_connections.at(0));
311521 auto subgraph_to_delete = &subgraphs.at(subgraph_connections.at(1));
311522 subgraph_to_merge_into->relations =
311523 &set_manager.Union(*subgraph_to_merge_into->relations, *subgraph_to_delete->relations);
311524 subgraph_to_merge_into->numerator_relations =
311525 &UpdateNumeratorRelations(*subgraph_to_merge_into, *subgraph_to_delete, edge);
311526 subgraph_to_merge_into->denom = CalculateUpdatedDenom(*subgraph_to_merge_into, *subgraph_to_delete, edge);
311527 subgraph_to_delete->relations = nullptr;
311528 auto remove_start = std::remove_if(subgraphs.begin(), subgraphs.end(),
311529 [](Subgraph2Denominator &s) { return !s.relations; });
311530 subgraphs.erase(remove_start, subgraphs.end());
311531 }
311532 }
311533
311534 // Slight penalty to cardinality for unused edges
311535 auto denom_multiplier = 1.0 + static_cast<double>(unused_edge_tdoms.size());
311536
311537 // It's possible cross-products were added and are not present in the filters in the relation_2_tdom
311538 // structures. When that's the case, merge all remaining subgraphs as if they are connected by a cross product
311539 if (subgraphs.size() > 1) {
311540 auto final_subgraph = subgraphs.at(0);
311541 for (auto merge_with = subgraphs.begin() + 1; merge_with != subgraphs.end(); merge_with++) {
311542 D_ASSERT(final_subgraph.relations && merge_with->relations);
311543 final_subgraph.relations = &set_manager.Union(*final_subgraph.relations, *merge_with->relations);
311544 D_ASSERT(final_subgraph.numerator_relations && merge_with->numerator_relations);
311545 final_subgraph.numerator_relations =
311546 &set_manager.Union(*final_subgraph.numerator_relations, *merge_with->numerator_relations);
311547 final_subgraph.denom *= merge_with->denom;
311548 }
311549 }
311550 if (!subgraphs.empty()) {
311551 // Some relations are connected by cross products and will not end up in a subgraph
311552 // Check and make sure all relations were considered, if not, they are connected to the graph by cross products
311553 auto &returning_subgraph = subgraphs.at(0);
311554 if (returning_subgraph.relations->count != set.count) {
311555 for (idx_t rel_index = 0; rel_index < set.count; rel_index++) {
311556 auto relation_id = set.relations[rel_index];
311557 auto &rel = set_manager.GetJoinRelation(relation_id);
311558 if (!JoinRelationSet::IsSubset(*returning_subgraph.relations, rel)) {
311559 returning_subgraph.numerator_relations =
311560 &set_manager.Union(*returning_subgraph.numerator_relations, rel);
311561 returning_subgraph.relations = &set_manager.Union(*returning_subgraph.relations, rel);
311562 }
311563 }
311564 }
311565 }
311566
311567 // can happen if a table has cardinality 0, a tdom is set to 0, or if a cross product is used.
311568 if (subgraphs.empty() || subgraphs.at(0).denom == 0) {
311569 // denominator is 1 and numerators are a cross product of cardinalities.
311570 return DenomInfo(set, 1, 1);
311571 }
311572 return DenomInfo(*subgraphs.at(0).numerator_relations, 1, subgraphs.at(0).denom * denom_multiplier);
311573}
static bool IsSubset(JoinRelationSet &super, JoinRelationSet &sub)
Returns true if sub is a subset of super.
Definition duckdb.cpp:312070

◆ SingleColumnFilter()

bool duckdb::CardinalityEstimator::SingleColumnFilter ( duckdb::FilterInfo & filter_info)
private
311218 {
311219 if (filter_info.left_set && filter_info.right_set && filter_info.set.get().count > 1) {
311220 // Both set and are from different relations
311221 return false;
311222 }
311223 if (EmptyFilter(filter_info)) {
311224 return false;
311225 }
311226 if (filter_info.join_type == JoinType::SEMI || filter_info.join_type == JoinType::ANTI) {
311227 return false;
311228 }
311229 return true;
311230}

◆ DetermineMatchingEquivalentSets()

vector< idx_t > duckdb::CardinalityEstimator::DetermineMatchingEquivalentSets ( optional_ptr< FilterInfo > filter_info)
private
311232 {
311233 vector<idx_t> matching_equivalent_sets;
311234 idx_t equivalent_relation_index = 0;
311235
311236 for (const RelationsSetToStats &r2tdom : relation_set_stats) {
311237 auto &i_set = r2tdom.equivalent_relations;
311238 if (i_set.find(filter_info->left_binding) != i_set.end()) {
311239 matching_equivalent_sets.push_back(equivalent_relation_index);
311240 } else if (i_set.find(filter_info->right_binding) != i_set.end()) {
311241 // don't add both left and right to the matching_equivalent_sets
311242 // since both left and right get added to that index anyway.
311243 matching_equivalent_sets.push_back(equivalent_relation_index);
311244 }
311245 equivalent_relation_index++;
311246 }
311247 return matching_equivalent_sets;
311248}

◆ AddToEquivalenceSets()

void duckdb::CardinalityEstimator::AddToEquivalenceSets ( optional_ptr< FilterInfo > filter_info,
vector< idx_t > matching_equivalent_sets )
private

Given a filter, add the column bindings to the matching equivalent set at the index given in matching equivalent sets. If there are multiple equivalence sets, they are merged.

311251 {
311252 D_ASSERT(matching_equivalent_sets.size() <= 2);
311253 if (matching_equivalent_sets.size() > 1) {
311254 // an equivalence relation is connecting two sets of equivalence relations
311255 // so push all relations from the second set into the first. Later we will delete
311256 // the second set.
311257 for (ColumnBinding i : relation_set_stats.at(matching_equivalent_sets[1]).equivalent_relations) {
311258 relation_set_stats.at(matching_equivalent_sets[0]).equivalent_relations.insert(i);
311259 }
311260 for (auto &column_name : relation_set_stats.at(matching_equivalent_sets[1]).column_names) {
311261 relation_set_stats.at(matching_equivalent_sets[0]).column_names.push_back(column_name);
311262 }
311263 relation_set_stats.at(matching_equivalent_sets[1]).equivalent_relations.clear();
311264 relation_set_stats.at(matching_equivalent_sets[1]).column_names.clear();
311265 relation_set_stats.at(matching_equivalent_sets[0]).filters.push_back(filter_info);
311266 // add all values of one set to the other, delete the empty one
311267 } else if (matching_equivalent_sets.size() == 1) {
311268 auto &tdom_i = relation_set_stats.at(matching_equivalent_sets.at(0));
311269 tdom_i.equivalent_relations.insert(filter_info->left_binding);
311270 tdom_i.equivalent_relations.insert(filter_info->right_binding);
311271 tdom_i.filters.push_back(filter_info);
311272 } else if (matching_equivalent_sets.empty()) {
311273 column_binding_set_t tmp;
311274 tmp.insert(filter_info->left_binding);
311275 tmp.insert(filter_info->right_binding);
311276 relation_set_stats.emplace_back(tmp);
311277 relation_set_stats.back().filters.push_back(filter_info);
311278 }
311279}

◆ CalculateUpdatedDenom()

double duckdb::CardinalityEstimator::CalculateUpdatedDenom ( Subgraph2Denominator left,
Subgraph2Denominator right,
FilterInfoWithTotalDomains & filter )
private
311397 {
311398 double new_denom = left.denom * right.denom;
311399 switch (filter.filter_info->join_type) {
311400 case JoinType::INNER: {
311401 // Collect comparison types
311402 ExpressionType comparison_type = ExpressionType::INVALID;
311403 ExpressionIterator::EnumerateExpression(filter.filter_info->filter, [&](Expression &expr) {
311404 if (expr.GetExpressionClass() == ExpressionClass::BOUND_COMPARISON) {
311405 comparison_type = expr.GetExpressionType();
311406 }
311407 });
311408 if (comparison_type == ExpressionType::INVALID) {
311409 new_denom *= filter.has_distinct_count_hll ? static_cast<double>(filter.distinct_count_hll)
311410 : static_cast<double>(filter.distinct_count_no_hll);
311411 // no comparison is taking place, so the denominator is just the product of the left and right
311412 return new_denom;
311413 }
311414 // extra_ratio helps represents how many tuples will be filtered out if the comparison evaluates to
311415 // false. set to 1 to assume cross product.
311416 double extra_ratio = 1;
311417 switch (comparison_type) {
311418 case ExpressionType::COMPARE_EQUAL:
311419 case ExpressionType::COMPARE_NOT_DISTINCT_FROM:
311420 // extra ratio stays 1
311421 extra_ratio = filter.has_distinct_count_hll ? static_cast<double>(filter.distinct_count_hll)
311422 : static_cast<double>(filter.distinct_count_no_hll);
311423 break;
311424 case ExpressionType::COMPARE_LESSTHANOREQUALTO:
311425 case ExpressionType::COMPARE_LESSTHAN:
311426 case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
311427 case ExpressionType::COMPARE_GREATERTHAN:
311428 case ExpressionType::COMPARE_NOTEQUAL:
311429 case ExpressionType::COMPARE_DISTINCT_FROM:
311430 // Assume this blows up, but use the tdom to bound it a bit
311431 extra_ratio = filter.has_distinct_count_hll ? static_cast<double>(filter.distinct_count_hll)
311432 : static_cast<double>(filter.distinct_count_no_hll);
311433 extra_ratio = pow(extra_ratio, 2.0 / 3.0);
311434 break;
311435 default:
311436 break;
311437 }
311438 new_denom *= extra_ratio;
311439 return new_denom;
311440 }
311441 case JoinType::SEMI:
311442 case JoinType::ANTI: {
311443 if (JoinRelationSet::IsSubset(*left.relations, *filter.filter_info->left_set) &&
311444 JoinRelationSet::IsSubset(*right.relations, *filter.filter_info->right_set)) {
311445 new_denom = left.denom * CardinalityEstimator::DEFAULT_SEMI_ANTI_SELECTIVITY;
311446 return new_denom;
311447 }
311448 new_denom = right.denom * CardinalityEstimator::DEFAULT_SEMI_ANTI_SELECTIVITY;
311449 return new_denom;
311450 }
311451 default:
311452 // cross product
311453 return new_denom;
311454 }
311455}
void pow(InputArray src, double power, OutputArray dst)

◆ UpdateNumeratorRelations()

JoinRelationSet & duckdb::CardinalityEstimator::UpdateNumeratorRelations ( Subgraph2Denominator left,
Subgraph2Denominator right,
FilterInfoWithTotalDomains & filter )
private
311378 {
311379 switch (filter.filter_info->join_type) {
311380 case JoinType::SEMI:
311381 case JoinType::ANTI: {
311382 if (JoinRelationSet::IsSubset(*left.relations, *filter.filter_info->left_set) &&
311383 JoinRelationSet::IsSubset(*right.relations, *filter.filter_info->right_set)) {
311384 return *left.numerator_relations;
311385 }
311386 return *right.numerator_relations;
311387 }
311388 default:
311389 // cross product or inner join
311390 return set_manager.Union(*left.numerator_relations, *right.numerator_relations);
311391 }
311392}

◆ AddRelationStats()

void duckdb::CardinalityEstimator::AddRelationStats ( FilterInfo & filter_info)
private
311202 {
311203 D_ASSERT(filter_info.set.get().count >= 1);
311204 for (const RelationsSetToStats &r2tdom : relation_set_stats) {
311205 auto &i_set = r2tdom.equivalent_relations;
311206 if (i_set.find(filter_info.left_binding) != i_set.end()) {
311207 // found an equivalent filter
311208 return;
311209 }
311210 }
311211
311212 auto key = ColumnBinding(filter_info.left_binding.table_index, filter_info.left_binding.column_index);
311213 RelationsSetToStats new_r2tdom(column_binding_set_t({key}));
311214
311215 relation_set_stats.emplace_back(new_r2tdom);
311216}

◆ EmptyFilter()

bool duckdb::CardinalityEstimator::EmptyFilter ( FilterInfo & filter_info)
private
311195 {
311196 if (!filter_info.left_set && !filter_info.right_set) {
311197 return true;
311198 }
311199 return false;
311200}

◆ EstimateCardinalityWithSet() [2/3]

template<>
double duckdb::CardinalityEstimator::EstimateCardinalityWithSet ( JoinRelationSet & new_set)
311588 {
311589 if (relation_set_2_cardinality.find(new_set.ToString()) != relation_set_2_cardinality.end()) {
311590 return relation_set_2_cardinality[new_set.ToString()].cardinality_before_filters;
311591 }
311592
311593 // can happen if a table has cardinality 0, or a tdom is set to 0
311594 auto denom = GetDenominator(new_set);
311595 // we pass numerator relations, because for semi and anti joins, we don't want to
311596 // include cardinalities of relations on the RHS of a semi/anti join.
311597 auto numerator = GetNumerator(denom.numerator_relations);
311598
311599 double result = numerator / denom.denominator;
311600 auto new_entry = CardinalityHelper(result);
311601 relation_set_2_cardinality[new_set.ToString()] = new_entry;
311602 return result;
311603}

◆ EstimateCardinalityWithSet() [3/3]

template<>
idx_t duckdb::CardinalityEstimator::EstimateCardinalityWithSet ( JoinRelationSet & new_set)
311606 {
311607 auto cardinality_as_double = EstimateCardinalityWithSet<double>(new_set);
311608 auto max = NumericLimits<idx_t>::Maximum();
311609 if (cardinality_as_double >= (double)max) {
311610 return max;
311611 }
311612 return (idx_t)cardinality_as_double;
311613}
T EstimateCardinalityWithSet(JoinRelationSet &new_set)
static softfloat max()

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