Repository navigation
Conversation
|
Workflow [PR], commit [e047b98] Summary: ❌
AI ReviewSummaryThis PR adds numeric min/max support to Missing context / blind spots
Findings
Final Verdict |
|
grace_hash_join.xml does SELECT sum(n) FROM (SELECT number * 2 AS n FROM numbers_mt(10000000)) AS lhs JOIN (SELECT number * 3 AS n FROM numbers_mt(10000000)) AS rhs USING (n) SETTINGS {settings} FORMAT NullSo we join numeric columns, the build side has high cardinality (i.e. the set representation changes to bloom filter + minmax). On the probe side, the filter lets 1/3 of the tuples pass and 2/3 not. This is below |
| DECLARE(Double, join_runtime_filter_pass_ratio_threshold_for_disabling, 0.7, "If ratio of passed rows to checked rows is greater than this threshold the runtime filter is considered as poorly performing and is disabled for the next `join_runtime_filter_blocks_to_skip_before_reenabling` blocks to reduce the overhead.", 0) \ | ||
| DECLARE(UInt64, join_runtime_filter_blocks_to_skip_before_reenabling, 30, "Number of blocks that are skipped before trying to dynamically re-enable a runtime filter that previously was disabled due to poor filtering ratio.", 0) \ | ||
| DECLARE(Double, join_runtime_bloom_filter_max_ratio_of_set_bits, 0.7, "If the number of set bits in a runtime bloom filter exceeds this ratio the filter is completely disabled to reduce the overhead.", 0) \ | ||
| DECLARE(Bool, join_runtime_filter_use_minmax, false, "Enable using minmax runtime filters that keep just minimum and maximum values to avoid unnecessary bloom filter lookups.", 0) \ |
There was a problem hiding this comment.
"keep" --> "test"/"probe"/"check"
| /// when the number of unique values exceeds the limit. | ||
| /// It is used for numeric columns only. | ||
| /// The minmax range allows to quickly filter out values that are outside of the observed min and max values, | ||
| /// which can be beneficial for avoiding unnecessary bloom filter lookups. |
There was a problem hiding this comment.
With the min max filter being the third runtime filter implementation we could consider to break the inheritance hierarchy into a composition and variant in the mid- to long-term.
This way we can keep them independent by modelling the transitions and parallel lifetimes explicitly outside the class definition:
class ExactContainsRuntimeFilter : public RuntimeFilterBase<false>;
class ExactNotContainsRuntimeFilter : public RuntimeFilterBase<true>;
class BloomFilterRuntimeFilter : public IRuntimeFilter;
class MinMaxRuntimeFilter : public IRuntimeFilter;
class ApproximateNumericContainsRuntimeFilters : public IRuntimeFilter{
BloomFilterRuntimeFilter bloomFilter;
MinMaxRuntimeFilter minMax;
};
using NumericContainsRuntimeFilter = std::variant<
ExactContainsRuntimeFilter,
ApproximateNumericContainsRuntimeFilters,
MinMaxRuntimeFilter>;
ApproximateNumericContainsRuntimeFilters toApproximate(const ExactContainsRuntimeFilter&);
MinMaxRuntimeFilter removeBloomFilter(const ApproximateNumericContainsRuntimeFilters&);
| /// It is used for numeric columns only. | ||
| /// The minmax range allows to quickly filter out values that are outside of the observed min and max values, | ||
| /// which can be beneficial for avoiding unnecessary bloom filter lookups. | ||
| template <typename T> |
There was a problem hiding this comment.
Should we constrain the template parameter T to numeric types or explicitly to the four instantiations that we got in RuntimeFilterLookup.cpp:
template class ApproximateNumericRuntimeFilter<UInt64>;
template class ApproximateNumericRuntimeFilter<Int64>;
template class ApproximateNumericRuntimeFilter<Float32>;
template class ApproximateNumericRuntimeFilter<Float64>;
Even though it does not make a difference now, it'll signal to readers already here that this runtime filter implementation is for these four numerics only at the moment.
In RuntimeFilterLookup.cpp:111 too we got a function template getColumnValue() which is not constrained and defaults to the Float64 code path for any non-numeric T. Would this raise a runtime error?
template <typename T>
T getColumnValue(const IColumn & column, size_t row);
|
@rschu1ze asked how two simple integer comparisons can increase runtimes by 33%. Measured answer: on a Screen on adapted TPC-H SF10 (dbgen data,
This bears on the gating in this PR. Removing the hashing instead of reducing itSince the cost is the hashing itself, an exact representation removes it. I gave the adaptive filter a Paired A/B against master
The A/A null arm shows no effect on any query in either suite (worst 2.5%). A single-pass screen over Correctness: all 99 TPC-DS and 23 TPC-H queries give identical sorted answer digests on the two Limitations
Prototype diff against rtbitset.patchdiff --git a/src/Processors/QueryPlan/RuntimeFilterLookup.cpp b/src/Processors/QueryPlan/RuntimeFilterLookup.cpp
index 580de0812e8..0dcdc9e1a0a 100644
--- a/src/Processors/QueryPlan/RuntimeFilterLookup.cpp
+++ b/src/Processors/QueryPlan/RuntimeFilterLookup.cpp
@@ -19,6 +19,10 @@
#include <Common/logger_useful.h>
#include <Common/ProfileEvents.h>
#include <algorithm>
+#include <type_traits>
+#include <limits>
+#include <bit>
+#include <Columns/ColumnVector.h>
#include <cmath>
#include <optional>
#include <vector>
@@ -287,6 +291,114 @@ UInt64 growBloomFilterBytes(UInt64 distinct_keys, UInt64 hash_functions, UInt64
const double clamped_bloom_filter_bytes = std::clamp(ideal_bloom_filter_bytes, 0.0, static_cast<double>(MAX_STATS_SIZED_BLOOM_FILTER_BYTES));
return std::max(static_cast<UInt64>(clamped_bloom_filter_bytes), default_bloom_filter_bytes);
}
+
+constexpr UInt64 BITSET_WORD_BITS = 64;
+
+/// Native integer keys are the ones that map one to one onto a dense bit index. Nullable and
+/// LowCardinality types are not native integers here, so they keep the exact-Set path as before.
+bool isDenseBitsetKeyType(const DataTypePtr & type)
+{
+ const WhichDataType which(type);
+ return which.isNativeInt() || which.isNativeUInt();
+}
+
+/// Align down to a word boundary. Two's complement masking also floors negative values.
+Int64 alignDownToWord(Int64 value)
+{
+ return static_cast<Int64>(static_cast<UInt64>(value) & ~(BITSET_WORD_BITS - 1));
+}
+
+/// Calls `op` with the raw data array of a native integer column. Returns false for anything else
+/// (const, sparse, or a non-vector column), so callers can use a generic fallback.
+template <typename Op>
+bool dispatchNativeIntColumn(const IColumn & column, Op && op)
+{
+#define CHPERF_DISPATCH_NATIVE_INT(TYPE) \
+ if (const auto * typed = typeid_cast<const ColumnVector<TYPE> *>(&column)) \
+ { \
+ op(typed->getData()); \
+ return true; \
+ }
+ CHPERF_DISPATCH_NATIVE_INT(UInt8)
+ CHPERF_DISPATCH_NATIVE_INT(UInt16)
+ CHPERF_DISPATCH_NATIVE_INT(UInt32)
+ CHPERF_DISPATCH_NATIVE_INT(UInt64)
+ CHPERF_DISPATCH_NATIVE_INT(Int8)
+ CHPERF_DISPATCH_NATIVE_INT(Int16)
+ CHPERF_DISPATCH_NATIVE_INT(Int32)
+ CHPERF_DISPATCH_NATIVE_INT(Int64)
+#undef CHPERF_DISPATCH_NATIVE_INT
+ return false;
+}
+
+template <typename Op>
+bool dispatchNativeIntMutableColumn(IColumn & column, Op && op)
+{
+#define CHPERF_DISPATCH_NATIVE_INT_MUT(TYPE) \
+ if (auto * typed = typeid_cast<ColumnVector<TYPE> *>(&column)) \
+ { \
+ op(typed->getData()); \
+ return true; \
+ }
+ CHPERF_DISPATCH_NATIVE_INT_MUT(UInt8)
+ CHPERF_DISPATCH_NATIVE_INT_MUT(UInt16)
+ CHPERF_DISPATCH_NATIVE_INT_MUT(UInt32)
+ CHPERF_DISPATCH_NATIVE_INT_MUT(UInt64)
+ CHPERF_DISPATCH_NATIVE_INT_MUT(Int8)
+ CHPERF_DISPATCH_NATIVE_INT_MUT(Int16)
+ CHPERF_DISPATCH_NATIVE_INT_MUT(Int32)
+ CHPERF_DISPATCH_NATIVE_INT_MUT(Int64)
+#undef CHPERF_DISPATCH_NATIVE_INT_MUT
+ return false;
+}
+
+/// Envelope of a native integer column in Int64 space. Returns false when the column is not a
+/// native integer vector, or when an unsigned value does not fit Int64 - the bit index is computed
+/// with modular arithmetic, but the *range* bookkeeping needs an ordered signed interval.
+bool nativeIntColumnEnvelope(const IColumn & column, Int64 & out_min, Int64 & out_max)
+{
+ bool ok = false;
+ bool representable = true;
+ bool first = true;
+ Int64 min_value = 0;
+ Int64 max_value = 0;
+ ok = dispatchNativeIntColumn(column, [&](const auto & data)
+ {
+ using T = std::decay_t<decltype(data[0])>;
+ for (const auto value : data)
+ {
+ const Int64 as_int = static_cast<Int64>(value);
+ if constexpr (std::is_unsigned_v<T>)
+ {
+ if (as_int < 0)
+ {
+ representable = false;
+ return;
+ }
+ }
+ if (first)
+ {
+ min_value = as_int;
+ max_value = as_int;
+ first = false;
+ }
+ else
+ {
+ min_value = std::min(min_value, as_int);
+ max_value = std::max(max_value, as_int);
+ }
+ }
+ });
+ if (!ok || !representable || first)
+ return false;
+ /// Keep the interval away from the Int64 edges so widening it cannot wrap.
+ static constexpr Int64 SAFE_BOUND = std::numeric_limits<Int64>::max() / 4;
+ if (min_value < -SAFE_BOUND || max_value > SAFE_BOUND)
+ return false;
+ out_min = min_value;
+ out_max = max_value;
+ return true;
+}
}
void ExactContainsRuntimeFilter::merge(const IRuntimeFilter * source)
@@ -359,7 +471,13 @@ void ApproximateRuntimeFilter::insert(ColumnPtr values)
if (inserts_are_finished)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Trying to insert into runtime filter after it was marked as finished");
- if (bloom_filter)
+ if (bitset_active)
+ {
+ /// Bitset mode dropped the values; track the envelope here.
+ updateRange(*values);
+ insertIntoBitset(values);
+ }
+ else if (bloom_filter)
{
/// Bloom mode dropped the values; track the envelope here.
updateRange(*values);
@@ -372,13 +490,22 @@ void ApproximateRuntimeFilter::insert(ColumnPtr values)
Base::insert(std::move(values));
- if (isFull())
+ if (isFull() && !tryStartBitset())
switchToBloomFilter();
}
}
void ApproximateRuntimeFilter::finishInsertImpl()
{
+ if (bitset_active)
+ {
+ /// Nothing to check: the bitset has no false positives, so the only reason to give up on it
+ /// is poor real selectivity, which the shared pass-ratio heuristic already measures on the
+ /// probe side. Bit density would be the wrong signal - a dense set over a narrow range can
+ /// still reject almost every probe row.
+ return;
+ }
+
if (bloom_filter)
{
checkBloomFilterWorthiness();
@@ -400,9 +527,17 @@ void ApproximateRuntimeFilter::merge(const IRuntimeFilter * source)
if (source_typed->bloom_filter)
{
+ if (bitset_active)
+ switchFromBitsetToBloomFilter();
switchToBloomFilter();
mergeBloomFilters(*bloom_filter, *source_typed->bloom_filter);
}
+ else if (source_typed->bitset_active)
+ {
+ /// A bitset holds its keys exactly, so they can be replayed through the normal insert path,
+ /// which keeps this filter in whatever representation it is already using.
+ insert(source_typed->bitsetValuesColumn());
+ }
else
{
insert(source_typed->getValuesColumn());
@@ -467,6 +602,49 @@ ColumnPtr ApproximateRuntimeFilter::findImpl(const ColumnWithTypeAndName & value
{
chassert(inserts_are_finished);
+ if (bitset_active)
+ {
+ const size_t rows = values.column->size();
+ auto dst = ColumnVector<UInt8>::create();
+ auto & dst_data = dst->getData();
+ dst_data.resize(rows);
+
+ ColumnPtr probe = values.column->convertToFullColumnIfConst();
+ probe = probe->convertToFullColumnIfSparse();
+
+ const UInt64 min_as_words = static_cast<UInt64>(bitset_min);
+ const UInt64 * const words = bitset.data();
+ const UInt64 bits = bitset_bits;
+ size_t found_count = 0;
+
+ /// A value maps into [0, bits) exactly when it lies in the covered range, so an index that
+ /// falls outside it is a definite miss: the bitset is exact over the whole range.
+ const bool dispatched = dispatchNativeIntColumn(*probe, [&](const auto & data)
+ {
+ for (size_t row = 0; row < rows; ++row)
+ {
+ const UInt64 index = static_cast<UInt64>(static_cast<Int64>(data[row])) - min_as_words;
+ const UInt8 result = index < bits ? ((words[index / BITSET_WORD_BITS] >> (index % BITSET_WORD_BITS)) & 1u) : 0u;
+ dst_data[row] = result;
+ found_count += result;
+ }
+ });
+
+ if (!dispatched)
+ {
+ for (size_t row = 0; row < rows; ++row)
+ {
+ const UInt64 index = static_cast<UInt64>(probe->getInt(row)) - min_as_words;
+ const UInt8 result = index < bits ? ((words[index / BITSET_WORD_BITS] >> (index % BITSET_WORD_BITS)) & 1u) : 0u;
+ dst_data[row] = result;
+ found_count += result;
+ }
+ }
+
+ updateStats(rows, found_count);
+ return dst;
+ }
+
if (bloom_filter)
{
auto dst = ColumnVector<UInt8>::create();
@@ -498,21 +676,189 @@ void ApproximateRuntimeFilter::insertIntoBloomFilter(ColumnPtr values)
});
}
+UInt64 ApproximateRuntimeFilter::bloomFilterBytes() const
+{
+ if (distinct_keys_hint)
+ return growBloomFilterBytes(*distinct_keys_hint, bloom_filter_hash_functions, getBytesLimit(), max_ratio_of_set_bits_in_bloom_filter);
+ return getBytesLimit();
+}
+
void ApproximateRuntimeFilter::switchToBloomFilter()
{
if (bloom_filter)
return;
- UInt64 bloom_filter_bytes = getBytesLimit();
- if (distinct_keys_hint)
- bloom_filter_bytes = growBloomFilterBytes(*distinct_keys_hint, bloom_filter_hash_functions, getBytesLimit(), max_ratio_of_set_bits_in_bloom_filter);
-
- bloom_filter = std::make_unique<BloomFilter>(bloom_filter_bytes, bloom_filter_hash_functions, BLOOM_FILTER_SEED);
+ bloom_filter = std::make_unique<BloomFilter>(bloomFilterBytes(), bloom_filter_hash_functions, BLOOM_FILTER_SEED);
insertIntoBloomFilter(getValuesColumn());
releaseExactValues();
}
+UInt64 ApproximateRuntimeFilter::bitsetMaxBytes() const
+{
+ /// Two independent budgets, whichever is larger: the bloom filter this replaces, and the space
+ /// the build-side keys themselves would occupy. The second matters because the bloom filter is
+ /// capped at 4 MiB and simply degrades its false positive rate beyond that, while a bitset has
+ /// none - but a bitset that costs more than storing every key exactly is not worth its memory.
+ static constexpr UInt64 BITSET_HARD_CAP_BYTES = 32 * 1024 * 1024;
+ static constexpr UInt64 MAX_TRUSTED_DISTINCT_KEYS_HINT = 1000000000;
+ UInt64 budget = bloomFilterBytes();
+ if (distinct_keys_hint && *distinct_keys_hint <= MAX_TRUSTED_DISTINCT_KEYS_HINT)
+ budget = std::max(budget, *distinct_keys_hint * filter_column_target_type->getSizeOfValueInMemory());
+ return std::min(budget, BITSET_HARD_CAP_BYTES);
+}
+
+bool ApproximateRuntimeFilter::tryStartBitset()
+{
+ if (!isDenseBitsetKeyType(filter_column_target_type))
+ return false;
+
+ const ColumnPtr values = getValuesColumn();
+ Int64 min_value = 0;
+ Int64 max_value = 0;
+ if (!nativeIntColumnEnvelope(*values, min_value, max_value))
+ return false;
+
+ const UInt64 max_words = bitsetMaxBytes() / sizeof(UInt64);
+ if (max_words == 0)
+ return false;
+
+ const Int64 aligned_min = alignDownToWord(min_value);
+ const UInt64 span_bits = static_cast<UInt64>(max_value) - static_cast<UInt64>(aligned_min) + 1;
+ const UInt64 words = (span_bits + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS;
+ if (words == 0 || words > max_words)
+ return false;
+
+ bitset.assign(words, 0);
+ bitset_min = aligned_min;
+ bitset_bits = words * BITSET_WORD_BITS;
+ bitset_max_words = max_words;
+ bitset_active = true;
+ setBitsetBits(*values);
+
+ releaseExactValues();
+ return true;
+}
+
+/// Widen the covered range to include [lo, hi]. `bitset_min` stays word aligned, so widening
+/// downwards only prepends whole words and no bit has to move inside its word.
+bool ApproximateRuntimeFilter::extendBitsetRange(Int64 lo, Int64 hi)
+{
+ const bool below = lo < bitset_min;
+ const Int64 current_top = bitset_min + static_cast<Int64>(bitset_bits);
+ const bool above = hi >= current_top;
+ if (!below && !above)
+ return true;
+
+ const Int64 target_min = below ? alignDownToWord(lo) : bitset_min;
+ const Int64 target_top = above ? hi + 1 : current_top;
+ const UInt64 needed_bits = static_cast<UInt64>(target_top) - static_cast<UInt64>(target_min);
+ UInt64 needed_words = (needed_bits + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS;
+ if (needed_words > bitset_max_words)
+ return false;
+
+ /// Grow geometrically upwards so a key column arriving in sorted order does not reallocate per block.
+ const UInt64 word_offset = (static_cast<UInt64>(bitset_min) - static_cast<UInt64>(target_min)) / BITSET_WORD_BITS;
+ needed_words = std::max(needed_words, std::min(bitset_max_words, static_cast<UInt64>(bitset.size()) * 2));
+ needed_words = std::max(needed_words, word_offset + static_cast<UInt64>(bitset.size()));
+ if (needed_words > bitset_max_words)
+ return false;
+
+ std::vector<UInt64> widened(needed_words, 0);
+ std::copy(bitset.begin(), bitset.end(), widened.begin() + word_offset);
+ bitset.swap(widened);
+ bitset_min = target_min;
+ bitset_bits = needed_words * BITSET_WORD_BITS;
+ return true;
+}
+
+void ApproximateRuntimeFilter::setBitsetBits(const IColumn & column)
+{
+ UInt64 * const words = bitset.data();
+ const UInt64 min_as_words = static_cast<UInt64>(bitset_min);
+ const bool dispatched = dispatchNativeIntColumn(column, [&](const auto & data)
+ {
+ for (const auto value : data)
+ {
+ const UInt64 index = static_cast<UInt64>(static_cast<Int64>(value)) - min_as_words;
+ chassert(index < bitset_bits);
+ words[index / BITSET_WORD_BITS] |= 1ULL << (index % BITSET_WORD_BITS);
+ }
+ });
+ if (!dispatched)
+ {
+ const size_t rows = column.size();
+ for (size_t row = 0; row < rows; ++row)
+ {
+ const UInt64 index = static_cast<UInt64>(column.getInt(row)) - min_as_words;
+ chassert(index < bitset_bits);
+ words[index / BITSET_WORD_BITS] |= 1ULL << (index % BITSET_WORD_BITS);
+ }
+ }
+}
+
+void ApproximateRuntimeFilter::insertIntoBitset(const ColumnPtr & values)
+{
+ Int64 min_value = 0;
+ Int64 max_value = 0;
+ ColumnPtr block = values->convertToFullColumnIfConst();
+ block = block->convertToFullColumnIfSparse();
+ if (block->empty())
+ return;
+
+ /// Anything the bitset cannot represent exactly - an unsupported column, a value outside the
+ /// safe range, or a range that no longer fits the byte budget - falls back to the bloom filter
+ /// with the keys recovered from the bits, so no key is ever lost.
+ if (!nativeIntColumnEnvelope(*block, min_value, max_value) || !extendBitsetRange(min_value, max_value))
+ {
+ switchFromBitsetToBloomFilter();
+ insertIntoBloomFilter(block);
+ return;
+ }
+
+ setBitsetBits(*block);
+}
+
+ColumnPtr ApproximateRuntimeFilter::bitsetValuesColumn() const
+{
+ MutableColumnPtr column = filter_column_target_type->createColumn();
+ const UInt64 min_as_words = static_cast<UInt64>(bitset_min);
+ const bool dispatched = dispatchNativeIntMutableColumn(*column, [&](auto & data)
+ {
+ using Container = std::decay_t<decltype(data)>;
+ using T = typename Container::value_type;
+ for (size_t word_index = 0; word_index < bitset.size(); ++word_index)
+ {
+ UInt64 word = bitset[word_index];
+ while (word)
+ {
+ const UInt64 bit = static_cast<UInt64>(std::countr_zero(word));
+ word &= word - 1;
+ const UInt64 value = min_as_words + word_index * BITSET_WORD_BITS + bit;
+ data.push_back(static_cast<T>(value));
+ }
+ }
+ });
+ if (!dispatched)
+ throw Exception(ErrorCodes::LOGICAL_ERROR, "Runtime filter bitset holds a non native integer key type");
+ return column;
+}
+
+void ApproximateRuntimeFilter::switchFromBitsetToBloomFilter()
+{
+ chassert(bitset_active);
+ const ColumnPtr recovered = bitsetValuesColumn();
+
+ bitset_active = false;
+ bitset.clear();
+ bitset.shrink_to_fit();
+ bitset_bits = 0;
+
+ bloom_filter = std::make_unique<BloomFilter>(bloomFilterBytes(), bloom_filter_hash_functions, BLOOM_FILTER_SEED);
+ if (!recovered->empty())
+ insertIntoBloomFilter(recovered);
+}
+
void ApproximateRuntimeFilter::checkBloomFilterWorthiness()
{
const auto & raw_filter_words = bloom_filter->getFilter();
diff --git a/src/Processors/QueryPlan/RuntimeFilterLookup.h b/src/Processors/QueryPlan/RuntimeFilterLookup.h
index b22f5d1b4ff..b7500f1242d 100644
--- a/src/Processors/QueryPlan/RuntimeFilterLookup.h
+++ b/src/Processors/QueryPlan/RuntimeFilterLookup.h
@@ -14,6 +14,7 @@
#include <functional>
#include <memory>
#include <optional>
+#include <vector>
namespace DB
{
@@ -307,12 +308,36 @@ private:
/// Disables bloom filter if it is likely to have bad selectivity
void checkBloomFilterWorthiness();
+ /// Bytes the bloom filter would occupy.
+ UInt64 bloomFilterBytes() const;
+ /// Memory budget the dense bitset must stay within.
+ UInt64 bitsetMaxBytes() const;
+
+ /// Dense exact representation for native integer keys: one bit per value of the covered range.
+ /// Probing is a single shifted load with no hashing and no false positives, so it replaces the
+ /// bloom filter whenever the observed key span fits the same byte budget.
+ bool tryStartBitset();
+ void insertIntoBitset(const ColumnPtr & values);
+ bool extendBitsetRange(Int64 lo, Int64 hi);
+ void setBitsetBits(const IColumn & column);
+ /// Exact keys held by the bitset, used when merging with a filter in another representation.
+ ColumnPtr bitsetValuesColumn() const;
+ void switchFromBitsetToBloomFilter();
+
const UInt64 bloom_filter_hash_functions;
const Float64 max_ratio_of_set_bits_in_bloom_filter = 0.7;
/// Measured distinct build-side keys from prior statistics, used to choose the bloom filter size.
const std::optional<UInt64> distinct_keys_hint;
BloomFilterPtr bloom_filter;
+
+ /// One bit per value of [bitset_min, bitset_min + bitset_bits). `bitset_min` is kept aligned to
+ /// a 64-bit word so the covered range can be widened by whole words, without shifting bits.
+ std::vector<UInt64> bitset;
+ Int64 bitset_min = 0;
+ UInt64 bitset_bits = 0;
+ UInt64 bitset_max_words = 0;
+ bool bitset_active = false;
};
/// Runtime filter that delegates probe to a function captured at publication time. |
|
Correction to my earlier comment: the limitation I listed — query_04 and query_21 unchanged because The blocker was not the representation but a memory policy choice, and one number in that bullet was wrong:
Giving the exact bitset its own allowance — 16 ×
query_03 crosses into this table with the growth fix. The earlier table's wins are preserved, so I am not restating them. The A/A null arm is flat on all 11, worst -2.0% with the CI spanning zero. The part that bears on this PR's design: because the bitset is exact inside its range, it also halves the rows the filter passes downstream — query_04 4,494,276 → 2,294,856 and query_21 6,895,425 → 3,458,628 — so the join probe receives less work, not merely cheaper filtering. A Costs and caveats:
|
|
The prototype caveat in my last comment is retired: the mechanism now applies to current master as one commit, and the gains reproduce there. @cv4g — it is already expressed for the post-#109620 shape you said you would rebase onto. Anchor is untouched master How it sits in the new hierarchy:
Measured on master, same method and node as the earlier tables (paired block-interleaved whole-server arms, rep 0 discarded, Student-t 95% CI on the mean paired log ratio, adapted TPC-H/TPC-DS SF10 on one exclusive 4-core host, not an audited TPC result):
Also h/query_08 -23.8%, query_03 -21.7%, query_16 -21.3%, query_09 -17.2%, query_02 -14.4%; ds/query_92 -38.3%, query_39 -21.0%, query_32 -20.5%, query_69 -19.2%, query_35 -18.8%, query_50 -13.7% (n=11 TPC-H, n=7 TPC-DS). The A/A null arm is flat on all 11, there is no regression anywhere, and Answers: TPC-H 23/23 and TPC-DS 98/99 identical sorted digests. The one difference, ds/query_65, is master's own tie-boundary nondeterminism — the unmodified anchor alternates between the same two digests, and with the Costs, on master:
Patch — 465 insertions, applies to
|
|
This PR should merge after #120232 which moves certain code parts into place as a preparatory step |
|
@snelheidai Thank you, that is a very interesting idea. Please open a PR based on current master and tag me on it. I am happy to review the change set and look forward to the CI Benchmark Suite results. Please try to avoid defining the CHPERF_DISPATCH_NATIVE_INT macro and check if you can go with another template meta programming alternative. |
…-filter Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. - retargeted PR record [email protected] to 26.10 (settings-history check rule) - retargeted PR record [email protected] to 26.10 (settings-history check rule) Also resolved conflicts in: - `src/Processors/QueryPlan/BuildRuntimeFilterStep.cpp` - `src/Processors/QueryPlan/Optimizations/joinRuntimeFilter.cpp` - `src/Processors/QueryPlan/RuntimeFilterBuildOptions.h` - `src/Processors/QueryPlan/RuntimeFilterLookup.cpp` - `src/Processors/QueryPlan/RuntimeFilterTypes.h` - `src/Processors/Transforms/BuildRuntimeFilterTransform.cpp` - `src/Processors/benchmarks/benchmark_runtime_filter.cpp` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| settings[QueryPlanSerializationSetting::join_runtime_filter_pass_ratio_threshold_for_disabling] = pass_ratio_threshold_for_disabling; | ||
| settings[QueryPlanSerializationSetting::join_runtime_filter_blocks_to_skip_before_reenabling] = blocks_to_skip_before_reenabling; | ||
| settings[QueryPlanSerializationSetting::join_runtime_bloom_filter_max_ratio_of_set_bits] = build_options.max_ratio_of_set_bits; | ||
| settings[QueryPlanSerializationSetting::join_runtime_filter_use_minmax] |
There was a problem hiding this comment.
RuntimeFilterMinMaxMode is now a per-step three-state contract, but serialization still collapses it to the legacy plan-global boolean here and deserialize turns any true back into Combined. That means the round-trip can no longer preserve what was actually planned: a MinMaxOnly step comes back as combined, and a plan with mixed runtime-filter steps (for example one numeric key and one String key) can only deserialize one global minmax choice, so at least one placeholder step reports the wrong mode.
Please serialize the enum per step, or keep deserialized BuildRuntimeFilterStep explicitly mode-blind instead of reconstructing a specific minmax mode.
|
Dear @cv4g, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |





Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Use
[min, max]range for join runtime filters to avoid unnecessary lookups in Bloom filters in case of numeric keys. Closes #96094.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/96779]