Skip to content

Enable enable_join_runtime_filters_index_analysis by default - #117375

Closed
alexey-milovidov wants to merge 45 commits into
masterfrom
enable-join-runtime-filters-index-analysis
Closed

alexey-milovidov wants to merge 45 commits into
masterfrom
enable-join-runtime-filters-index-analysis

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Related: #109085
Related: #117322

The runtime filter collected from the right side of a JOIN was already used to filter the probe side row by row (enable_join_runtime_filters, enabled by default since 26.2), but it pruned granules of the probe side only when enable_join_runtime_filters_index_analysis was enabled explicitly. This enables it by default.

Measured on 30 million rows in a fact table ordered by the join key, joined against a small dimension table (marks read, and rows read on the probe side):

dimension shape marks, off marks, on rows read, off rows read, on
100000 contiguous keys 3677 25 30.1M 206K
10 keys spread over the table 3666 12 30.0M 90K
minmax skip index on the join key 3681 224 30.1M 1.8M

The pass is skipped when the join key is neither a primary key column nor covered by a minmax, set or bloom_filter skip index, and when the filter is not built yet, so it either prunes granules that cannot match or does nothing. The one exception is use_skip_indexes_on_data_read = 0: it switches the pruning off, but the build side still records the key range of the filter, because EXPLAIN forces that setting to false in its own context and a plan decided on it would differ from the plan the same query runs with. On a dimension table whose keys span the whole fact table, where nothing can be pruned, the query time is the same within measurement noise (best of 7 runs: 0.081 s vs 0.079 s for the primary key case, 0.074 s vs 0.078 s for the skip index case).

Enabling the setting also used to switch on the build-side key range tracking (an extra getExtremes pass over every build chunk) for every runtime filter, including those whose probe side can never consume it. That is fixed here: the new final optimizer pass disableUnusedRuntimeFilterKeyRangeTracking turns the tracking off for every build step whose filter no ReadFromMergeTree registered for index analysis, so a non-prunable join pays nothing. EXPLAIN actions = 1 prints the decision as Key range tracking, pinned by the new test 05175_join_runtime_filter_key_range_tracking.

The existing join_runtime_filter performance test cannot cover this path: it joins on o_custkey while orders is ordered by o_orderkey, so the join key is neither in the primary key nor indexed and no filter is ever registered for index analysis. This adds join_runtime_filter_index_analysis, which measures pruning by a key range, pruning by an exact IN set, the overhead of the pass when nothing can be pruned, and a join key that is not prunable at all.

Correctness of the pruning itself is covered by the existing tests 04490_join_runtime_filters_index_analysis, 04498_join_runtime_filters_multihop, 04611_join_runtime_filters_index_analysis_skip_index, 04612_join_runtime_filters_index_analysis_multi_key_anti and 04628_join_runtime_filter_reverse_key. In addition, clickhouse-test has randomized this setting since it was introduced, so the whole stateless suite has already been running with it enabled about half of the time.

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Enabled enable_join_runtime_filters_index_analysis by default. The set of JOIN keys collected from the right side of a JOIN at runtime is now also used to skip granules of the left side, in addition to filtering its rows. It applies when the join key is a primary key column or is covered by a minmax, set or bloom_filter skip index.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/117375]

The runtime filter collected from the right side of a JOIN was already used to
filter the probe side row by row (`enable_join_runtime_filters`, on by default
since 26.2), but only pruned granules of the probe side when
`enable_join_runtime_filters_index_analysis` was enabled explicitly. Enable it by
default and move the setting from the experimental to the beta tier, next to
`enable_join_runtime_filters` which it extends.

Measured on 30 million rows in a fact table ordered by the join key, joined
against a small dimension table (marks read, and rows read of the probe side):

    dimension shape                     off              on
    100000 contiguous keys      3677 marks       25 marks     30.1M -> 206K rows
    10 keys spread over table   3666 marks       12 marks     30.0M -> 90K rows
    minmax skip index on key    3681 marks      224 marks     30.1M -> 1.8M rows

The pass is skipped when the join key is neither a primary key column nor covered
by a `minmax`, `set` or `bloom_filter` skip index, and when the filter is not
built yet, so it either prunes granules that cannot match or does nothing. On a
dimension table whose keys span the whole fact table, where nothing can be
pruned, the query time is the same within measurement noise (best of 7 runs:
0.081 s vs 0.079 s for the primary key case, 0.074 s vs 0.078 s for the skip
index case).

The existing `join_runtime_filter` performance test cannot cover this path: it
joins on `o_custkey` while `orders` is ordered by `o_orderkey`, so the join key
is neither in the primary key nor indexed and no filter is ever registered for
index analysis. Add `join_runtime_filter_index_analysis`, which measures pruning
by a key range, pruning by an exact `IN` set, and the overhead of the pass when
nothing can be pruned.

Correctness of the pruning is covered by the existing tests
`04490_join_runtime_filters_index_analysis`,
`04498_join_runtime_filters_multihop`,
`04611_join_runtime_filters_index_analysis_skip_index`,
`04612_join_runtime_filters_index_analysis_multi_key_anti` and
`04628_join_runtime_filter_reverse_key`, and the setting has been randomized by
`clickhouse-test` since it was introduced, so the whole stateless suite has been
running with it enabled about half of the time.
@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [979b737]

Summary: ❌

job_name test_name status info comment
Performance Comparison (amd_release, master_head, 1/6) FAIL Performance dashboard
timeseries_to_grid_scalar_add #2 FAIL dashboard
iceberg_suite_rw_features #5 unstable query history
insert_sequential_and_background_merges #0 unstable query history
timeseries_to_grid_scalar_add #0 slower query history
timeseries_to_grid_scalar_add #1 unstable query history
Performance Comparison (amd_release, master_head, 5/6) FAIL Performance dashboard
re2_regex_caching #3 FAIL dashboard
codecs_int_insert #9 unstable query history
file_table_function #15 unstable query history
number_formatting_formats #0 unstable query history
number_formatting_formats #1 unstable query history
number_formatting_formats #6 unstable query history
polymorphic_parts_m #0 unstable query history
polymorphic_parts_s #0 unstable query history
re2_regex_caching #5 slower query history

AI Review

Summary

This PR enables enable_join_runtime_filters_index_analysis by default and tightens many of the cases where the build side should stop tracking runtime-filter key ranges. The remaining issue is the parallel-replicas path: reads can still be marked ineligible after descriptor registration, so the build side keeps paying the getExtremes cost even though the final read will not prune. Status: ⚠️ Request changes.

Findings

⚠️ Majors

  • [src/Processors/QueryPlan/Optimizations/optimizeTree.cpp:377-380,422,869-872] The new “plan-level pass and pipeline cannot drift apart” contract still breaks for plan-based parallel replicas. registerLeftSideIndexAnalysisSecondPass records descriptors before applyParallelReplicas marks the coordinated read as parallel (src/Processors/QueryPlan/Optimizations/applyParallelReplicas.cpp:630-636), and disableUnusedRuntimeFilterKeyRangeTracking later keys only off those stale descriptors. But ReadFromMergeTree::canUseJoinRuntimeFilterIndexAnalysis now vetoes the same read once isParallelReadingFromReplicas is set (src/Processors/QueryPlan/ReadFromMergeTree.cpp:2916-2944), so execution does no probe-side pruning while the build side still keeps key-range tracking alive.
    Suggested fix: either retract/revalidate the runtime-filter descriptors when applyParallelReplicas marks a read for replica coordination, or rerun disableUnusedRuntimeFilterKeyRangeTracking after that rewrite so the final plan shape drives the build-side decision.
Tests
  • ⚠️ There is still no focused regression for the parallel-replicas variant of this contract. A minimal test should enable plan-based parallel replicas on a prunable join and prove that once the read is marked for replica coordination it no longer leaves Key range tracking: 1 behind on the build side.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  • Ensure parallel-replicas rewrites cannot leave BuildRuntimeFilterStep tracking enabled after the coordinated ReadFromMergeTree becomes ineligible for runtime-filter index analysis.
  • Add a focused regression that exercises that parallel-replicas path.

LLVM Coverage Report

Measured on commit 979b737.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 352/364 (96.70%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Aug 31, 2026
Comment thread src/Core/Settings.cpp Resolved
Comment thread src/Core/Settings.cpp Outdated
DECLARE(Bool, enable_join_runtime_filters_index_analysis, true, R"(
Prune granules on the left (probe) side of a JOIN with the runtime filter collected from the right side, see `enable_join_runtime_filters`.

The pruning predicate is an `IN` set of the key values recorded by the filter, or the recorded `[min, max]` key range when there are too many values to keep exactly, see `join_runtime_filter_exact_values_limit`. It is evaluated by the second index analysis pass that runs at data read time, see `use_skip_indexes_on_data_read`, and it applies when the join key is a primary key column or is covered by a `minmax`, `set` or `bloom_filter` skip index. When the filter is not built yet the pass is skipped, so a granule is never pruned by mistake.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This should mention that runtime filters as bloom filters (if their size is > join_runtime_filter_exact_values_limit) cannot be used for pruning.\

  2. "Second index analysis pass" is odd terminology. Let's please just mention dynamic skip index analysis during part read.

  3. Sentence When the filter is not built yet [...] provides no extra value for the reader and can be removed. I actually think that runtime filters are always build fully before they are used.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Rewritten in 31bf81b, thanks. The description now reads:

Prune granules on the probe (left) side of a JOIN with the runtime filter collected from the build (right) side, see enable_join_runtime_filters. The pruning happens as a dynamic skip index analysis while the probe side parts are read (see use_skip_indexes_on_data_read), so it can use a filter that is only known at runtime.

Only a join key that is a primary key column of the probe side, or is covered by a minmax, set or bloom_filter skip index there, can be pruned. If the runtime filter kept the exact key values, the pruning predicate is an IN set of them; if the build side had more keys than join_runtime_filter_exact_values_limit and the filter became a bloom filter, only the recorded key range is used, which prunes less.

On the three points:

  1. Agreed, "second index analysis pass" is gone — it now says dynamic skip index analysis during the part read, and names use_skip_indexes_on_data_read.
  2. Agreed, removed; you are right that the filter is always built before it is used, the fail-open branch is only a safety net.
  3. Here I had to phrase it differently, because a bloom filter can still prune. convertRuntimeFilterToKeyConditionDAG (src/Processors/QueryPlan/RuntimeFilterLookup.cpp) uses the exact key values when the filter kept them, and otherwise falls back to the recorded [min, max] key range, which a bloom filter does record. So exceeding join_runtime_filter_exact_values_limit makes the pruning coarser (a range instead of an IN set) rather than impossible. Let me know if you would rather have it stated as a flat "no pruning" — then the code should be changed instead of the description.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current head still contradicts the fixed in 31bf81b67384 explanation here. src/Core/Settings.cpp:9438-9440 still says that once the filter overflows join_runtime_filter_exact_values_limit, "only the recorded key range is used", but RuntimeFilterIndexAnalysis::supportsDataType only records that range for integer/date-like keys. 05247_join_runtime_filter_string_key_no_range now proves the String case: after overflow, getRecordedKeyRanges stays empty and pruning becomes a no-op instead of a coarser range check.

So the original wording concern is still real for String join keys: the setting text, and the matching SettingsChangesHistory entry, should say that the range fallback is type-dependent rather than unconditional.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Agreed, fixed in 148e11f. RuntimeFilterIndexAnalysis::supportsDataType records the range only for integer and date/date-time keys, so the setting text now says that for any other key type (String, floating-point, Decimal, UUID) the pruning stops once the filter loses the exact values, and the 26.10 SettingsChangesHistory record says the same. 05247_join_runtime_filter_string_key_no_range already pins the String behavior.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@rschu1ze — tagging you on this one as JOIN-related, as requested. Review request sent too.

@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 39 queries analysed

This PR defaults on probe-side JOIN granule pruning (enable_join_runtime_filters_index_analysis) and adds build-side key-range tracking that is dropped when no read can consume the filter; it touches only the join runtime-filter path. Both flagged ClickBench queries are single-table aggregations with no join (Q16: GROUP BY UserID; Q28: GROUP BY CounterID), so neither exercises the changed code. Both were already left non-directional by the deterministic gates: Q16 sits inside master's current variance band on an intrinsically noisy query, and Q28's two tests disagree on noisy measurements. No real regression or improvement is attributable to this change in the flagged set.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 16 not_sure 565 622 +10.1% <0.0001 aggregation: Q16 is a single-table GROUP BY UserID with no join, so the join runtime-filter changes cannot touch its path. The row is a marked-noisy query and already sits inside master's variance band, so the +10.1% reads as run-to-run variance.
⚠️ 28 not_sure 1124 1062 -5.5% 0.0098 aggregation: Q28 is a single-table GROUP BY CounterID scan with no join, untouched by the runtime-filter work. The two tests disagree and the measurements were noisy, so the -5.5% is not a PR effect.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: a69ff287-2c46-434c-ba43-5bdd0243f9bd
  • MIRAI run: e77cdb48-3565-4ffd-8831-674c3012816c
  • PR check IDs:
    • clickbench_307405_1789484484
    • clickbench_307411_1789484484
    • clickbench_307417_1789484484
    • tpch_adapted_1_official_307426_1789484484
    • tpch_adapted_1_official_307439_1789484484
    • tpch_adapted_1_official_307476_1789484484

@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 979b73753e8527fa1d3d6d85d2d314bf9fbf7520 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@rschu1ze rschu1ze self-assigned this Sep 2, 2026
@rschu1ze

rschu1ze commented Sep 2, 2026

Copy link
Copy Markdown
Member

@rschu1ze — tagging you on this one as JOIN-related, as requested. Review request sent too.

@alexey-milovidov I posted comments two days ago. Lgtm, overall, thanks.

@clickhouse-gh clickhouse-gh Bot added the comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... label Sep 4, 2026
@clickhouse-gh clickhouse-gh Bot added the submodule changed At least one submodule changed in this PR. label Sep 9, 2026
Comment thread src/Core/Settings.cpp Resolved
alexey-milovidov and others added 2 commits September 10, 2026 06:33
…de can use it

`enable_join_runtime_filters_index_analysis` was passed straight into every
`BuildRuntimeFilterStep` as `track_key_range`, so turning it on by default made
`BuildRuntimeFilterTransform` call `enableIndexAnalysis` and pay an extra
`getExtremes` pass over every build chunk - even for joins whose probe side can
never consume the result. The eligibility check (join key in the primary key, or
covered by a `minmax`, `set` or `bloom_filter` skip index) happens later, in
`ReadFromMergeTree::addJoinRuntimeFilterIndexAnalysisOnDataRead`, and the
descriptors are also dropped for reads that are replaced afterwards, such as
distributed and parallel-replica reads.

Add a final optimization pass, `disableUnusedRuntimeFilterKeyRangeTracking`,
which runs on the final plan: it collects the rendezvous keys of the runtime
filters that some `ReadFromMergeTree` really registered for index analysis, and
turns off key range tracking on every build step that is not among them. With
that, the new default is a genuine no-op for non-prunable joins.

`EXPLAIN actions = 1` now prints `Key range tracking` for `BuildRuntimeFilter`,
so the decision is observable; test `05175_join_runtime_filter_key_range_tracking`
pins it, including a query with two runtime filters where only the prunable one
is tracked. `03716_anti_join_runtime_filters_2` pins the setting, which is
randomized in CI and would otherwise change the printed plan.

Also add the non-prunable join key to
`tests/performance/join_runtime_filter_index_analysis.xml`, which is exactly the
shape that had to be benchmarked, and reword the setting description: the
pruning happens on the probe (left) side, not on the build side.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only red on the previous run was Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) with a job-level session-timeout occurred during test execution (no individual test failed). This is fleet-wide, not specific to this PR — CIDB shows the same Timeout failure across many PRs every day of the last week (22 occurrences over 7 PRs on 2026-09-10, 124 over 45 PRs on 2026-09-09):

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117375&sha=fd850f737e6c1a20695e27cea49b0476df57f3d4&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%206%2F6%29

@groeneai, could you investigate the integration-test job timeouts and provide a fix in a separate PR? If a fix is already in progress, please link it here.

Master is merged and the review findings are addressed in 31bf81b, so the job runs again from scratch on the new head.

@groeneai

Copy link
Copy Markdown
Collaborator

Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6): job-level session-timeout

Confirmed as the graceful-overrun shape on fd850f737e6c: 1220 OK, 34 skipped, one synthetic Timeout row, no individual test failure. Per-shard job wall clocks on that run were 6658 / 7118 / 6694 / 6095 / 7061 / 7332 s for 1/6 through 6/6. The cut shard's job ran 7332 s against a 7200 s session cut, so 132 s sits outside the session as setup and teardown; subtracting the same overhead from its siblings puts 2/6 and 5/6 at roughly 6990 and 6930 s of session, 97% and 96% of the bound. Three of six shards were that close to the cut, so a few per cent of runner speed decides which one goes red. The whole arm has also been running at about 5x its 30-day rate for two days now (52 of 3401 trees against 0.29%), all six batches lifted together.

The fix in progress is your own #118933 (eight batches, approved by Algunenano on 09-09, checks green), so I have not opened a competing PR. For this PR, 6/6 is the rarest of the six batches (13 of 11655 trees over 30 days, 2 of 567 in the last two days, against 0.45% for 3/6 and 5/6), so the run on 31bf81b67384 should clear it about 99.6 times in 100.

One part of the fleet-wide count is worth separating, because #118933 does not reach it: 73 of the 124 rows on 09-09, and 16 of the 22 today, are amd_asan_ubsan, db disk, N/4 on 26.6, 26.7 and 26.8, which still run four batches. #116591 took that arm to six on master and carries no backport label, so the release branches never received it. Over the last 14 days on those three branches:

arm trees with a Timeout row
db disk, N/4 (four batches) 307 of 308 (933 rows)
db disk, old analyzer, N/6 (six batches) 3 of 308

That is the batch-count argument from #118933 measured in production, on the same branches over the same window. v26.6-must-backport, v26.7-must-backport and v26.8-must-backport on #116591 would clear the larger half of the count.


if (auto * read_step = typeid_cast<ReadFromMergeTree *>(node->step.get()))
{
for (const auto & descriptor : read_step->getJoinRuntimeFiltersForIndexAnalysis())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still treats “a ReadFromMergeTree registered a descriptor” as the same thing as “some probe-side read can actually consume a positive pruning predicate”, but those are not equivalent.

A concrete counterexample is single-key LEFT ANTI JOIN: registerLeftSideIndexAnalysisSecondPass intentionally still registers the descriptor here, even though the comment right above says those filters stay fail-open. The built filter is ExactNotContainsRuntimeFilter, which sets range_positive = false in src/Processors/QueryPlan/RuntimeFilterLookup.h:255-269, and then convertRuntimeFilterToKeyConditionDAG returns nullptr because both getRecordedKeyValues and getRecordedKeyRanges are absent (src/Processors/QueryPlan/RuntimeFilterLookup.cpp:690-693). So consumed_filter_keys keeps the filter alive here, disableUnusedRuntimeFilterKeyRangeTracking leaves track_key_range on, and we still pay column.getExtremes() on every build chunk for a query shape that can never prune.

The same proxy also misses later read-side bail-outs in ReadFromMergeTree::initializePipeline (FINAL, pending mutations, disabled / ignored skip indexes, etc.), so the new default is still not “prune or do nothing” for every supported shape. Can we base this pass on “predicate actually buildable” rather than raw descriptor presence, or at least force track_key_range = false for check_left_does_not_contain and add an EXPLAIN test for that case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Adopted in 4e083a0, thank you — the counterexample is real.

You are right that registerLeftSideIndexAnalysisSecondPass registers a descriptor for the single-key LEFT ANTI shape, that the built filter is ExactNotContains with range_positive = false, and that convertRuntimeFilterToKeyConditionDAG therefore returns nullptr for it — so the old pass kept track_key_range on for a query shape that can never prune.

Two changes:

  1. BuildRuntimeFilterStep is now constructed with track_key_range = false whenever check_left_does_not_contain holds — both for the per-column filters of a single-key ANTI join and for the tuple filter of a multi-key one, which is always negating. This is decided at the source, where the semantics are known, rather than inferred later.
  2. disableUnusedRuntimeFilterKeyRangeTracking now matches reads against build steps in both directions. It first drops the read-side descriptors of any filter whose build step cannot produce a positive predicate, so the dynamic-predicate machinery is not installed for them at all, and only then disables tracking for the build steps that no remaining descriptor consumes.

05175_join_runtime_filter_key_range_tracking gets the EXPLAIN test you asked for, in three cases: a single-key ANTI join whose key is the primary key of the probe side (Key range tracking: 0), the multi-key tuple variant (0), and a query with a prunable INNER JOIN filter next to an ANTI filter, which prints 1 and 0 under one setting value — so it proves the decision is per filter and not per query. 44 of the 46 local *runtime_filter* tests pass; the two that do not need process_query_plan_packet in the server config (distributed plan serialization), which my local server does not have.

On the second half of your point — the later read-side bail-outs in ReadFromMergeTree::initializePipeline (FINAL, pending mutations, use_skip_indexes off, ignore_data_skipping_indices, parallel replicas): those are decided from the query context at pipeline-build time, after plan optimization has run, so the plan-level pass cannot see them. Making the new default literally "prune or do nothing" for those shapes needs the decision to move to (or be echoed back from) initializePipeline, which is a larger change than this PR should carry. The residual cost there is the getExtremes pass on the build side only; the read side already fails open. I am tracking that as a follow-up rather than widening this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Adopted in d25d7be071a5. You were right that I dismissed this too quickly — the late read-side guards are not actually "after plan optimization and therefore unfixable here", because every one of them is already knowable while the plan is being optimized.

ReadFromMergeTree::canUseJoinRuntimeFilterIndexAnalysis now holds those vetoes (FINAL, pending mutations, parallel replicas), and addJoinRuntimeFilterIndexAnalysisOnDataRead refuses to register a descriptor for a read that would reject it anyway. The registration also applies use_skip_indexes and ignore_data_skipping_indices to the skip-index half of the key test, which it previously ignored. initializePipeline calls the same method, so the plan-level pass and the pipeline cannot drift apart.

The second half of your finding — MergeTreeIndexReadResultPool::read materializing the predicate for every part when prune_primary_key == false and dynamic_skip_indexes is empty — is fixed at the source: dynamic_predicate_builder is now installed only when runtime_prune_primary_key || !runtime_skip_indexes.empty(), instead of whenever any descriptor exists.

One deliberate exception: use_skip_indexes_on_data_read is not part of the plan-level method. InterpreterExplainQuery forces it to false in its own context, so deciding the plan on it would make every EXPLAIN actions = 1 print a plan that differs from the one the same query really runs — a worse problem than the one being fixed. It stays checked in initializePipeline; with it off the dynamic predicate is not installed either, so only the build-side extremes pass remains.

Tests, in 05175_join_runtime_filter_key_range_tracking — including the exact case you asked for, each next to the positive control that pins the difference to that one reason:

  • ignore_data_skipping_indices = 'idx_v' on the join key with idx_w still active on the read → 0; the same query without it → 1.
  • use_skip_indexes = 0 with a skip-index-covered join key → 0; with a primary-key join key → 1 (the primary-key path is not gated by that setting).
  • FINAL → 0; the same table without FINAL → 1.

46/46 *runtime_filter* stateless tests pass locally.

@alexey-milovidov alexey-milovidov Sep 13, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Adopted in cceee73d698f, by narrowing the contract rather than the code, as the review offered as the second option.

You are right that the test comment listed use_skip_indexes_on_data_read among the read-side vetoes the plan acts on while canUseJoinRuntimeFilterIndexAnalysis deliberately leaves it out, so the text and the code disagreed. The code stays: EXPLAIN forces that setting to false in its own context (InterpreterExplainQuery, for #88467), so a plan gated on it would make every EXPLAIN actions = 1 print a plan that differs from the one the same query runs, which is a worse outcome than the residual min/max pass on the build side. With the setting off, the read installs no dynamic predicate at all (initializePipeline checks it before runtime_prune_primary_key / runtime_skip_indexes are computed), so the only remaining cost is that getExtremes pass over the build chunks.

What changed: the setting description and the SettingsChangesHistory entry now say explicitly that use_skip_indexes_on_data_read = 0 switches the pruning off but the build side still records the key range; the test comment no longer claims otherwise; and 05175_join_runtime_filter_key_range_tracking pins the exception with a read-time skip indexes disabled case that prints Key range tracking: 1, plus the corresponding result check, so a later change of this behavior has to be a deliberate one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parallel-replicas half of this is still present on the current head.

registerLeftSideIndexAnalysisSecondPass still runs before applyParallelReplicas (optimizeTree.cpp:377-380 vs. 422), so the coordinated ReadFromMergeTree can already have join_runtime_filters_for_index_analysis populated when applyParallelReplicas later marks it as is_parallel_reading_from_replicas = true (applyParallelReplicas.cpp:630-636, ReadFromMergeTree.h:480-483). disableUnusedRuntimeFilterKeyRangeTracking then sees only those stale descriptors and keeps the build step alive, but the actual read will refuse to consume them because canUseJoinRuntimeFilterIndexAnalysis now returns false on that same step (ReadFromMergeTree.cpp:2916-2944).

So the plan/pipeline drift you said d25d7be071a5 removed is still there for plan-based parallel replicas: those queries can still pay the build-side getExtremes pass without any probe-side pruning. This needs either descriptor retraction/revalidation when applyParallelReplicas marks a read for replica coordination, or a rerun of disableUnusedRuntimeFilterKeyRangeTracking after that rewrite.

alexey-milovidov and others added 3 commits September 10, 2026 18:34
…me filter

Addresses the review finding that "a `ReadFromMergeTree` registered a
descriptor" is not the same thing as "a pruning predicate can actually be
built".

A `LEFT ANTI` join builds its runtime filter as `ExactNotContains`, whose
`range_positive` is false, so `RuntimeFilter::getRecordedKeyValues` and
`RuntimeFilter::getRecordedKeyRanges` both return nothing and
`convertRuntimeFilterToKeyConditionDAG` can never produce a predicate from it.
`registerLeftSideIndexAnalysisSecondPass` still registers a descriptor for the
single-key ANTI shape, so `disableUnusedRuntimeFilterKeyRangeTracking` used to
keep `track_key_range` on there and the build side paid an extra
`column.getExtremes` pass over every chunk for a query that can never prune.

Two changes:

- `BuildRuntimeFilterStep` is now constructed with `track_key_range = false`
  whenever `check_left_does_not_contain` holds - both for the per-column
  filters of a single-key ANTI join and for the tuple filter of a multi-key
  one, which is always negating.
- `disableUnusedRuntimeFilterKeyRangeTracking` now matches reads against build
  steps in both directions: it first drops the read-side descriptors of filters
  whose build step cannot produce a positive predicate (so the dynamic-predicate
  machinery is not installed for them at all), and only then disables tracking
  for the build steps no remaining descriptor consumes.

`05175_join_runtime_filter_key_range_tracking` gets three `EXPLAIN` cases: a
single-key ANTI join on the primary key, a multi-key one, and a query that has
a prunable `INNER JOIN` filter and an ANTI filter side by side - the last one
prints `1` and `0` for one setting value, so it proves the decision is per
filter.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 9b4424a721b1.

  1. Fixed our own CI red. The three Unit tests (asan_ubsan / tsan / msan) failures were mine: after splitting key range tracking off index analysis, RuntimeFilterIndexAnalysis::enable no longer implies recording the [min, max] range, so the RuntimeFilterLookup gtests that assert getRecordedKeyRanges have to call enableKeyRangeTracking explicitly, exactly as BuildRuntimeFilterTransform does. Added IndexAnalysisWithoutKeyRangeTrackingRecordsNoRange as the control of the split. 18/18 RuntimeFilterLookup.* pass locally.

  2. Adopted the remaining AI Review finding (thread on ReadFromMergeTree.cpp): dynamic_skip_index_filter was consulted inside the per-index loop, so a bloom_filter-only probe key whose runtime filter overflowed join_runtime_filter_exact_values_limit still paid the per-part dynamic predicate and then pruned nothing. MergeTreeIndexReadResultPool::build now collects the usable dynamic skip indexes first and builds the predicate only when a consumer is left. 05245_join_runtime_filter_bloom_filter_index additionally asserts RuntimeFilterGranulesConsidered: 0 for the overflowed case, non-zero for every case that prunes.

The only other red, 05227_storage_settings_unknown_name, is fleet-wide on master and unrelated to this PR; the fix is #121163 (still open).

Local: 45/45 *join_runtime_filter* pass in three randomized runs, plus 03716 and the 0524x family.

Comment thread src/Core/Settings.cpp Resolved
alexey-milovidov and others added 2 commits September 20, 2026 19:29
…ed fixed-hash-table filter is published

`HashJoin::publishSharedRuntimeFilters` replaced the runtime filter registered by
`BuildRuntimeFilterStep` with one that probes the join's own `FixedHashMap`, and
copied `getRecordedKeyValues` / `getRecordedKeyRanges` once at that moment. The
publication can run before the last stream-local filter has registered, and the
metadata accessors expose nothing until every merge has happened, so the copy was
empty for good: the later `IRuntimeFilterLookup::add` calls reached the no-op merge
path of `SharedFixedHashTableRuntimeFilter` and could no longer contribute. With
both `join_runtime_filter_from_fixed_hash_table` and
`enable_join_runtime_filters_index_analysis` on by default, a multi-stream build
could therefore lose granule pruning on the probe side nondeterministically and
fall back to the row-wise `__applyFilter`.

`IRuntimeFilterLookup::replace` now keeps the superseded filter as the
index-analysis metadata source of the replacement, and `RuntimeFilter` forwards
`merge`, `finishInsert`, `getRecordedKeyValues` and `getRecordedKeyRanges` to it.
Probing still goes through the complete hash table from the moment of publication,
while the exact key set and the `[min, max]` key range are finished by the late
registrations exactly as they would have been without the publication. Nothing is
snapshotted any more, so the ordering no longer matters.

`RuntimeFilterLookup.LateAddAfterSharedFilterPublicationFailsOpenForIndexMetadata`
pinned the old outcome and becomes
`LateAddAfterSharedFilterPublicationCompletesIndexMetadata`;
`SharedFilterPublicationKeepsCompleteIndexMetadata` is the control for the
already-complete case. `05246_join_runtime_filter_shared_fixed_hash_table_index_analysis`
pins the end-to-end contract: a multi-part build side that converts to a
`FixedHashMap` still drops granules on the probe side, and drops none with index
analysis off.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed b7b8caaf86a5, addressing the single Major of the Not ready yet AI Review verdict on c0c05819bea7.

The finding is real. HashJoin::publishSharedRuntimeFilters snapshotted getRecordedKeyValues / getRecordedKeyRanges when it swapped in the SharedFixedHashTableRuntimeFilter. Those accessors expose nothing until every stream-local filter has merged, and the publication can run before the last BuildRuntimeFilterTransform::finish(), so a snapshot taken then was empty for good — the late lookup->add calls reached the no-op merge path and could not repair it. With join_runtime_filter_from_fixed_hash_table and enable_join_runtime_filters_index_analysis both default-on, a multi-stream build could lose probe-side granule pruning nondeterministically.

Fix: remove the snapshot. IRuntimeFilterLookup::replace keeps the superseded filter as the index-analysis metadata source of the replacement, and RuntimeFilter forwards merge, finishInsert, getRecordedKeyValues and getRecordedKeyRanges to it. Probing goes through the complete hash table from the moment of publication as before; the exact key set and the [min, max] range are finished by the late registrations exactly as they would have been without any publication. Details and the reasoning for picking this over delaying publication are in the thread reply.

Tests: the gtest that pinned the old outcome becomes LateAddAfterSharedFilterPublicationCompletesIndexMetadata (fails on the pre-fix binary, so it is the control), plus SharedFilterPublicationKeepsCompleteIndexMetadata for the already-complete case and a new 05246_join_runtime_filter_shared_fixed_hash_table_index_analysis pinning the end-to-end contract. Local: 19/19 RuntimeFilterLookup.* gtests, 51/51 *runtime_filter* stateless tests.

The two red performance shards on c0c05819bea7 are not ours. Both confirmed regressions are on queries without a JOIN, so neither enable_join_runtime_filters_index_analysis nor the MergeTreeIndexReadResultPool change (guarded by dynamic_predicate_builder, which only exists for runtime filters) can reach them:

  • order_by_read_in_order #1 (amd/3, +20.0%) — SELECT * FROM hits_100m_single ORDER BY CounterID DESC, ..., and the shard is labelled under-utilized RAM, under-utilized CPU.
  • cryptographic_hashes #18 (arm/5, +75.4%) — a pure hash-function benchmark, shard labelled under-utilized CPU, disk-almost-full.

The same run shows what the PR is actually for: 8 faster, 2 slower over 6994 queries, with tpcds #36 / #81 / #20 at -1.86x / -1.94x / -1.44x and top_k_through_join #0 at -1.86x on amd and -1.51x on arm.

alexey-milovidov and others added 3 commits September 21, 2026 14:25
…read time

`RuntimeFilterIndexAnalysis` records a `[min, max]` key range only for the
types `supportsDataType` accepts (integers and date-like), but the build side
collects a runtime filter for `String` keys as well. Once such a filter
overflows `join_runtime_filter_exact_values_limit` it keeps no exact values
either, so `convertRuntimeFilterToKeyConditionDAG` can only return `nullptr`
and no pruning is possible any more - regardless of how index-capable the
probe side is.

`MergeTreeIndexReadResultPool` still acquired the data part before asking for
the predicate, so a `String` primary key or a `set`-indexed `String` key paid
that per-part work for nothing. Ask `dynamic_predicate_builder` first and enter
the pruning path only when it produced a predicate.

New test `05247_join_runtime_filter_string_key_no_range` pins the contract:
`RuntimeFilterGranulesConsidered` is zero for both overflowed `String` shapes,
while the exact-values controls and the integer key of the same size (which
still records a range) do prune.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

alexey-milovidov commented Sep 21, 2026 •

Copy link
Copy Markdown
Member Author

🕵 Pushed d791ccacc41a + 5df3e12b98da (master merged on top, 466 commits behind before).

The Request changes verdict (AI Review of 2026-09-21) — adopted

The remaining Major was real: RuntimeFilterIndexAnalysis::supportsDataType records a [min, max] range only for integer and date-like keys, so a String join key never gets one. Once its filter overflows join_runtime_filter_exact_values_limit it also keeps no exact values, and convertRuntimeFilterToKeyConditionDAG can then only return nullptr — no pruning is possible any more, however index-capable the probe side is.

I did not make the plan-level admission type-aware, on purpose: the overflow is not knowable at plan time, and a String key whose build side stays under the limit prunes perfectly well through the primary key or a set index. Vetoing those keys statically would give up a working optimization for the common case.

Instead the read-time path now costs nothing when no predicate can exist. MergeTreeIndexReadResultPool::build used to acquire the data part (and throw for a part-less read) before it ever asked dynamic_predicate_builder for a predicate; the predicate is now built first and the whole pruning block, data part included, is entered only when one came back.

New test 05247_join_runtime_filter_string_key_no_range:

  • String primary key and set-indexed String key, 5000-value build side with join_runtime_filter_exact_values_limit = 1000 → RuntimeFilterGranulesConsidered is 0, a true no-op;
  • the same two shapes with a 5-value build side → granules considered and dropped (the controls that prove the queries would prune if they could);
  • an integer primary key with the same 5000-value build side and limit → still prunes, because it records a range. That is the control for the overflow itself.

Local: 49/52 *runtime_filter* stateless tests pass; the 3 reds are CLUSTER_DOESNT_EXIST for parallel-replica clusters my local server does not define.

CI reds on b7b8caaf86a5 — all unrelated

3 performance shards. read_in_reverse_order_final #0 (+25.9%, amd/2), order_by_read_in_order #1 (+20.8%, amd/4) and and_compare_chain_derived #2 (+23.1%, arm/5). The first two contain no JOIN at all, so no code this PR touches is reachable from them. and_compare_chain_derived #2 does join, but both its tables are ENGINE = MergeTree ORDER BY tuple() with no skip indexes, so no descriptor is ever registered and the index-analysis path is a no-op there too.

All three are also within their own noise floor. Over the last 21 days, comparing the ::old and ::new durations recorded per run in the checks table, the relative deviation exceeds the ~13.9% threshold in:

query shards runs over threshold max deviation
read_in_reverse_order_final #0 12 3494 26.0 – 44.1% 150%
order_by_read_in_order #1 12 3495 31.3 – 50.0% 61.5%
and_compare_chain_derived #2 10 3514 36.9 – 47.2% 68.8%

The reported +20…+26% all sit comfortably inside that band. (and_compare_chain_derived #2 on this very shard was refuted the same way on #120808 yesterday.) Shard-wide the run is 9 faster / 6 slower over 6992 queries, which fetch_perf_report.py summarises as no significant performance changes.

Stress test (amd_debug) — Logical error: 'Cannot write to canceled buffer' in PostgreSQLProtocol::Messaging::ErrorOrNoticeResponse::serialize via PostgreSQLHandler::processQuery. That is the known open #118344, nothing to do with JOIN runtime filters; the fix is already in flight as #118369.

Build profile diff — RuntimeError: CI logs cluster query failed again, the CI logs cluster infrastructure. Open fix: #121048.

…ap of the JOIN runtime filter

A probe key that only a `bloom_filter` skip index covers is pruned with the
exact values of the runtime filter, but `ReadFromMergeTree` admits the index
only while the filter keeps at most `join_runtime_filter_exact_values_limit / 100`
values (100 with the default limit). The description of
`enable_join_runtime_filters_index_analysis` claimed the pruning lasts until
the filter overflows the limit, which is a stronger contract than the code
implements. The cap is deliberate: the index tests the `IN` set one value at
a time for every granule and its false positives add up over the set, so a
few hundred values with the default 0.025 rate make every granule test positive.

Describe the real contract in the setting text, explain the cap next to the
code, and pin it with `05248_join_runtime_filter_bloom_filter_index_cap`:
500 exact keys below the limit but above the cap are not pruned
(`RuntimeFilterGranulesConsidered` = 0, so the predicate is not even built),
raising the limit so the cap covers them prunes again, and a `minmax` index
takes the same set as is.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pass of 2026-09-22 on this PR.

  • CI on the previous head 5df3e12b98da was green: 161 checks passed, 0 failed, only CH Inc sync still pending. Not re-merged master (305 behind, but merged on 2026-09-21 and the branch is green).
  • The AI review verdict (Request changes, one Major) about the bloom_filter-only admission cap in ReadFromMergeTree is addressed in 951e244 by documenting and pinning the real contract: the cap of join_runtime_filter_exact_values_limit / 100 exact values is deliberate (the index tests the IN set per value and per granule, and its false positives add up over the set), so the setting text now states it, a comment next to the code explains it, and the new 05248_join_runtime_filter_bloom_filter_index_cap pins it with a raised-limit control and a minmax control. Details in the thread reply.
  • Local: 05248 passes 3 of 3 randomized runs; 05245, 05247 and 04611_join_runtime_filters_index_analysis_skip_index pass on the rebuilt branch binary.
  • Remaining unresolved threads: the @rschu1ze wording thread (answered, left for a human) and the AI cap thread (answered above).

…lters_index_analysis` describes only the default flip

The `26.9` record already states that the JOIN runtime filters became a Production tier feature; repeating that sentence in the `26.10` record made `system.settings_changes` claim the tier change twice. The `26.10` record now describes only the `false` -> `true` default change and its contract.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pass of 2026-09-22 (second) on this PR.

  • CI on 951e244c74d6 was green: 159 checks passed, 0 failed, only CH Inc sync and the aggregate PR job still pending. Not re-merged master (465 behind, but merged on 2026-09-21 and green).
  • The AI review verdict (Not ready yet, one Major) about three system.settings_changes rows for enable_join_runtime_filters_index_analysis is addressed in 3408012: the 26.10 record no longer repeats the "became a Production tier feature" sentence that the released 26.9 record already carries, so it describes only the default flip. The two 26.9 rows are master's history from Make join runtime filters non-experimental #117383 and the setting's introduction and stay as they are. Details in the thread reply.
  • Remaining unresolved threads: the @rschu1ze wording thread (answered, left for a human) and the AI history thread (answered above).

…s_index_analysis` depends on the key type

`RuntimeFilterIndexAnalysis::supportsDataType` records the key range only for
integer and date/date-time keys, so after the filter overflows
`join_runtime_filter_exact_values_limit` a `String` (or float, `Decimal`, `UUID`)
key is not pruned at all, as `05247_join_runtime_filter_string_key_no_range`
shows. State this in the setting description and the `26.10` history record.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 148e11f: the enable_join_runtime_filters_index_analysis description and its 26.10 history record now state that the key-range fallback after overflowing join_runtime_filter_exact_values_limit exists only for integer and date/date-time keys (review thread).

The two stress reds on 3408012 are unrelated to this PR:

alexey-milovidov and others added 3 commits September 23, 2026 02:28
…-filters-index-analysis

# Conflicts:
#	src/Core/SettingsChangesHistory.cpp
…analysis

With `enable_join_runtime_filters_index_analysis` enabled by default, a join on
a sorting key column still pruned the probe side by the primary key under
`use_primary_key = 0`, because neither the plan-level registration in
`addJoinRuntimeFilterIndexAnalysisOnDataRead` nor the read-time admission in
`initializePipeline` looked at the setting. Both now apply the same gate as the
ordinary primary key analysis: with `use_primary_key = 0` a key column is pruned
only by a skip index covering it, and without one no descriptor is registered,
so the build side does not track the key range either.

`05249_join_runtime_filter_index_analysis_use_primary_key` pins the plan
(`Key range tracking`) and `RuntimeFilterGranulesConsidered`/`Dropped` for the
three shapes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…lter

The `join_runtime_filter_exact_values_limit / 100` cap for a `bloom_filter`
skip index was only a yes/no gate for the whole index: as soon as one runtime
filter on its column stayed within the cap, the index was applied with the
shared predicate, which `buildRuntimeRangePredicate` builds from every
descriptor - so a sibling exact set above the cap (`p.k = b1.k AND p.k = b2.k`)
was still hashed and tested per granule.

`MergeTreeSkipIndexReader::DynamicSkipIndexFilter` now returns a
`DynamicSkipIndexUse` (`Skip`, `Shared` or `Own`), and `DynamicPredicateBuilder`
takes the index an `Own` predicate is built for. `ReadFromMergeTree` gives a
`bloom_filter` index its own predicate from the cap-admitted filters only; the
primary key and the other skip indexes keep the shared predicate, built once
per part as before.

`05250_join_runtime_filter_bloom_filter_index_cap_per_filter` pins the
same-key two-filter shapes (one filter on each side of the cap, and two
admitted filters).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 4f3aee29aec8:

  • Merged master (1101 commits behind; one conflict in SettingsChangesHistory.cpp, where both sides added a 26.10 record, so I kept both).
  • df8036d fixes the AI Major about use_primary_key = 0: the setting is now honored at plan registration and at read-time admission. Covered by the new 05249 test.
  • 4f3aee2 fixes the AI Major about the bloom_filter cap: it now applies to each runtime filter, and a bloom_filter index gets its own predicate built only from the admitted filters. Covered by the new 05250 test.

Locally, on a fresh build of this branch, all *runtime_filter* tests pass, and the new tests passed 16 of 16 randomized runs together with 05245 and 05248. The only red on the previous head was Performance Comparison (amd_release, master_head, 6/6), on encrypt_decrypt #2 (+41%, right at its 41.4% threshold). That query has no join, so it cannot reach the runtime-filter path. On play it has 1346 successes across 198 PRs in the last 14 days and has never been reported slower elsewhere, so I read it as one-off noise; the new push re-runs it.

Comment thread src/Core/SettingsChangesHistory.cpp Resolved
alexey-milovidov and others added 2 commits September 23, 2026 05:49
…-filters-index-analysis

Master moved the `BuildRuntimeFilterStep` / `BuildRuntimeFilterTransform` parameters into
`RuntimeFilterBuildOptions` (`f6d52e79fada`). The PR's split of index analysis from key range
tracking is carried over as a new `RuntimeFilterBuildOptions::index_analysis` field next to
`track_key_range`; `disableIndexAnalysis` / `disableKeyRangeTracking` now update `build_options`.
…aveats in the `26.10` settings history record

The `system.settings_changes` text for the `enable_join_runtime_filters_index_analysis` flip now says
that a key covered only by a `bloom_filter` index is pruned only while the filter keeps at most
`join_runtime_filter_exact_values_limit / 100` exact values (pinned by
`05248_join_runtime_filter_bloom_filter_index_cap`), and that with `use_primary_key = 0` a primary
key column is pruned only by a skip index that covers it (pinned by
`05249_join_runtime_filter_index_analysis_use_primary_key`), same as the setting description.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 1001f907e449:

  • Merged master again. The PR had become CONFLICTING because master moved the BuildRuntimeFilterStep / BuildRuntimeFilterTransform parameters into RuntimeFilterBuildOptions (f6d52e79fada). The PR splits index analysis from key range tracking, so that split now lives in a new RuntimeFilterBuildOptions::index_analysis field next to track_key_range. disableIndexAnalysis and disableKeyRangeTracking now update build_options, and the LEFT ANTI filters keep both flags off, as before.
  • Addressed the review thread on the 26.10 SettingsChangesHistory record. It now mentions the bloom_filter cap (join_runtime_filter_exact_values_limit / 100) and the use_primary_key = 0 caveat, matching the setting description.

Local: the merged clickhouse binary builds, and all 56 *runtime_filter* stateless tests pass against it.

… pruning

The replacement `SharedFixedHashTable` filter is `isReady` at once, but only
`__applyFilter` looks at that; granule pruning reads `getRecordedKeyValues` /
`getRecordedKeyRanges`, which forward to the superseded filter and stay empty
until its last registration, with or without the replacement.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@rschu1ze

Copy link
Copy Markdown
Member

Obsoleted by #121859

@rschu1ze rschu1ze closed this Sep 24, 2026
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Oct 13, 2026
…on computed

`PartsSplitter::buildFilters` cloned the sorting key AST into the per-layer
border predicate and `applyRangeFilterFromAST` resolved it again with the
query's `ExpressionAnalyzer`. A key expression whose result type depends on a
session setting - `CAST(json.b, 'String')` is `String` in a table created
under `cast_keep_nullable = 0` and `Nullable(String)` in a session with
`cast_keep_nullable = 1` - then became a different function with different
values: the row whose `json.b` is missing is `''` for the table and `NULL`
for the query, the layer filter `tuple(key) > tuple(border)` evaluated to
`NULL` for it, and `FilterSortedStreamByRange` dropped the row from every
layer. Visible as a wrong `FINAL` result, and in CI as
`05187_read_in_order_key_type_setting_divergence` losing its `NULL` rows
whenever the randomized settings paired `index_granularity = 1` with
`merge_tree_read_split_ranges_into_intersecting_and_non_intersecting_injection_probability`.

Every caller (`readByLayers`, the distributed `FINAL` lanes in
`MergeTreeFinalMerge`) runs the table's own sorting expression on the pipe
right before the filter, so the key columns are already in the stream under
their `getColumnName` names. The filter now refers to them by name and is
resolved against the stream header instead of the table columns, so it
compares exactly the values the layers were split by.

Test `05217_parts_splitter_layer_filter_key_type_divergence`: a
`ReplacingMergeTree FINAL` and a forced split on an ordinary read under the
diverged type, each losing the `NULL` row before the fix, plus a same-type
control.

Related: ClickHouse#119385
CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117375&sha=9e46ee24a0a6d36d1f40aea2f3c12fbb65608268&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 (PR ClickHouse#117375)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... pr-performance Pull request with some performance improvements submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants