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

Public Member Functions

 JoinFilterPushdownOptimizer (Optimizer &optimizer)
void VisitOperator (LogicalOperator &op) override
Public Member Functions inherited from duckdb::LogicalOperatorVisitor
virtual void VisitExpression (unique_ptr< Expression > *expression)

Static Public Member Functions

static void GetPushdownFilterTargets (LogicalOperator &op, vector< JoinFilterPushdownColumn > columns, vector< PushdownFilterTarget > &targets)
static bool IsFiltering (const unique_ptr< LogicalOperator > &op)
Static Public Member Functions inherited from duckdb::LogicalOperatorVisitor
static void EnumerateExpressions (LogicalOperator &op, const std::function< void(unique_ptr< Expression > *child)> &callback)

Private Member Functions

void GenerateJoinFilters (LogicalComparisonJoin &join)

Private Attributes

Optimizer & optimizer

Additional Inherited Members

Protected Member Functions inherited from duckdb::LogicalOperatorVisitor
void VisitOperatorChildren (LogicalOperator &op)
void VisitOperatorExpressions (LogicalOperator &op)
void VisitOperatorWithProjectionMapChildren (LogicalOperator &op)
 Alternatives for VisitOperatorChildren for operators that have a projection map.
void VisitChildOfOperatorWithProjectionMap (LogicalOperator &child, vector< idx_t > &projection_map)
virtual void VisitExpressionChildren (Expression &expression)
virtual unique_ptr< Expression > VisitReplace (BoundAggregateExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundBetweenExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundCaseExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundCastExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundColumnRefExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundComparisonExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundConjunctionExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundConstantExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundDefaultExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundFunctionExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundOperatorExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundReferenceExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundSubqueryExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundParameterExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundWindowExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundUnnestExpression &expr, unique_ptr< Expression > *expr_ptr)

Detailed Description

The JoinFilterPushdownOptimizer links comparison joins to data sources to enable dynamic execution-time filter pushdown

Constructor & Destructor Documentation

◆ JoinFilterPushdownOptimizer()

duckdb::JoinFilterPushdownOptimizer::JoinFilterPushdownOptimizer ( Optimizer & optimizer)
explicit
310759 : optimizer(optimizer) {
310760}

Member Function Documentation

◆ VisitOperator()

void duckdb::JoinFilterPushdownOptimizer::VisitOperator ( LogicalOperator & op)
overridevirtual

Reimplemented from duckdb::LogicalOperatorVisitor.

311053 {
311054 if (op.type == LogicalOperatorType::LOGICAL_COMPARISON_JOIN) {
311055 // comparison join - try to generate join filters (if possible)
311056 GenerateJoinFilters(op.Cast<LogicalComparisonJoin>());
311057 }
311058 LogicalOperatorVisitor::VisitOperator(op);
311059}

◆ GetPushdownFilterTargets()

void duckdb::JoinFilterPushdownOptimizer::GetPushdownFilterTargets ( LogicalOperator & op,
vector< JoinFilterPushdownColumn > columns,
vector< PushdownFilterTarget > & targets )
static
310799 {
310800 auto &probe_child = op;
310801 switch (probe_child.type) {
310802 case LogicalOperatorType::LOGICAL_LIMIT:
310803 case LogicalOperatorType::LOGICAL_FILTER:
310804 case LogicalOperatorType::LOGICAL_ORDER_BY:
310805 case LogicalOperatorType::LOGICAL_TOP_N:
310806 case LogicalOperatorType::LOGICAL_DISTINCT:
310807 case LogicalOperatorType::LOGICAL_COMPARISON_JOIN:
310808 case LogicalOperatorType::LOGICAL_CROSS_PRODUCT:
310809 // does not affect probe side - recurse into left child
310810 // FIXME: we can probably recurse into more operators here (e.g. window, unnest)
310811 GetPushdownFilterTargets(*probe_child.children[0], std::move(columns), targets);
310812 break;
310813 case LogicalOperatorType::LOGICAL_UNNEST: {
310814 auto &unnest = probe_child.Cast<LogicalUnnest>();
310815 // check if the filters apply to the unnest index
310816 for (auto &filter : columns) {
310817 if (filter.probe_column_index.table_index == unnest.unnest_index) {
310818 // the filter applies to the unnest index - bail out
310819 return;
310820 }
310821 }
310822 GetPushdownFilterTargets(*probe_child.children[0], std::move(columns), targets);
310823 break;
310824 }
310825 case LogicalOperatorType::LOGICAL_EXCEPT:
310826 case LogicalOperatorType::LOGICAL_INTERSECT:
310827 case LogicalOperatorType::LOGICAL_UNION: {
310828 auto &setop = probe_child.Cast<LogicalSetOperation>();
310829 // union
310830 // check if the filters apply to this table index
310831 for (auto &filter : columns) {
310832 if (filter.probe_column_index.table_index != setop.table_index) {
310833 // the filter does not apply to the union - bail-out
310834 return;
310835 }
310836 }
310837 for (auto &child : probe_child.children) {
310838 // rewrite the filters for each of the children of the union
310839 vector<JoinFilterPushdownColumn> child_columns;
310840 auto child_bindings = child->GetColumnBindings();
310841 child_columns.reserve(columns.size());
310842 for (auto &child_column : columns) {
310843 JoinFilterPushdownColumn new_col;
310844 new_col.probe_column_index = child_bindings[child_column.probe_column_index.column_index];
310845 child_columns.push_back(new_col);
310846 }
310847 // then recurse into the child
310848 GetPushdownFilterTargets(*child, std::move(child_columns), targets);
310849
310850 // for EXCEPT we can only recurse into the first (left) child
310851 if (probe_child.type == LogicalOperatorType::LOGICAL_EXCEPT) {
310852 break;
310853 }
310854 }
310855 break;
310856 }
310857 case LogicalOperatorType::LOGICAL_GET: {
310858 // found LogicalGet
310859 auto &get = probe_child.Cast<LogicalGet>();
310860 if (!get.function.filter_pushdown) {
310861 // filter pushdown is not supported - no need to consider this node
310862 return;
310863 }
310864 get.ResolveOperatorTypes();
310865 const auto bindings = get.GetColumnBindings();
310866 for (auto &filter : columns) {
310867 if (filter.probe_column_index.table_index != get.table_index) {
310868 // the filter does not apply to the probe side here - bail-out
310869 return;
310870 }
310871 // add storage type to columns
310872 for (idx_t i = 0; i < bindings.size(); i++) {
310873 if (filter.probe_column_index.column_index == bindings[i].column_index) {
310874 filter.storage_type = get.types[i];
310875 break;
310876 }
310877 }
310878 D_ASSERT(filter.storage_type != LogicalType::INVALID);
310879 }
310880 targets.emplace_back(get, std::move(columns));
310881 break;
310882 }
310883 case LogicalOperatorType::LOGICAL_PROJECTION: {
310884 // projection - check if we all of the expressions are only column references
310885 auto &proj = probe_child.Cast<LogicalProjection>();
310886 for (auto &filter : columns) {
310887 if (filter.probe_column_index.table_index != proj.table_index) {
310888 // index does not belong to this projection - bail-out
310889 return;
310890 }
310891 auto &expr = *proj.expressions[filter.probe_column_index.column_index];
310892 if (!PushdownJoinFilterExpression(expr, filter)) {
310893 // cannot push through this expression - bail-out
310894 return;
310895 }
310896 }
310897 GetPushdownFilterTargets(*probe_child.children[0], std::move(columns), targets);
310898 break;
310899 }
310900 case LogicalOperatorType::LOGICAL_AGGREGATE_AND_GROUP_BY: {
310901 // we can push filters through aggregates IF they all point to groups
310902 auto &aggr = probe_child.Cast<LogicalAggregate>();
310903 for (auto &filter : columns) {
310904 if (filter.probe_column_index.table_index != aggr.group_index) {
310905 // index does not refer to a group - bail-out
310906 return;
310907 }
310908 auto &expr = *aggr.groups[filter.probe_column_index.column_index];
310909 if (!PushdownJoinFilterExpression(expr, filter)) {
310910 // cannot push through this expression - bail-out
310911 return;
310912 }
310913 }
310914 GetPushdownFilterTargets(*probe_child.children[0], std::move(columns), targets);
310915 break;
310916 }
310917 default:
310918 // unsupported child type
310919 break;
310920 }
310921}
__host__ cudaTextureObject_t get() const noexcept
void filter(InputArray image, InputArray kernel, OutputArray output)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ IsFiltering()

bool duckdb::JoinFilterPushdownOptimizer::IsFiltering ( const unique_ptr< LogicalOperator > & op)
static
310923 {
310924 switch (op->type) {
310925 case LogicalOperatorType::LOGICAL_GET: {
310926 auto &get = op->Cast<LogicalGet>();
310927 return !get.table_filters.filters.empty();
310928 }
310929 case LogicalOperatorType::LOGICAL_FILTER: {
310930 return true;
310931 }
310932 case LogicalOperatorType::LOGICAL_TOP_N: {
310933 return true;
310934 }
310935 default:
310936 for (const unique_ptr<LogicalOperator> &child : op->children) {
310937 if (IsFiltering(child)) {
310938 return true;
310939 }
310940 }
310941 return false;
310942 }
310943}

◆ GenerateJoinFilters()

void duckdb::JoinFilterPushdownOptimizer::GenerateJoinFilters ( LogicalComparisonJoin & join)
private
310945 {
310946 switch (join.join_type) {
310947 case JoinType::MARK:
310948 case JoinType::SINGLE:
310949 case JoinType::LEFT:
310950 case JoinType::OUTER:
310951 case JoinType::ANTI:
310952 case JoinType::RIGHT_ANTI:
310953 case JoinType::RIGHT_SEMI:
310954 // cannot generate join filters for these join types
310955 // mark/single - cannot change cardinality of probe side
310956 // left/outer always need to include every row from probe side
310957 // FIXME: anti/right_anti - we could do this, but need to invert the join conditions
310958 return;
310959 default:
310960 break;
310961 }
310962 // re-order conditions here - otherwise this will happen later on and invalidate the indexes we generate
310964 auto pushdown_info = make_uniq<JoinFilterPushdownInfo>();
310965
310966 vector<JoinFilterPushdownColumn> pushdown_columns;
310967 for (idx_t cond_idx = 0; cond_idx < join.conditions.size(); cond_idx++) {
310968 auto &cond = join.conditions[cond_idx];
310969 switch (cond.comparison) {
310970 case ExpressionType::COMPARE_EQUAL:
310971 case ExpressionType::COMPARE_LESSTHAN:
310972 case ExpressionType::COMPARE_LESSTHANOREQUALTO:
310973 case ExpressionType::COMPARE_GREATERTHAN:
310974 case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
310975 break;
310976 case ExpressionType::COMPARE_NOT_DISTINCT_FROM:
310977 // TODO: Need OR predicates
310978 continue;
310979 default:
310980 continue;
310981 }
310982
310983 JoinFilterPushdownColumn pushdown_col;
310984 if (!PushdownJoinFilterExpression(*cond.left, pushdown_col)) {
310985 continue;
310986 }
310987
310988 pushdown_columns.push_back(pushdown_col);
310989 pushdown_info->join_condition.push_back(cond_idx);
310990 }
310991 if (pushdown_columns.empty()) {
310992 // could not generate any filters - bail-out
310993 return;
310994 }
310995 // recurse the query tree to find the LogicalGets in which we can push the filter info
310996 vector<PushdownFilterTarget> pushdown_filter_targets;
310997 GetPushdownFilterTargets(*join.children[0], pushdown_columns, pushdown_filter_targets);
310998 for (auto &target : pushdown_filter_targets) {
310999 auto &get = target.get;
311000 // pushdown info can be applied to this LogicalGet - push the dynamic table filter set
311001 if (!get.dynamic_filters) {
311002 get.dynamic_filters = make_shared_ptr<DynamicTableFilterSet>();
311003 }
311004
311005 JoinFilterPushdownFilter get_filter;
311006 get_filter.dynamic_filters = get.dynamic_filters;
311007 get_filter.columns = std::move(target.columns);
311008 pushdown_info->probe_info.push_back(std::move(get_filter));
311009 }
311010
311011 // Even if we cannot find any table sources in which we can push down filters,
311012 // we still initialize the aggregate states so that we have the possibility of doing a perfect hash join
311013 // TODO: Can ExpressionType::COMPARE_NOT_DISTINCT_FROM be used with perfect hash joins?
311014 const auto compute_aggregates_anyway = join.join_type == JoinType::INNER && join.conditions.size() == 1 &&
311015 pushdown_info->join_condition.size() == 1 &&
311016 join.conditions[0].comparison == ExpressionType::COMPARE_EQUAL &&
311017 TypeIsIntegral(join.conditions[0].right->return_type.InternalType());
311018 if (pushdown_info->probe_info.empty() && !compute_aggregates_anyway) {
311019 // no table sources found in which we can push down filters
311020 return;
311021 }
311022
311023 // set up the min/max aggregates for each of the filters
311024 vector<AggregateFunction> aggr_functions;
311025 aggr_functions.push_back(MinFunction::GetFunction());
311026 aggr_functions.push_back(MaxFunction::GetFunction());
311027 for (auto &join_condition : pushdown_info->join_condition) {
311028 for (auto &aggr : aggr_functions) {
311029 FunctionBinder function_binder(optimizer.GetContext());
311030 vector<unique_ptr<Expression>> aggr_children;
311031 aggr_children.push_back(join.conditions[join_condition].right->Copy());
311032 auto aggr_expr = function_binder.BindAggregateFunction(aggr, std::move(aggr_children), nullptr,
311033 AggregateType::NON_DISTINCT);
311034 if (aggr_expr->children.size() != 1) {
311035 // min/max with collation - not supported
311036 return;
311037 }
311038 pushdown_info->min_max_aggregates.push_back(std::move(aggr_expr));
311039 }
311040 }
311041 if (!pushdown_info->probe_info.empty()) {
311042 const auto &rhs_child = join.children[1];
311043 if (rhs_child->type == LogicalOperatorType::LOGICAL_DELIM_GET) {
311044 pushdown_info->build_side_has_filter = IsFiltering(join.children[0]);
311045 } else {
311046 pushdown_info->build_side_has_filter = IsFiltering(join.children[1]);
311047 }
311048 }
311049 // set up the filter pushdown in the join itself
311050 join.filter_pushdown = std::move(pushdown_info);
311051}
static void ReorderConditions(vector< JoinCondition > &conditions)
Re-order join conditions so that equality predicates are first, followed by other predicates.
Definition duckdb.cpp:183817
cv::String join(const cv::String &base, const cv::String &path)

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