Skip to content

Document and pin the no-op modes of enable_join_runtime_filters_index_analysis - #119041

Merged
alexey-milovidov merged 6 commits into
masterfrom
join-runtime-filter-index-analysis-distributed-noop
Sep 25, 2026
Merged

alexey-milovidov merged 6 commits into
masterfrom
join-runtime-filter-index-analysis-distributed-noop

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Related: #117383

enable_join_runtime_filters_index_analysis became a Production tier setting in #117383, but the second-pass granule pruning it asks for only happens for a left side that is read locally. The descriptors driving it are attached to ReadFromMergeTree while the query plan is optimized, and they are carried by neither clone nor serialize/deserialize; on top of that initializePipeline skips the pruning outright under parallel replicas. So with make_distributed_plan = 1, or with parallel replicas (coordinator-driven or plan-based), the setting silently does nothing — which overstates the supported surface for a production-tier setting. Since #121859 the setting is also enabled by default, so these modes now apply to every query rather than only to users who opted in.

Making those modes throw is not an option: the setting is an optimization hint, and rejecting a JOIN because its left side is read remotely would break working queries for no benefit. So the supported surface is now stated where a user looks for it, following the convention of the other production-tier settings that only apply to a subset of execution modes. The setting description now says that the pruning does not happen with enable_parallel_replicas = 1 or make_distributed_plan = 1, that the results are unchanged there, and that the JOIN runtime filter itself is unaffected.

The new test 05153_join_runtime_filters_index_analysis_distributed_noop pins that contract in all four modes: a local read prunes granules (RuntimeFilterGranulesConsidered and RuntimeFilterGranulesDropped are nonzero), while a distributed query plan, coordinator-driven parallel replicas and plan-based parallel replicas prune none — and all four return the same rows.

Measured on a local build, summing the profile events of every query sharing the initiator's initial_query_id:

mode RuntimeFiltersCreated RuntimeFilterRowsChecked RuntimeFilterGranulesConsidered RuntimeFilterGranulesDropped
local 1 64 125 121
make_distributed_plan = 1 0 0 0 0
parallel replicas 3 6000 0 0
plan-based parallel replicas 1 2000 0 0

A local read served from a normal projection is not one of the no-op modes: optimizeUseNormalProjections used to rebuild the left side's read step and copy only the TopK state, which dropped the descriptors silently. The projection read now gets them through copyJoinRuntimeFilterIndexAnalysisDescriptors (each one re-checked against the projection's own primary key and skip indexes) and builds its index templates on demand, since its analysis result is precomputed. The new test 05223_join_runtime_filters_index_analysis_normal_projection pins that a projection sorted by the join key prunes granules and a projection sorted by an unrelated column stays a correct plain read.

The pruning is also not implemented for a left side read with FINAL: initializePipeline skips it there (as it does for tables with pending mutations or patch parts), and optimizeLazyFinal rebuilds such reads without the descriptors. The setting description now lists those cases too, and 05243_join_runtime_filters_index_analysis_final_noop pins that a ReplacingMergeTree ... FINAL probe side returns the deduplicated result without considering any granules, while the same query without FINAL prunes.

Propagating the descriptors to worker plans, so that the optimization also applies there, stays a follow-up; the code comments at the three sites that drop them now point at the documented contract and this test.

Follows up on this review comment: https://github.com/ClickHouse/ClickHouse/pull/117383/changes#r3959601132

Changelog category (leave one):

  • Improvement

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

The granule pruning of enable_join_runtime_filters_index_analysis now also applies when the left side of a JOIN is read from a normal projection. The setting description states that the pruning does not happen with parallel replicas, a distributed query plan, or FINAL.


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

Version info

  • Merged into: 26.10.1.691-master (included in 26.10 and later)

…_analysis

`enable_join_runtime_filters_index_analysis` became a Production tier setting
in #117383, but its second-pass granule pruning only happens for a left side
that is read locally. The descriptors that drive it are attached to
`ReadFromMergeTree` during query plan optimization and are carried by neither
`clone` nor `serialize`/`deserialize`, and `initializePipeline` skips the
pruning outright under parallel replicas. So with `make_distributed_plan = 1`
or with parallel replicas the setting silently does nothing.

Making those modes throw is not an option: the setting is an optimization hint,
and rejecting a JOIN because its left side is read remotely would break working
queries for no benefit. Instead the supported surface is now stated where a user
looks for it, following the convention of the other production-tier settings
that only apply to a subset of execution modes: the setting description says
that the pruning does not happen with `enable_parallel_replicas = 1` or
`make_distributed_plan = 1`, that the results are unchanged there, and that the
JOIN runtime filter itself is unaffected.

The new test `05153_join_runtime_filters_index_analysis_distributed_noop` pins
that contract in all four modes: a local read prunes granules
(`RuntimeFilterGranulesConsidered`/`Dropped` are nonzero), a distributed query
plan, coordinator-driven parallel replicas and plan-based parallel replicas
prune none, and all four return the same rows.

Follows up on the review of #117383:
https://github.com/ClickHouse/ClickHouse/pull/117383/changes#r3959601132

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

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b67f50c]

Summary: ✅


AI Review

Summary

This PR documents the unsupported surfaces of enable_join_runtime_filters_index_analysis, adds regression tests for distributed / parallel-replica / FINAL no-op cases, and propagates the index-analysis descriptors through normal-projection rewrites so local projection reads can still prune. The remaining issue is that the new description promises a true no-op in unsupported modes, but the build side still enables runtime-filter key-range tracking in several of those modes, so the setting still adds work even when probe-side pruning can never run.

Findings

⚠️ Majors

  • [src/Core/Settings.cpp:9497] The new "no-op" contract is too strong. joinRuntimeFilter.cpp still sets RuntimeFilterBuildOptions::track_key_range straight from enable_join_runtime_filters_index_analysis, and BuildRuntimeFilterTransform / RuntimeFilter::insert still scan the build-side key column to maintain min/max state. ReadFromMergeTree::initializePipeline() only later suppresses probe-side pruning for FINAL, pending mutations / patch parts, and parallel-replica reads, so those modes still pay extra build-side work even though the recorded range can never be consumed. Either gate track_key_range on the probe read actually supporting index analysis, or narrow the user-facing contract to “results stay the same, but the extra build-side tracking may still happen.”
Final Verdict

Status: ⚠️ Request changes

Minimum required action: make the setting a real no-op in the unsupported modes that still build a runtime filter locally, or adjust the documentation/tests so they no longer claim that only probe-side granule pruning changes there.

LLVM Coverage Report

Measured on commit b67f50c.

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

Changed lines: Changed C/C++ lines covered: 40/40 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-documentation Documentation PRs for the specific code PR label Sep 9, 2026
Comment thread src/Core/Settings.cpp Resolved
@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 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b67f50c0d with master d43d60676 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

120 translation units recompiled, 1364 s compile time in total, 120 of them have a recent master baseline.

Job report

alexey-milovidov and others added 2 commits September 17, 2026 11:50
…rmal projection read

`registerLeftSideIndexAnalysisSecondPass` runs before the projection optimizations, so
the descriptors that drive the second-pass granule pruning of
`enable_join_runtime_filters_index_analysis` are attached to the base-table
`ReadFromMergeTree`. `optimizeUseNormalProjections` then replaced that step with a
fresh read from the projection and copied only the TopK state, so a JOIN whose left
side is served from a normal projection silently lost the pruning even though the
read stayed local. That contradicted the setting description this PR adds, which
promises the pruning for every local read.

The projection read now gets the descriptors through
`copyJoinRuntimeFilterIndexAnalysisDescriptors`, which registers each of them anew
via `addJoinRuntimeFilterIndexAnalysisOnDataRead`, so a descriptor survives only if
the key column is in the projection's own primary key or has an applicable skip
index there. A projection read also arrives with its analysis result precomputed,
so `selectRangesToRead` never built `indexes` for it; `initializePipeline` now
builds them on demand when descriptors are present, otherwise the
`indexes.has_value()` gate skipped the pruning.

The new test `05223_join_runtime_filters_index_analysis_normal_projection` pins it:
a projection sorted by the join key prunes granules, a projection sorted by an
unrelated column drops the descriptor and prunes none, and both return the same
rows as the base table.

Addresses the review thread on `Settings.cpp`:
#119041 (comment)

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

Copy link
Copy Markdown
Member Author

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-documentation Documentation PRs for the specific code PR labels Sep 17, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

Confirmed both, and nothing fresher exists for either.

AST fuzzer (amd_debug), STID 3293-4e7f. #111993 is the right one. The failed query is a matcher inside a lambda body under WITH ROLLUP (arrayLast(x -> (* APPLY isNull EXCEPT (...) REPLACE (...) <= x), [1, 2, 3]) ... GROUP BY ... WITH ROLLUP), aborting in ColumnFunction::appendArgument with got Nullable(UInt8), but UInt8 is expected: a matcher expanded inside a lambda keeps its pre-promotion types, so group_by_use_nulls never reaches it. That is what #111993 fixes in QueryAnalyzer::resolveMatcher, and its regression test already carries the same shape (arrayMap(z -> sipHash64(t3.*), [1]) ... GROUP BY x, y WITH ROLLUP). I matched it by STID plus query shape, not by rerunning that fuzzer query on the branch.

Worth separating: two distinct signatures share this message. 3293-4e7f (yours, lambda plus join_use_nulls / group_by_use_nulls) is #111993; the sibling 3293-46fa, which fires mostly on Stress checks with a matcher inside a lambda in PREWHERE, is #112898. Since 2026-09-01 the only occurrence of the message anywhere in CI is the one on this PR, so it is weeks older than this change and not caused by it.

Stateless tests (arm_asan_ubsan, targeted), 04891_distributed_plan_limit_early_stop. #117764 is the right one, and it covers the 05024_..._idle_sink sibling too. Both tests decided PASS/FAIL by elapsed time against their own max_execution_time = 25; every sighting overshot the cap by 0.3% to 2.6% and was green on rerun, so #117764 asserts the stop propagation instead (each exchange endpoint traces the action it takes when the stop arrives). Your #116017 is in the same area but is not the carrier for this class: the timeout kept firing after it merged on 2026-08-26. Last 30 days for the family: 37 failures over 22 distinct pull requests, plus 3 on true master, the two most recent earlier today.

Both fixes are approved and unmerged (#111993 by @ vdimir on 2026-07-29, then auto-unassigned by the 30-day inactivity bot on 2026-08-28; #117764 by @ davenger on 2026-09-02), which is why both signatures keep landing on unrelated heads.

alexey-milovidov and others added 2 commits September 23, 2026 19:15
…untime_filters_index_analysis`

The second-pass granule pruning is skipped in `ReadFromMergeTree::initializePipeline`
for `FINAL` reads, and `optimizeLazyFinal` rebuilds such reads without the join
runtime filter descriptors, so the setting description overstated the supported
local surface. Document `FINAL` (and pending mutations / patch parts, which are
skipped by the same guard) as no-op cases, and add
`05243_join_runtime_filters_index_analysis_final_noop`, which checks that a
`ReplacingMergeTree ... FINAL` probe side returns the deduplicated result without
considering granules, while the same query without `FINAL` does prune.

Review thread: #119041 (comment)

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

@alexey-milovidov alexey-milovidov left a comment

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.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 25, 2026
…-index-analysis-distributed-noop

# Conflicts:
#	src/Core/Settings.cpp
Comment thread src/Core/Settings.cpp
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, can be pruned.
If the runtime filter kept the exact key values, the pruning predicate is an `IN` set of them, otherwise the minimum/maximum key range is used (this has a lower pruning power).

Takes effect only when the probe side of the join is read locally. The descriptors that drive the pruning are attached to the read step while the query plan is optimized, and they are not carried over when that step is rebuilt for remote execution, so the granule pruning does not happen with parallel replicas (`enable_parallel_replicas = 1`) or with a distributed query plan (`make_distributed_plan = 1`). In those modes the setting is a no-op: the query returns the same result and the JOIN runtime filter itself behaves exactly as it does with this setting disabled, only the granule pruning is lost.

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 overstates the new contract. joinRuntimeFilter.cpp:174-182 still enables track_key_range directly from enable_join_runtime_filters_index_analysis, and BuildRuntimeFilterTransform / RuntimeFilter::insert still pay the extra build-side range-tracking scan when that flag is on (BuildRuntimeFilterTransform.cpp:79-81, RuntimeFilterLookup.cpp:735-746).

ReadFromMergeTree::initializePipeline() only decides later that probe-side pruning is unsupported (FINAL, pending mutations / patch parts, and parallel-replica reads at ReadFromMergeTree.cpp:5238-5251). So in those modes the setting is not actually a no-op: results stay the same, but the build side still does extra work for key-range tracking that can never be consumed. Could we either gate track_key_range on the probe read being able to use index analysis, or weaken this description/tests so they stop promising a true no-op?

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 25, 2026
Merged via the queue into master with commit 0691f4d Sep 25, 2026
177 checks passed
@alexey-milovidov
alexey-milovidov deleted the join-runtime-filter-index-analysis-distributed-noop branch September 25, 2026 18:48
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 25, 2026
pull Bot pushed a commit to erickirt/ClickHouse that referenced this pull request Sep 27, 2026
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-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants