Repository navigation
Support skip indexes in ranges refiner - #112296
Conversation
Generalize `ProjectionIndexReadRangesRefiner` into `IndexReadRangesRefiner`: mark ranges fully filtered out by indexes evaluated at data-read time are dropped in MergeTree read pools before a read task is created for them. Previously only the projection index bitmap was applied this way; now the skip index read result (`use_skip_indexes_on_data_read`), including the top-k threshold check and runtime filters from JOIN, is applied as well. The granule-skipping predicate is factored into `MergeTreeIndexReadResult::canSkipMark`, shared between the refiner and `MergeTreeReaderIndex`, so task-cut time and read time decisions cannot diverge. Applying the top-k threshold earlier is sound because `TopKThresholdTracker` only tightens monotonically. Replace the setting `use_projection_index_in_read_pools` (introduced in the same unreleased version) with a single common setting `use_indexes_refiner_in_read_pools` that covers both index kinds. Follow-up to: ClickHouse#110291 Co-Authored-By: Claude Fable 5 <[email protected]>
With a `set` index over ~350k granules the index granule read dominates the query (~1s measured via `FilteringMarksWithSecondaryKeysMicroseconds`) and hides the refiner effect below the report threshold (~3%). A `minmax` index prunes the same granules (`needle` sorts above every `hay_*` value) but is much cheaper to read, making the refiner win visible: ~29% on both the default and the prefetched read pool in local runs. Co-Authored-By: Claude Fable 5 <[email protected]>
Numeric min/max comparisons are cheaper and more representative for a minmax index than strings, and the pruning logic is easier to see: hay granules cover [0, 63] while the needle value 9999 lies outside every such range. Pruning is unchanged: 196 of 351563 marks selected, the rest dropped by the ranges refiner at task-cut time. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [3212298] Summary: ❌
AI ReviewSummaryThis PR generalizes the Findings
Final VerdictNeeds changes: regenerate the autogenerated settings documentation for the renamed setting before merge. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 97/99 (97.98%) · Uncovered code |
The CI test profile sets `max_rows_to_read` (tests/config/users.d/limits.yaml), and with the default `read_overflow_mode = 'throw'` this disables applying skip indexes at data-read time entirely (`supportsSkipIndexesOnDataRead`): the skip index is applied during index analysis instead and the ranges refiner has nothing to drop, so the ProfileEvents assertions returned 0. Pin `max_rows_to_read = 0` in the test. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112296&sha=a9232d5bc1c5a71896a1e4abbaa67211636508f1&name_0=PR&name_1=Fast%20test PR: ClickHouse#112296 Co-Authored-By: Claude Fable 5 <[email protected]>
The skip index reader applies JOIN runtime filters with a once-per-part, fail-open snapshot. The refiner builds the per-part index read result at task-cut time, possibly before the build side has published the filters, which would cache the result without runtime pruning for the whole part. Do not create the refiner when runtime filters can prune through the primary key or dynamic skip indexes, so the result is built at reader initialization as before. Resolves review comment: ClickHouse#112296 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
The setting was already present in the SettingsRandomizer dict; the second key silently overrode the first. Co-Authored-By: Claude Fable 5 <[email protected]>
|
I've tested this PR on S3 and noticed that some queries may slow down due to increased fragmentation of read ranges and a higher number of Examples of queries: With text index With refiner: SELECT message
FROM text_log_large_indexed_v3
WHERE hasAllTokens(message, 'key=2046511834937189626')
SETTINGS enable_filesystem_cache = 0, enable_parallel_replicas = 0, use_indexes_refiner_in_read_pools = 1Without refiner: SELECT message
FROM text_log_large_indexed_v3
WHERE hasAllTokens(message, 'key=2046511834937189626')
SETTINGS enable_filesystem_cache = 0, enable_parallel_replicas = 0, use_indexes_refiner_in_read_pools = 0With set index With refiner: SELECT count()
FROM text_log_large_indexed_v3
WHERE pull_request_number = 56944
SETTINGS enable_filesystem_cache = 0, enable_parallel_replicas = 1, use_indexes_refiner_in_read_pools = 1Without refiner: SELECT count()
FROM text_log_large_indexed_v3
WHERE pull_request_number = 56944
SETTINGS enable_filesystem_cache = 0, enable_parallel_replicas = 1, use_indexes_refiner_in_read_pools = 1 |
`04653_join_runtime_filters_index_analysis_refiner` asserts that `RuntimeFilterGranulesConsidered` and `RuntimeFilterGranulesDropped` are non-zero, but its probe side (`refiner_fact`) has only 2000 rows, while `clickhouse-test` randomizes `join_runtime_filter_min_probe_rows` uniformly over 1..10000. Whenever the draw exceeds 2000 no runtime filter is built at all and both counters collapse to zero, so the test prints `0 0` instead of `1 1`. All 14 failing runs in CI drew a value above 2000, the smallest being 2036. Pin `join_runtime_filter_min_probe_rows = 0`, and also pin `query_plan_optimize_join_order_randomize = 0` because the asserted granule-pruning counts depend on which side of the join builds the filter. These are the same two pins that `04490`, `04611` and `04612` already carry; the test was modelled on `04611` before they were added there. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112296&sha=381c5ffae13e6bc74d8cdf677b773e55395ec25c&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 Related: ClickHouse#112296 Related: ClickHouse#111691 Co-Authored-By: Claude Opus 5 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 101/105 (96.19%) · Uncovered code |
`merge_tree_read_split_ranges_into_intersecting_and_non_intersecting_injection_probability` is randomized by the test harness and drawn per query. When it fires, `splitPartsWithRangesByPrimaryKey` replaces the read pool with in-order layer reads and the mark on a layer boundary is read by both layers, so `read_rows` grows by one granule while `SelectedMarks` and the runtime filter pruning counters stay identical. The two runs of the test flip the coin independently, which breaks the `read_rows` parity assertion. The effect needs `num_streams > 1`, so it only shows up on remote storage: on a local disk the small part collapses to a single stream and the draw is inert. Hence the failure was exclusive to the s3 storage job. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112296&sha=e865dc2ac565051199b4226e12835ebf67a4745e&name_0=PR ClickHouse#112296 Co-Authored-By: Claude Opus 5 <[email protected]>
The merge of `master` into this branch kept both the renamed history entry `use_indexes_refiner_in_read_pools` and the old `use_projection_index_in_read_pools` entry that master still carries from ClickHouse#110291, while `Settings.cpp` merged cleanly and declares only the new name. `SettingsImpl::applyCompatibilitySetting` calls `getTier` for every history entry newer than the requested version, and `getTier` throws `UNKNOWN_SETTING` for a name that is not declared. A dangling entry therefore makes every `SET compatibility = ...` fail, which broke 25 otherwise unrelated fast tests. The old name was introduced in the same unreleased 26.8 cycle and never shipped, so its history entry is simply dropped. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112296&sha=c3a5f3209fa04b588d5c4cfc51921e9bdeae8ad8&name_0=PR&name_1=Fast%20test Related: ClickHouse#112296 Co-Authored-By: Claude Opus 5 <[email protected]>
`use_projection_index_in_read_pools` was renamed to `use_indexes_refiner_in_read_pools` in this pull request. The previous commit dropped its settings history entry, which the style check `settings_changes_history` rejects: a removed record is indistinguishable, from the diff alone, from a default change that was reverted without being recorded, and the check's only exemption is a change touching `src/Core/SettingsChangesHistory.cpp` alone - which a rename can never be, since it edits `src/Core/Settings.cpp` too. Declare the old name in `OBSOLETE_SETTINGS` and restore its history entry. `applyCompatibilitySetting` skips entries whose tier is `OBSOLETE`, so `SET compatibility` no longer throws `UNKNOWN_SETTING`, and `03999_stateless_settings_history` ignores obsolete settings. It also keeps configurations written against master, where the old name has been present since ClickHouse#110291, from failing to load. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112296&sha=318ff84832ea55bcc8c68f33e8860a4df16d744a&name_0=PR&name_1=Style%20check Related: ClickHouse#112296 Co-Authored-By: Claude Opus 5 <[email protected]>
Build profile diff (arm_release)No arm_release build profile data for commit 3212298 - the build was skipped, reused from cache, or predates profile upload. |
|
@KochetovNicolai, could you review the latest commits, please? |
The parameter is redundant since commit fbacf3a, which keeps `IMergeTreeReader::all_mark_ranges` in sync with the current task's mark ranges on the reader-reuse path (`MergeTreeReadPoolBase::createTask`). At every call site the passed value was equal to `getLastMark(reader->all_mark_ranges)`, so the right bound of ranged read requests on remote disks is now derived inside the reader from its own `all_mark_ranges` (cached in the `last_mark_to_read` member). This also fixes multiplied S3 read requests when a step of the readers chain reads over fragmented mark ranges: `continueReadingChain` computed the bound from the ranges started by the current read block only, not from the whole task, so with fragmented task ranges (e.g. a skip index applied at index analysis time plus `PREWHERE`) the bound advanced on every read block, and every advance cancelled the buffer's prefetch and issued a new small read request. Patch readers are now refreshed with their per-task mark ranges on the reader-reuse path (`MergeTreeReadTask::Readers::updateAllMarkRanges`), because their right bound now also comes from their own `all_mark_ranges`. Related: ClickHouse#112296 Related: ClickHouse#112296 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
6c239f5 to
3042e31
Compare
3042e31 to
c8fcfdd
Compare
Test `04812_prewhere_fragmented_ranges_s3_read_requests` now runs the same `PREWHERE` query twice: with the mark ranges of a read task fragmented by index analysis, and with them fragmented by the ranges refiner in read pools (`use_indexes_refiner_in_read_pools`). Both cases assert that the number of S3 read requests stays low; the refiner case also asserts that the refiner did drop marks, so it cannot silently degrade into the analysis path. Checked against the release build of the last commit without the fix for read fragmentation (`2de0d16b63b`): the analysis case issues 99 S3 read requests and the refiner case 189 (with 3375 marks dropped by the refiner), versus 7 and 3 with the fix. Test `04654_skip_indexes_refiner_remote_disk` is removed. It asserted the shrink-only refinement of ranges of parts on remote disks, which was dropped in `c8fcfdd09cc` because the right bound of ranged read requests now spans the whole read task. Build report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112296&sha=2de0d16b63bf36975d10da3068a0d9fc025c7825&name_0=PR&name_1=Build+%28amd_release%29 Related: ClickHouse#112296 Related: ClickHouse#113584 Co-Authored-By: Claude Opus 5 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR renames the read-pool projection-index setting to use_indexes_refiner_in_read_pools and extends the read-pool mark-range refiner to also cover skip indexes, with a guard so JOIN runtime filters aren't snapshotted early. The refiner is gated behind a setting that defaults off, and everything on the default path is an identical-logic refactor (canSkipMark/canSkipAnyMark moved onto the index read result). ClickBench Q16 and Q17 are plain aggregation scans that don't enable the refiner, so neither flagged delta (Q17 +19.0%, Q16 +11.6% and already within master's variance band) can be attributed to this change — both read as run-to-run variance. Q17 is downgraded to not_sure accordingly. 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
|
4641beb
Changelog category (leave one):
Additional context
Added support for refining
MergeTreeranges using the analysis result of skip indexes, in addition to the result of the projection index introduced in #110291. PR is not for the changelog, because the changelog should have one entry from #110291.Version info
26.8.1.999(included in26.8and later)