Repository navigation
Skip granules on the left side of a JOIN using use_skip_indexes_on_data_read - #109085
shankar-iyer merged 37 commits into
Conversation
|
New setting added : |
|
Workflow [PR], commit [215190e] Summary: ✅
AI ReviewSummaryThis PR adds the experimental Findings
Final Verdict |
|
📊 Cloud Performance Report ✅ AI verdict: This PR adds an experimental, default-off JOIN runtime-filter feature (enable_join_runtime_filters_index_analysis) that prunes left-side granules; the only unconditional change is a reordering of SelectedRanges/SelectedMarks metric accounting, which does not affect execution time. All four flagged ClickBench queries are single-table with no JOIN, so none can exercise the new path, and their mixed-direction deltas (Q4 -14.8%, Q15 -20.6% faster; Q9 +10.2%, Q11 +16.1% slower) are run-to-run variance. The deterministic within-envelope suppressions are all consistent with the diff and stand as no_change / not_sure. clickbenchFlagged queries (2 of 43)
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
|
|
The comments from the review-bot are valid and easy to fix. I was hoping for some feedback on how to report back the pruning. Showing it in |
|
The best case for this PR is a large fact table joined to a filtered dimension, where the filter is on a dimension attribute The set of surviving foreign keys turns out to be small — and if the fact table has skip index on the that key, its granules get pruned (based on distribution ofcourse). Or if joining 2 large fact tables ordered by the same/similar sort key - depends on the range of IDs gathered by the RHS and the table insertion layout. Representative query - Some self joins should also be improved. |
|
Trying a run with default enable of the new setting. |
|
PR in action - 7.50 million rows v/s 1.63 million rows and pruning confirmed - |
|
@groeneai How to trigger one more run performance run like this one : #109085 (comment) |
|
Clean CI run at 35dbad4 with default enable of the new setting. |
|
@shankar-iyer That report is the Cloud Performance Report (StressHouse + MIRAI) posted by clickhouse-gh[bot], generated as part of this PR's CI run. To get another one, push a commit to the branch and the new SHA's CI produces a fresh report (that is what your 35dbad4 run does). It is internal cloud-benchmark infra tied to the commit's CI, so there is no open-repo slash command or comment trigger for it; a fresh CI run on a new commit is the mechanism. Separately, for the in-repo |
|
I will re-run TPC-H, but first read looks like not much pruning. TPC-DS is better - With only |
|
Asked Claude to run SQLStorm (10000 queries) and Claude generated below report similar to my TPC-DS run report - So the definitive, defensible SQLStorm statement for the PR: on 10,000 realistic LLM-generated analytical queries, the feature engages on ~9%, near-eliminates those queries' filtered scans (99.9% of examined granules), cuts blended rows-read by ~4.3% over 13.7B rows, and never changes a result. |
…-test` Address review feedback: add the new `enable_join_runtime_filters_index_analysis` setting to the `SettingsRandomizer` in `clickhouse-test` so the join runtime-filter left-side granule pruning path is exercised across the whole stateless test suite. The setting is result-neutral (it only prunes granules that cannot contain rows matching the runtime filter), and its effective value is already ANDed with `enable_join_runtime_filters` in `QueryPlanOptimizationSettings`, so no extra dependency handling is needed in the randomizer. The four dedicated feature tests set the setting explicitly (session-level and per-query), so the randomized session default cannot perturb their assertions. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address the AI review "Request changes" note that `enable_join_runtime_filters_index_analysis` descriptors are dropped when a `ReadFromMergeTree` step is rebuilt: the pruning state in `join_runtime_filters_for_index_analysis` is not carried by `clone`/`serialize`/`deserialize`, so left-side granule pruning is intentionally skipped for distributed (`make_distributed_plan`) and parallel-replicas reads. This is correctness-safe (the read just performs no runtime pruning; results are unchanged) and only loses the optimization. Document it in `serialize` and at the member declaration so the behavior is an explicit, discoverable limitation rather than a silent oversight, mirroring the existing parallel-replicas guard. Propagating the descriptors to worker plans is a follow-up. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 383/434 (88.25%) · Uncovered code |
|
Green CI at 215190e |
|
@shankar-iyer Could it be generalized later for any table in multiple tables JOIN? Something like #109262 ? |
4493169
Hey @4ertus2 , Right now, this PR will indeed do index analysis for a chain of multiple tables in the JOIN - if runtime filters are built at each join step (check test case I think your approach is close to the predicate transfer research I have seen - is your approach about exclusively using static index analysis and doing bidirectional (or even more) transfer of predicates and not worry about join ordering? Some thing like - Step 1 - Start with index analysis on And extend this to multiple tables. The problem is that in a column store with sparse indexes, shortlisting rows in index analysis will always be 1000s time more (coarse) and runtime filter ultimately is best for sideways information passing. Of course, some queries could do well with the above technique, maybe star schema. |
You are able to make projection index over every joining key on every query. Then you do not need dynamic filter to pass through join. select * from a join b on a.jkey = b.jkey You could pass "b.bar = 42 and a.jkey = b.jkey" predicate into a-scan. And "a.foo = 10 and b.key = a.key" into b-scan. Generally you'll have to make a dynamic filter there to apply the predicates. But there could be other options such as "make an entire HashMap if it's small" or "use merge-join". Or decide which table would be a filter (in full hash-map version) regardless of later joins order. To pass predicates top-down and then decide to make dynamic filters is more general approach then to first decide to use dynamic-filters and pass them bottom-up. Am I wrong? |
|
In other words, if you are federated engine like Trino you have to pass dynamic filters bottom up. |
The master merge `ad6c485c078` pulled in #109085 (`enable_join_runtime_filters_index_analysis`), which lets a JOIN's runtime filter prune a probe-side `MergeTree` scan through the primary key index using a filter built from the (small) build-side join keys. That is a second, independent way to shrink `read_rows` besides this PR's `IN (...)` injection, so it confounds the test's `read_rows` proofs. In particular the "optimization disabled -> full scan -> high `read_rows`" fallback proofs (`branch_local_disable_respected`, `byte_limit_fallback_full_scan`) saw the fallback scan pruned by the runtime filter instead and read far fewer rows, flipping the boolean assertion. This surfaced in the flaky check where `enable_join_runtime_filters_index_analysis` is randomized to `1`: `04489_recursive_cte_join_index` failed in several build variants. Disable JOIN runtime filters for the whole test so `read_rows` isolates the recursive-CTE `IN`-injection optimization actually under test. The optimization is semantics-preserving, so the walk results are unchanged. Verified against a `MergeTree` reproduction of the `str_walk` fallback: with runtime filters + index analysis on, the fallback scan reads only 953 rows (proof `read_rows > 10000` fails); with them off it reads the full 35057 rows (proof passes); the walk count is 7 either way. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| (SELECT sum(f.v) FROM bf_fact AS f INNER JOIN bf_dim AS d ON f.k = d.k WHERE d.tag = 'hot' SETTINGS enable_join_runtime_filters_index_analysis = 0) = | ||
| (SELECT sum(f.v) FROM bf_fact AS f INNER JOIN bf_dim AS d ON f.k = d.k WHERE d.tag = 'hot' SETTINGS enable_join_runtime_filters_index_analysis = 1); | ||
| SELECT | ||
| (SELECT sum(f.v) FROM jrf_fact AS f INNER JOIN jrf_dim AS d ON f.k = d.k SETTINGS join_algorithm = 'hash', max_bytes_before_external_join = 0, max_bytes_ratio_before_external_join = 0, enable_join_fixed_hash_table_conversion = 1, join_runtime_filter_from_fixed_hash_table = 1, enable_join_runtime_filters_index_analysis = 0) = |
There was a problem hiding this comment.
@shankar-iyer is this optimization going to work with all join algorithms, plus outer joins? What about pruning granules on the right side?
…_pk_and_skip_for_join Skip granules on the left side of a JOIN using use_skip_indexes_on_data_read
…ed reading After ClickHouse#109085: RuntimeFilterReadRangesRefiner builds its primary key condition with the shared convertRuntimeFilterToKeyConditionDAG (which also covers the bloom-overflow case through the [min, max] envelope) instead of hand-rolling the IN-set DAG, and markSealGatedReading detects the probe-side __applyFilter conjunct with findAppliedRuntimeFilters, extracted from registerLeftSideIndexAnalysisSecondPass. Since the filter records key values only on request (enable_join_runtime_filters_index_analysis defaults to off), the marking now turns the recording on through BuildRuntimeFilterStep::enableKeyRangeTracking. Co-Authored-By: Claude Fable 5 <[email protected]>
Use the
JoinRuntimeFilterto get the join keys (asetof values or just a min-maxrange) and then leverage theuse_skip_indexes_on_data_readinfra to run index analysis (primary key index and skip index) to prune granules before reading from table parts of the left hand side.Changelog category
Changelog entry