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

Public Member Functions

 JoinDependentFilterRule (ExpressionRewriter &rewriter)
unique_ptr< Expression > Apply (LogicalOperator &op, vector< reference< Expression > > &bindings, bool &changes_made, bool is_root) override
Public Member Functions inherited from duckdb::Rule
 Rule (ExpressionRewriter &rewriter)
ClientContext & GetContext () const

Additional Inherited Members

Public Attributes inherited from duckdb::Rule
ExpressionRewriter & rewriter
 The expression rewriter this rule belongs to.
unique_ptr< ExpressionMatcher > root
 The expression matcher of the rule.

Detailed Description

Join-dependent filter derivation as proposed in https://homepages.cwi.nl/~boncz/snb-challenge/chokepoints-tpctc.pdf This rule inspects filters like this: SELECT * FROM nation n1 JOIN nation n2 ON ((n1.n_name = 'FRANCE' AND n2.n_name = 'GERMANY') OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE')); The join filter as a whole cannot be pushed down, because it references tables from both sides. However, we can derive from this two filters that can be pushed down, namely: WHERE (n1.n_name = 'FRANCE' OR n1.n_name = 'GERMANY') AND (n2.n_name = 'GERMANY' OR n2.n_name = 'FRANCE') By adding this filter, we can reduce both sides of the join before performing the join on the original condition.

Constructor & Destructor Documentation

◆ JoinDependentFilterRule()

duckdb::JoinDependentFilterRule::JoinDependentFilterRule ( ExpressionRewriter & rewriter)
explicit
321225 : Rule(rewriter) {
321226 // Match on a ConjunctionExpression that has at least two ConjunctionExpressions as children
321227 auto op = make_uniq<ConjunctionExpressionMatcher>();
321228 op->matchers.push_back(make_uniq<ConjunctionExpressionMatcher>());
321229 op->policy = SetMatcher::Policy::SOME;
321230 root = std::move(op);
321231}
ExpressionRewriter & rewriter
The expression rewriter this rule belongs to.
Definition duckdb.cpp:69564
unique_ptr< ExpressionMatcher > root
The expression matcher of the rule.
Definition duckdb.cpp:69566
@ SOME
Only some entries have to be matched, the order of the matches does not matter.
Definition duckdb.cpp:69125

Member Function Documentation

◆ Apply()

unique_ptr< Expression > duckdb::JoinDependentFilterRule::Apply ( LogicalOperator & op,
vector< reference< Expression > > & bindings,
bool & changes_made,
bool is_root )
overridevirtual

Implements duckdb::Rule.

321268 {
321269 // Only applies to top-level FILTER expressions
321270 if ((op.type != LogicalOperatorType::LOGICAL_FILTER && op.type != LogicalOperatorType::LOGICAL_ANY_JOIN) ||
321271 !is_root) {
321272 return nullptr;
321273 }
321274
321275 // The expression must be an OR
321276 auto &conjunction = bindings[0].get().Cast<BoundConjunctionExpression>();
321277 if (conjunction.GetExpressionType() != ExpressionType::CONJUNCTION_OR) {
321278 return nullptr;
321279 }
321280
321281 // Must have at least one join-dependent AND expression
321282 auto &children = conjunction.children;
321283 bool eligible = false;
321284 for (const auto &child : children) {
321285 if (child->GetExpressionClass() == ExpressionClass::BOUND_CONJUNCTION &&
321286 child->GetExpressionType() == ExpressionType::CONJUNCTION_AND &&
321287 ExpressionReferencesMultipleTables(*child)) {
321288 eligible = true;
321289 break;
321290 }
321291 }
321292 if (!eligible) {
321293 return nullptr;
321294 }
321295
321296 // Extract all comparison expressions between column references and constants that are AND'ed together
321297 auto conjuncted_expressions = make_uniq_array<unordered_map<idx_t, unique_ptr<Expression>>>(children.size());
321298 for (idx_t child_idx = 0; child_idx < children.size(); child_idx++) {
321299 conjuncted_expressions[child_idx] = unordered_map<idx_t, unique_ptr<Expression>>();
321300 ExtractConjunctedExpressions(*children[child_idx], conjuncted_expressions[child_idx]);
321301 }
321302
321303 auto derived_filter = make_uniq<BoundConjunctionExpression>(ExpressionType::CONJUNCTION_AND);
321304 for (auto &entry : conjuncted_expressions[0]) {
321305 auto derived_entry_filter = make_uniq<BoundConjunctionExpression>(ExpressionType::CONJUNCTION_OR);
321306 derived_entry_filter->children.push_back(entry.second->Copy());
321307
321308 bool found = true;
321309 for (idx_t conj_idx = 1; conj_idx < children.size(); conj_idx++) {
321310 auto &other_entry = conjuncted_expressions[conj_idx];
321311 auto other_it = other_entry.find(entry.first);
321312 if (other_it == other_entry.end()) {
321313 found = false;
321314 break; // Expression does not appear in every conjuncted expression, cannot derive any restriction
321315 }
321316 derived_entry_filter->children.push_back(other_it->second->Copy());
321317 }
321318
321319 if (!found) {
321320 continue; // Expression must show up in every entry
321321 }
321322
321323 derived_filter->children.push_back(std::move(derived_entry_filter));
321324 }
321325
321326 if (derived_filter->children.empty()) {
321327 return nullptr; // Could not derive filters that can be pushed down
321328 }
321329
321330 // Add the derived expression to the original expression with an AND
321331 auto result = make_uniq_base<Expression, BoundConjunctionExpression>(ExpressionType::CONJUNCTION_AND);
321332 auto &result_conjunction = result->Cast<BoundConjunctionExpression>();
321333 result_conjunction.children.push_back(conjunction.Copy());
321334
321335 if (derived_filter->children.size() == 1) {
321336 result_conjunction.children.push_back(std::move(derived_filter->children[0]));
321337 } else {
321338 result_conjunction.children.push_back(std::move(derived_filter));
321339 }
321340 return result;
321341}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

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