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::JoinFilterPushdownInfo Struct Reference
Collaboration diagram for duckdb::JoinFilterPushdownInfo:

Public Member Functions

unique_ptr< JoinFilterGlobalState > GetGlobalState (ClientContext &context, const PhysicalOperator &op) const
unique_ptr< JoinFilterLocalState > GetLocalState (JoinFilterGlobalState &gstate) const
void Sink (DataChunk &chunk, JoinFilterLocalState &lstate) const
void Combine (JoinFilterGlobalState &gstate, JoinFilterLocalState &lstate) const
unique_ptr< DataChunk > Finalize (ClientContext &context, optional_ptr< JoinHashTable > ht, JoinFilterGlobalState &gstate, const PhysicalComparisonJoin &op) const
unique_ptr< DataChunk > FinalizeMinMax (JoinFilterGlobalState &gstate) const
unique_ptr< DataChunk > FinalizeFilters (ClientContext &context, optional_ptr< JoinHashTable > ht, const PhysicalComparisonJoin &op, unique_ptr< DataChunk > final_min_max, bool is_perfect_hashtable) const

Public Attributes

vector< idx_t > join_condition
 The join condition indexes for which we compute the min/max aggregates.
vector< JoinFilterPushdownFilter > probe_info
 The probes to push the filter into.
vector< unique_ptr< Expression > > min_max_aggregates
 Min/Max aggregates.
bool build_side_has_filter
 Whether the build side has a filter -> we might be able to push down a bloom filter into the probe side.

Private Member Functions

void PushInFilter (const JoinFilterPushdownFilter &info, JoinHashTable &ht, const PhysicalOperator &op, idx_t filter_idx, idx_t filter_col_idx) const
void PushBloomFilter (const JoinFilterPushdownFilter &info, JoinHashTable &ht, const PhysicalOperator &op, idx_t filter_col_idx) const
bool CanUseInFilter (const ClientContext &context, optional_ptr< JoinHashTable > ht, const ExpressionType &cmp) const
bool CanUseBloomFilter (const ClientContext &context, optional_ptr< JoinHashTable > ht, const PhysicalComparisonJoin &op, const ExpressionType &cmp, bool is_perfect_hashtable) const

Member Function Documentation

◆ GetGlobalState()

unique_ptr< JoinFilterGlobalState > duckdb::JoinFilterPushdownInfo::GetGlobalState ( ClientContext & context,
const PhysicalOperator & op ) const
184333 {
184334 // clear any previously set filters
184335 // we can have previous filters for this operator in case of e.g. recursive CTEs
184336 for (auto &info : probe_info) {
184337 info.dynamic_filters->ClearFilters(op);
184338 }
184339 auto result = make_uniq<JoinFilterGlobalState>();
184340 result->global_aggregate_state =
184341 make_uniq<GlobalUngroupedAggregateState>(BufferAllocator::Get(context), min_max_aggregates);
184342 return result;
184343}
vector< JoinFilterPushdownFilter > probe_info
The probes to push the filter into.
Definition duckdb.cpp:147183
vector< unique_ptr< Expression > > min_max_aggregates
Min/Max aggregates.
Definition duckdb.cpp:147185

◆ GetLocalState()

unique_ptr< JoinFilterLocalState > duckdb::JoinFilterPushdownInfo::GetLocalState ( JoinFilterGlobalState & gstate) const
184424 {
184425 auto result = make_uniq<JoinFilterLocalState>();
184426 result->local_aggregate_state = make_uniq<LocalUngroupedAggregateState>(*gstate.global_aggregate_state);
184427 return result;
184428}

◆ Sink()

void duckdb::JoinFilterPushdownInfo::Sink ( DataChunk & chunk,
JoinFilterLocalState & lstate ) const
184529 {
184530 // if we are pushing any filters into a probe-side, compute the min/max over the columns that we are pushing
184531 for (idx_t pushdown_idx = 0; pushdown_idx < join_condition.size(); pushdown_idx++) {
184532 auto join_condition_idx = join_condition[pushdown_idx];
184533 for (idx_t i = 0; i < 2; i++) {
184534 idx_t aggr_idx = pushdown_idx * 2 + i;
184535 lstate.local_aggregate_state->Sink(chunk, join_condition_idx, aggr_idx);
184536 }
184537 }
184538}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
vector< idx_t > join_condition
The join condition indexes for which we compute the min/max aggregates.
Definition duckdb.cpp:147181

◆ Combine()

void duckdb::JoinFilterPushdownInfo::Combine ( JoinFilterGlobalState & gstate,
JoinFilterLocalState & lstate ) const
184564 {
184565 gstate.global_aggregate_state->Combine(*lstate.local_aggregate_state);
184566}

◆ Finalize()

unique_ptr< DataChunk > duckdb::JoinFilterPushdownInfo::Finalize ( ClientContext & context,
optional_ptr< JoinHashTable > ht,
JoinFilterGlobalState & gstate,
const PhysicalComparisonJoin & op ) const
185114 {
185115 auto final_min_max = FinalizeMinMax(gstate);
185116 return FinalizeFilters(context, ht, op, std::move(final_min_max), false);
185117}

◆ FinalizeMinMax()

unique_ptr< DataChunk > duckdb::JoinFilterPushdownInfo::FinalizeMinMax ( JoinFilterGlobalState & gstate) const
185006 {
185007 // finalize the min/max aggregates
185008 vector<LogicalType> min_max_types;
185009 for (auto &aggr_expr : min_max_aggregates) {
185010 min_max_types.push_back(aggr_expr->return_type);
185011 }
185012 auto final_min_max = make_uniq<DataChunk>();
185013 final_min_max->Initialize(Allocator::DefaultAllocator(), min_max_types);
185014
185015 gstate.global_aggregate_state->Finalize(*final_min_max);
185016 return final_min_max;
185017}

◆ FinalizeFilters()

unique_ptr< DataChunk > duckdb::JoinFilterPushdownInfo::FinalizeFilters ( ClientContext & context,
optional_ptr< JoinHashTable > ht,
const PhysicalComparisonJoin & op,
unique_ptr< DataChunk > final_min_max,
bool is_perfect_hashtable ) const
185022 {
185023 if (probe_info.empty()) {
185024 return final_min_max; // There are not table souces in which we can push down filters
185025 }
185026
185027 // create a filter for each of the aggregates
185028 for (idx_t filter_idx = 0; filter_idx < join_condition.size(); filter_idx++) {
185029 const auto cmp = op.conditions[join_condition[filter_idx]].comparison;
185030 for (auto &info : probe_info) {
185031 const auto &pushdown_column = info.columns[filter_idx];
185032 auto &filter_col_idx = pushdown_column.probe_column_index.column_index;
185033 auto min_idx = filter_idx * 2;
185034 auto max_idx = min_idx + 1;
185035
185036 auto min_val = final_min_max->data[min_idx].GetValue(0);
185037 auto max_val = final_min_max->data[max_idx].GetValue(0);
185038
185039 // Cast to storage type, skip if fails
185040 D_ASSERT(pushdown_column.storage_type.IsValid());
185041 if (!min_val.DefaultTryCastAs(pushdown_column.storage_type)) {
185042 continue;
185043 }
185044 if (!max_val.DefaultTryCastAs(pushdown_column.storage_type)) {
185045 continue;
185046 }
185047
185048 if (min_val.IsNull() || max_val.IsNull()) {
185049 // min/max is NULL
185050 // this can happen in case all values in the RHS column are NULL, but they are still pushed into the
185051 // hash table e.g. because they are part of a RIGHT join
185052 continue;
185053 }
185054 // if the HT is small we can generate a complete "OR" filter
185055 // but only if the join condition is equality.
185056 if (ht && CanUseInFilter(context, ht, cmp)) {
185057 PushInFilter(info, *ht, op, filter_idx, filter_col_idx);
185058 }
185059 if (Value::NotDistinctFrom(min_val, max_val)) {
185060 // min = max - single value
185061 // generate a "one-sided" comparison filter for the LHS
185062 // Note that this also works for equalities.
185063 auto constant_filter = make_uniq<ConstantFilter>(cmp, std::move(min_val));
185064 info.dynamic_filters->PushFilter(op, filter_col_idx, std::move(constant_filter));
185065 } else {
185066 // min != max - generate a range filter or bloom filter + optional range filter
185067 // for non-equalities, the range must be half-open
185068 // e.g., for lhs < rhs we can only use lhs <= max
185069
185070 switch (cmp) {
185071 case ExpressionType::COMPARE_EQUAL:
185072 case ExpressionType::COMPARE_GREATERTHAN:
185073 case ExpressionType::COMPARE_GREATERTHANOREQUALTO: {
185074 auto greater_equals =
185075 make_uniq<ConstantFilter>(ExpressionType::COMPARE_GREATERTHANOREQUALTO, std::move(min_val));
185076 auto optional_greater_equals = make_uniq<SelectivityOptionalFilter>(
185077 std::move(greater_equals), SelectivityOptionalFilter::MIN_MAX_THRESHOLD,
185078 SelectivityOptionalFilter::MIN_MAX_CHECK_N);
185079 info.dynamic_filters->PushFilter(op, filter_col_idx, std::move(optional_greater_equals));
185080 break;
185081 }
185082 default:
185083 break;
185084 }
185085 switch (cmp) {
185086 case ExpressionType::COMPARE_EQUAL:
185087 case ExpressionType::COMPARE_LESSTHAN:
185088 case ExpressionType::COMPARE_LESSTHANOREQUALTO: {
185089 auto less_equals =
185090 make_uniq<ConstantFilter>(ExpressionType::COMPARE_LESSTHANOREQUALTO, std::move(max_val));
185091 auto optional_less_equals = make_uniq<SelectivityOptionalFilter>(
185092 std::move(less_equals), SelectivityOptionalFilter::MIN_MAX_THRESHOLD,
185093 SelectivityOptionalFilter::MIN_MAX_CHECK_N);
185094 info.dynamic_filters->PushFilter(op, filter_col_idx, std::move(optional_less_equals));
185095 break;
185096 }
185097 default:
185098 break;
185099 }
185100
185101 auto condition_type = op.conditions[join_condition[filter_idx]].left->return_type;
185102 bool has_cast = condition_type != pushdown_column.storage_type;
185103 if (!has_cast && ht && CanUseBloomFilter(context, ht, op, cmp, is_perfect_hashtable)) {
185104 PushBloomFilter(info, *ht, op, filter_col_idx);
185105 }
185106 }
185107 }
185108 }
185109 return final_min_max;
185110}
static DUCKDB_API bool NotDistinctFrom(const Value &lvalue, const Value &rvalue)
Returns true if the values are not distinct from each other, following SQL semantics for NOT DISTINCT...
Definition duckdb.cpp:134034

◆ PushInFilter()

void duckdb::JoinFilterPushdownInfo::PushInFilter ( const JoinFilterPushdownFilter & info,
JoinHashTable & ht,
const PhysicalOperator & op,
idx_t filter_idx,
idx_t filter_col_idx ) const
private
184927 {
184928 // generate a "OR" filter (i.e. x=1 OR x=535 OR x=997)
184929 // first scan the entire vector at the probe side
184930 auto build_idx = join_condition[filter_idx];
184931 Vector tuples_addresses(LogicalType::POINTER, ht.Count()); // allocate space for all the tuples
184932 Vector build_vector(ht.layout_ptr->GetTypes()[build_idx], ht.Count());
184933 auto key_count = ht.ScanKeyColumn(tuples_addresses, build_vector, build_idx);
184934 if (key_count == 0) {
184935 return;
184936 }
184937
184938 // generate the OR-clause - note that we only need to consider unique values here (so we use a seT)
184939 value_set_t unique_ht_values;
184940 for (idx_t k = 0; k < key_count; k++) {
184941 // Cast to storage type, only insert if it succeeds
184942 auto value = build_vector.GetValue(k);
184943 if (!value.DefaultTryCastAs(info.columns[filter_idx].storage_type)) {
184944 return; // it's all or nothing sadly
184945 }
184946 unique_ht_values.insert(value);
184947 }
184948 vector<Value> in_list(unique_ht_values.begin(), unique_ht_values.end());
184949
184950 // generating the OR filter only makes sense if the range is
184951 // not dense and that the range does not contain NULL
184952 // i.e. if we have the values [0, 1, 2, 3, 4] - the min/max is fully equivalent to the OR filter
184953 if (FilterCombiner::ContainsNull(in_list) || FilterCombiner::IsDenseRange(in_list)) {
184954 return;
184955 }
184956
184957 // generate the OR filter
184958 auto in_filter = make_uniq<InFilter>(std::move(in_list));
184959
184960 // we push the OR filter as an OptionalFilter so that we can use it for zonemap pruning only
184961 // the IN-list is expensive to execute otherwise
184962 auto filter = make_uniq<OptionalFilter>(std::move(in_filter));
184963 info.dynamic_filters->PushFilter(op, filter_col_idx, std::move(filter));
184964}
static bool IsDenseRange(vector< Value > &in_list)
Returns whether or not a set of integral values is a dense range (i.e. 1, 2, 3, 4,...
Definition duckdb.cpp:308572
void filter(InputArray image, InputArray kernel, OutputArray output)

◆ PushBloomFilter()

void duckdb::JoinFilterPushdownInfo::PushBloomFilter ( const JoinFilterPushdownFilter & info,
JoinHashTable & ht,
const PhysicalOperator & op,
idx_t filter_col_idx ) const
private
184993 {
184994 // If the nulls are equal, we let nulls pass. If not, we filter them
184995 auto filters_null_values = !ht.NullValuesAreEqual(0);
184996 const auto key_name = ht.conditions[0].right->ToString();
184997 const auto key_type = ht.conditions[0].left->return_type;
184998 auto bf_filter = make_uniq<BFTableFilter>(ht.GetBloomFilter(), filters_null_values, key_name, key_type);
184999 ht.SetBuildBloomFilter(true);
185000
185001 auto opt_bf_filter = make_uniq<SelectivityOptionalFilter>(
185002 std::move(bf_filter), SelectivityOptionalFilter::BF_THRESHOLD, SelectivityOptionalFilter::BF_CHECK_N);
185003 info.dynamic_filters->PushFilter(op, filter_col_idx, std::move(opt_bf_filter));
185004}

◆ CanUseInFilter()

bool duckdb::JoinFilterPushdownInfo::CanUseInFilter ( const ClientContext & context,
optional_ptr< JoinHashTable > ht,
const ExpressionType & cmp ) const
private
184921 {
184922 auto dynamic_or_filter_threshold = Settings::Get<DynamicOrFilterThresholdSetting>(context);
184923 return ht && ht->Count() > 1 && ht->Count() <= dynamic_or_filter_threshold && cmp == ExpressionType::COMPARE_EQUAL;
184924}

◆ CanUseBloomFilter()

bool duckdb::JoinFilterPushdownInfo::CanUseBloomFilter ( const ClientContext & context,
optional_ptr< JoinHashTable > ht,
const PhysicalComparisonJoin & op,
const ExpressionType & cmp,
bool is_perfect_hashtable ) const
private
184968 {
184969 if (!ht) {
184970 return false;
184971 }
184972
184973 // with a perfect hashtable we expect good min/max pruning, so we don't want the bloom filter
184974 if (is_perfect_hashtable) {
184975 return false;
184976 }
184977
184978 // bf is only supported for single key joins with equality condition as the Filter API only allows
184979 // single-column filters so far
184980 const bool can_use_bf = ht->conditions.size() == 1 && cmp == ExpressionType::COMPARE_EQUAL;
184981
184982 // building the bloom filter is costly on the build to make probing faster, so only use it if there are
184983 // more probing tuples than build tuples
184984 const double build_to_probe_ratio =
184985 static_cast<double>(op.children[0].get().estimated_cardinality) / static_cast<double>(ht->Count());
184986 const bool probe_larger_then_build = build_to_probe_ratio > 1.0;
184987
184988 // only use bloom filter if there is no in-filter already
184989 return can_use_bf && build_side_has_filter && probe_larger_then_build;
184990}
bool build_side_has_filter
Whether the build side has a filter -> we might be able to push down a bloom filter into the probe si...
Definition duckdb.cpp:147188

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