Repository navigation
Conversation
…edicts to saturate `ApproximateRuntimeFilter` sizes its Bloom filter from the build-side key count of the hash table statistics, but the size is capped at 4 MiB. With more distinct keys than fit at `join_runtime_bloom_filter_max_ratio_of_set_bits`, every build thread filled and merged its 4 MiB copy only for `checkBloomFilterWorthiness` to discard the result: on a 30M-key `SEMI JOIN` that was a third of all CPU time, and the query's profile events showed no row ever checked against the filter. The same formula that sizes the filter predicts its fill rate at the capped size, `1 - exp(-keys * hashes / bits)`. When that exceeds the maximal ratio, the filter is disabled before the build instead of after it. The min/max envelope for index analysis is still tracked. New profile event `RuntimeFilterBloomFilterBuildsSkipped`. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01SGvsqqytvRcokXN8TWn2Mr
|
Workflow [PR], commit [7d51c7b] Summary: ✅
AI ReviewSummaryThis PR makes Findings
Final VerdictChanges requested. The pre-build skip still has a real stale-hint regression on variable-sized workloads, and the new user-visible setting behavior is not documented. LLVM Coverage ReportMeasured on commit 7d51c7b.
Changed lines: Changed C/C++ lines covered: 103/104 (99.04%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units223 translation units recompiled, 2421 s compile time in total, 223 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…ip-saturated-bloom-filter
…er build The hash table statistics are keyed by the join order optimization, which assigns no key when `query_plan_optimize_join_order_limit` is 0. The test harness randomizes that setting to 0 in about 5% of the runs, so the second run of the test found no size hint and built the filter again instead of skipping it. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118336&sha=latest&name_0=PR PR: ClickHouse#118336 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Pp8vKdfGBejMpYwu4EKgP8
…nd allow for a stale key count The hash table statistics count distinct join keys. A per-column filter of a multi-key join gets only an upper bound of its distinct values from them, so its build is sized by the count but never skipped. The statistics also keep a measured size until a run finds less than half of it, so the build is skipped only if half of the counted keys would saturate the filter. Also explain in `disable` why it releases the exact values, link the fill rate formula, and reword the comments from the review. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Pp8vKdfGBejMpYwu4EKgP8
| /// (`HashJoinEntry::shouldBeUpdated`), so the build is skipped only if half of the hinted keys saturate the filter. | ||
| if (distinct_keys_hint_matches_filter_key) | ||
| { | ||
| const double least_distinct_keys = static_cast<double>(*distinct_keys_hint) / 2.0; |
There was a problem hiding this comment.
Using *distinct_keys_hint / 2 here does not actually make the skip safe on the first execution after the build side shrinks. getBuildSideDistinctKeys reads the previous HashJoinEntry::ht_size, and HashTablesStatistics::update deliberately keeps the old maximum until a later run finishes with new_entry.ht_size < old / 2. So a query that previously saw, say, 8M build keys and now sees 1M will still plan with least_distinct_keys = 4M and can hit disable() even though the current Bloom filter would stay below the density threshold. Before this PR a stale hint only oversized the filter; now it changes behavior. Please keep the hint sizing-only, or gate this fast path on a freshness signal that proves the current run is within that 2x window.
There was a problem hiding this comment.
The stale hint cannot be verified at planning time: the current run's size is unknown until the hash table is built, so no freshness signal can prove it is within the 2x window. The / 2 covers the case where the statistics deliberately keep the old maximum. For the remaining case, a build side that shrinks by more than 2x below a hint above ~27M keys (defaults), the cost is one run without the Bloom filter: it is never wrong, only absent, the min/max envelope is still tracked, and that same run updates the statistics (new_entry.ht_size < ht_size / 2), so the next run plans correctly. The old sizing-only behavior filled and merged a 4 MiB filter per thread that was then discarded, which the fast path avoids, so I keep it.
| /*track_key_range_=*/optimization_settings.enable_join_runtime_filters_index_analysis, | ||
| distinct_keys_hint); | ||
| distinct_keys_hint, | ||
| /*distinct_keys_hint_matches_filter_key_=*/true); |
There was a problem hiding this comment.
It's not clear to me why we set true in l. 479.
There was a problem hiding this comment.
It's true because this filter is built on the complete join key, so the hash table size counts exactly this filter's distinct keys
…he build side `HashJoinEntry::shouldBeUpdated` and the Bloom filter build skip both relied on the literal `2`, which must stay in sync. Expose it as `HashJoinEntry::MAX_OVERESTIMATION_FACTOR` and use it in both places. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01JyZgVjwycGoE67Jf1wvve6
… filter test, add a performance test `05077_join_runtime_filter_skip_saturated_bloom_filter` failed in the old analyzer and the parallel replicas CI configurations: the old analyzer builds no join runtime filters, and with parallel replicas the probe side is read on the replicas, so `RuntimeFilterRowsChecked` stays zero on the initiator. The test now sets `enable_analyzer = 1` and `enable_parallel_replicas = 0` like the other runtime filter tests. The performance test joins a 1M row probe side with a 40M distinct key build side, which saturates the largest statistics-sized Bloom filter, so the build is skipped from the second run on. Interleaved runs of the CI-built master (55c2563) and PR binaries, 20 per binary, on a 12-core machine: median 702 ms -> 432 ms (Mann-Whitney p = 6.8e-8, Welch p = 1.8e-21), and no change for a 1M key build side, a multi-key join, or a join without runtime filters. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118336&sha=b4a7e250382525575e3d467dd803093b507aff62&name_0=PR Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019Y56AP2MkgeFa9TAJ9oMjE
| const double least_distinct_keys = static_cast<double>(*distinct_keys_hint) / HashJoinEntry::MAX_OVERESTIMATION_FACTOR; | ||
| const double predicted_fill_rate = -std::expm1( | ||
| -static_cast<double>(bloom_filter_hash_functions) * least_distinct_keys / (static_cast<double>(bloom_filter_bytes) * 8.0)); | ||
| if (predicted_fill_rate > max_ratio_of_set_bits_in_bloom_filter) |
There was a problem hiding this comment.
This makes join_runtime_filter_size_from_hash_table_stats more than a sizing knob: with the setting enabled, planning can now skip building the Bloom filter altogether. The source-level setting docs still say it only sizes the runtime filter and otherwise falls back to join_runtime_bloom_filter_bytes, so users will not see this new behavior documented. Please update the DECLARE text in src/Core/Settings.cpp (and the matching SettingsChangesHistory.cpp blurb if you keep them aligned).
…skip-saturated-bloom-filter
| <fill_query>INSERT INTO rf_probe SELECT number FROM numbers(1000000)</fill_query> | ||
| <fill_query>INSERT INTO rf_build SELECT number * 2 FROM numbers(40000000)</fill_query> | ||
|
|
||
| <query>SELECT count() FROM rf_probe INNER JOIN rf_build ON rf_probe.k = rf_build.k</query> |
There was a problem hiding this comment.
We'd need to run the same query twice here ... which the test framework doesn't allow.
The test was added by some agent. Let's remove it?
| } | ||
| else | ||
| /// We can only merge the min-max value envelopes. | ||
| if (source_typed->is_fully_disabled) |
There was a problem hiding this comment.
Someone reading
if (source_typed->is_fully_disabled)
disable();will be too confused. Could you give the member variable and the function more fitting names please?
Requested in ClickHouse#118336 (comment) Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_015spRVzDCnLCTyZZ5to1u8h
The state means the filter gave up on its key set and passes all rows while still tracking the key-range envelope, so name it `key_set_dropped` / `markKeySetDropped` / `dropKeySet` instead. Requested in ClickHouse#118336 (comment) Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_015spRVzDCnLCTyZZ5to1u8h
… hash table statistics The hash table of a join is keyed on both `Equals` and `NullSafeEquals` pairs, so its statistics count distinct tuples of all of them, while runtime filters are built only from the `Equals` keys (`JoinStepLogical::preCalculateKeys`). For `ON a = b AND c <=> d` the single filter key was marked as matching the statistics, and `AdaptiveSetRuntimeFilter::switchToApproximateFilter` predicted a saturated Bloom filter from the inflated tuple count and skipped it from the second run on. Mark the statistics as matching the filter key only when the filter keys are all the hash table keys. Such filters are still sized by the statistics, but never skipped. ClickHouse#122167 Related: ClickHouse#118336 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #118230
ApproximateRuntimeFiltersizes its Bloom filter from the build-side key count of the hash table statistics, but the size is capped at 4 MiB. With more distinct keys than fit atjoin_runtime_bloom_filter_max_ratio_of_set_bits, every build thread filled and merged its 4 MiB copy only forcheckBloomFilterWorthinessto discard the result: on a 30M-keySEMI JOINthat was a third of all CPU time, and the query's profile events showed no row ever checked against the filter.The same formula that sizes the filter predicts its fill rate at the capped size,
1 - exp(-keys * hashes / bits). When that exceeds the maximal ratio, the filter is disabled before the build instead of after it. The min/max envelope for index analysis is still tracked. New profile eventRuntimeFilterBloomFilterBuildsSkipped.Split out of #118230.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The join runtime filter no longer builds a Bloom filter that the build-side key count predicts to be too dense to be useful.
Workflow [PR]
Sync PR [sync-upstream/pr/118336]
Version info
26.9.1.1041(included in26.9and later)