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

Classes

struct  MaterializedCTEInfo
 CTE info needed for creating OR filters that can be pushed down. More...

Public Member Functions

 CTEFilterPusher (Optimizer &optimizer)
unique_ptr< LogicalOperator > Optimize (unique_ptr< LogicalOperator > op)
 Finds all materialized CTEs and pushes OR filters into them (if applicable).

Private Member Functions

void FindCandidates (LogicalOperator &op)
 Find all materialized CTEs and their refs.
void PushFilterIntoCTE (MaterializedCTEInfo &info)
 Creates an OR filter and pushes it into a materialized CTE.

Private Attributes

Optimizer & optimizer
 The optimizer.
InsertionOrderPreservingMap< unique_ptr< MaterializedCTEInfo > > cte_info_map
 Mapping from CTE index to CTE info, order preserving so deepest CTEs are done first.

Constructor & Destructor Documentation

◆ CTEFilterPusher()

duckdb::CTEFilterPusher::CTEFilterPusher ( Optimizer & optimizer)
explicit
306905 : optimizer(optimizer_p) {
306906}
Optimizer & optimizer
The optimizer.
Definition duckdb.cpp:306771

Member Function Documentation

◆ Optimize()

unique_ptr< LogicalOperator > duckdb::CTEFilterPusher::Optimize ( unique_ptr< LogicalOperator > op)

Finds all materialized CTEs and pushes OR filters into them (if applicable).

306908 {
306909 FindCandidates(*op);
306910 auto ctes = std::move(cte_info_map);
306911
306912 // Iterate once over all materialized CTEs
306913 for (auto it = ctes.rbegin(); it != ctes.rend(); it++) {
306914 if (!it->second->all_cte_refs_are_filtered) {
306915 continue;
306916 }
306917
306918 // The cte_info_map must be reconstructed each time.
306919 // Changes to the plan otherwise break the non-unique_ptr references.
306920 cte_info_map = InsertionOrderPreservingMap<unique_ptr<MaterializedCTEInfo>>();
306921 FindCandidates(*op);
306922
306923 PushFilterIntoCTE(*cte_info_map[it->first]);
306924 }
306925 return op;
306926}
void PushFilterIntoCTE(MaterializedCTEInfo &info)
Creates an OR filter and pushes it into a materialized CTE.
Definition duckdb.cpp:306958
void FindCandidates(LogicalOperator &op)
Find all materialized CTEs and their refs.
Definition duckdb.cpp:306928
InsertionOrderPreservingMap< unique_ptr< MaterializedCTEInfo > > cte_info_map
Mapping from CTE index to CTE info, order preserving so deepest CTEs are done first.
Definition duckdb.cpp:306773
Here is the call graph for this function:

◆ FindCandidates()

void duckdb::CTEFilterPusher::FindCandidates ( LogicalOperator & op)
private

Find all materialized CTEs and their refs.

306928 {
306929 if (op.type == LogicalOperatorType::LOGICAL_MATERIALIZED_CTE) {
306930 // We encountered a new CTE, add it to the map
306931 auto key = to_string(op.Cast<LogicalMaterializedCTE>().table_index);
306932 auto value = make_uniq<MaterializedCTEInfo>(op);
306933
306934 cte_info_map.insert(key, std::move(value));
306935 } else if (op.type == LogicalOperatorType::LOGICAL_FILTER &&
306936 op.children[0]->type == LogicalOperatorType::LOGICAL_CTE_REF) {
306937 // We encountered a filtered CTE ref, update the according CTE info
306938 auto &cte_ref = op.children[0]->Cast<LogicalCTERef>();
306939 auto it = cte_info_map.find(to_string(cte_ref.cte_index));
306940 if (it != cte_info_map.end()) {
306941 it->second->filters.push_back(op);
306942 }
306943 return;
306944 } else if (op.type == LogicalOperatorType::LOGICAL_CTE_REF) {
306945 // We encountered a CTE ref without a filter on top, so we can't do the optimization
306946 auto &cte_ref = op.Cast<LogicalCTERef>();
306947 auto it = cte_info_map.find(to_string(cte_ref.cte_index));
306948 if (it != cte_info_map.end()) {
306949 it->second->all_cte_refs_are_filtered = false;
306950 }
306951 return;
306952 }
306953 for (auto &child : op.children) {
306954 FindCandidates(*child);
306955 }
306956}
std::string to_string(const T &value)
Definition duckdb.cpp:19425
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PushFilterIntoCTE()

void duckdb::CTEFilterPusher::PushFilterIntoCTE ( MaterializedCTEInfo & info)
private

Creates an OR filter and pushes it into a materialized CTE.

306958 {
306959 D_ASSERT(info.materialized_cte.type == LogicalOperatorType::LOGICAL_MATERIALIZED_CTE);
306960 if (info.filters.empty()) {
306961 return;
306962 }
306963
306964 // Create an OR expression with all the filters on all references of the CTE
306965 unique_ptr<Expression> outer_expr;
306966 for (auto &filter : info.filters) {
306967 D_ASSERT(filter.get().type == LogicalOperatorType::LOGICAL_FILTER);
306968
306969 auto old_bindings = filter.get().children[0]->GetColumnBindings();
306970 auto new_bindings = info.materialized_cte.children[0]->GetColumnBindings();
306971 D_ASSERT(old_bindings.size() == new_bindings.size());
306972
306973 ColumnBindingReplacer replacer;
306974 replacer.replacement_bindings.reserve(old_bindings.size());
306975 for (idx_t i = 0; i < old_bindings.size(); i++) {
306976 replacer.replacement_bindings.emplace_back(old_bindings[i], new_bindings[i]);
306977 }
306978
306979 // We copy the filters and replace the CTE reference bindings with the bindings in the CTE definition
306980 unique_ptr<Expression> inner_expr;
306981 for (auto &filter_expr : filter.get().expressions) {
306982 auto filter_expr_copy = filter_expr->Copy();
306983 replacer.VisitExpression(&filter_expr_copy);
306984 if (inner_expr) {
306985 inner_expr = make_uniq<BoundConjunctionExpression>(ExpressionType::CONJUNCTION_AND,
306986 std::move(inner_expr), std::move(filter_expr_copy));
306987 } else {
306988 inner_expr = std::move(filter_expr_copy);
306989 }
306990 }
306991
306992 if (outer_expr) {
306993 outer_expr = make_uniq<BoundConjunctionExpression>(ExpressionType::CONJUNCTION_OR, std::move(outer_expr),
306994 std::move(inner_expr));
306995 } else {
306996 outer_expr = std::move(inner_expr);
306997 }
306998 }
306999
307000 // Add the filter on top of the CTE definition and split the predicates
307001 auto new_cte = make_uniq_base<LogicalOperator, LogicalFilter>(std::move(outer_expr));
307002 LogicalFilter::SplitPredicates(new_cte->Cast<LogicalFilter>().expressions);
307003
307004 // Rewrite the operator expressions before adding the child op (children should be rewritten already)
307005 optimizer.rewriter.VisitOperator(*new_cte);
307006 new_cte->children.push_back(std::move(info.materialized_cte.children[0]));
307007
307008 // Push down the filter
307009 FilterPushdown pushdown(optimizer);
307010 new_cte = pushdown.Rewrite(std::move(new_cte));
307011
307012 info.materialized_cte.children[0] = std::move(new_cte);
307013}
void filter(InputArray image, InputArray kernel, OutputArray output)
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:

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