Repository navigation
Track used skip indices - #128223
Merged
Merged
Track used skip indices#128223
Conversation
Contributor
|
Workflow [PR], commit [620afc8] Summary: ✅
AI ReviewSummaryAdds Final VerdictStatus: ✅ Approve |
…rt stats, distributed analysis and unusable indexes
The counters were differences between `index_stats` entries, so they credited query condition cache exclusions to the primary key, lost skip-index totals with `per_part_index_stats`, counted the combined distributed analysis entry as primary key, and listed indexes that no part could use. `filterPartsByPrimaryKeyAndSkipIndexes` now measures the drops per layer and marks an index as used when it passes `canUseIndex` and its file exists in a part. A replica of distributed index analysis records its share in its own `query_log` entry. Proof: 05460 failed before (warm cache 0/7/0, per-part skip 0, distributed []/7/0, unusable idx_c and idx_b listed), passes now; 05459 still passes.
…ejected vector index
A vector similarity index passed canUseIndex and its file existed, so it was listed in used_data_skipping_indices, but filterMarksUsingIndex skips it when the primary key excluded some granules of the part. filterMarksUsingIndex now reports whether it evaluated the index. Test 05462 failed before (idx_vec listed with USearchSearchCount 0) and passes now.
…hole read optimizeTrivialCountFromTextIndex drops ReadFromMergeTree when the text index is materialized in all parts, so its index usage and pruning events were lost. The replacement step now reports the analysis of the replaced read once, from recordIndexUsage, which also counts the partition-key drops now. With a partially materialized index ReadFromMergeTree stays and reports as before. Test 05461 failed before ([] and 0 with the optimization) and passes now.
…e top-K filtering
…n-adaptive granularity
…ead time With a WHERE clause the analysis-time top-K step does not run, but with `use_skip_indexes_on_data_read` the dynamic top-K filter still reads the `minmax` index in `MergeTreeIndexReadResultPool`. The index was not in `used_data_skipping_indices` when the WHERE clause did not use it. Index analysis now lists it for a part that keeps ranges and has the index file, the same rule as for other read-time indexes. Drop counters are not changed. Test 05464 gave [] before and gives ['idx_a'] now.
When a normal or aggregate projection, or the implicit `_minmax_count_projection`, serves all parts, the parent `ReadFromMergeTree` is detached without `initializePipeline`, so its used skip indexes and the parts it excluded were lost. The step that replaces it now reports that analysis when its pipeline is built (`ISourceStep::setOnInitializePipeline`, set by `ReadFromMergeTree::reportIndexUsageWith`); `ReadFromTextIndexCount` uses the same mechanism instead of its own copy. Index analysis keeps the primary-key and skip-index drops of each part in `RangesInDataPart`, and `filterPartsByProjection` removes them for parts that the chosen projection reads, because the projection read reports its own analysis of them. `getMinMaxCountProjectionBlock` returns the marks of the parts that the partition key excluded. Test 05463 gave [] 0 3 0 (normal and aggregate projection) and partition drops 0 (minmax count) before; now ['idx_a'] 0 3 4 and 4.
…ta read are off The CI test profile sets `max_rows_to_read`, which turns off skip indexes on data read, so the dynamic top-K filter did not read `idx_a` in Fast test, but the index was still listed. The test now resets `max_rows_to_read` and adds a case with a throwing limit, which gives ['idx_a'] instead of [] on the current code. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128223&sha=05c0f392edb5e57bb6d78a55a29acda9397a6906&name_0=PR&name_1=Fast%20test PR: #128223
… read are in effect `skip_indexes.threshold_tracker` is set from the `use_skip_indexes_on_data_read` setting, but `MergeTreeSkipIndexReader` is created only when `supportsSkipIndexesOnDataRead` is true; a throwing `max_rows_to_read` or `max_partitions_to_read`, FINAL with exact mode or pending mutations turn it off. The dynamic top-K filter then does not read the index, but `used_data_skipping_indices` still listed it. Index analysis now also requires the effective `use_skip_indexes_on_data_read_`, the same flag that decides read-time filtering for the other skip indexes. Test 05464 gives [] for the case with `max_rows_to_read = 100000` now (before: ['idx_a']). CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128223&sha=05c0f392edb5e57bb6d78a55a29acda9397a6906&name_0=PR&name_1=Fast%20test PR: #128223
…d distributed analysis under projections Co-Authored-By: Claude Opus 5.5 <[email protected]>
`assert_cast<ISourceStep &>` checks the exact type in debug and sanitizer builds, so every projection and text index count replacement threw `Bad cast from type DB::ReadFromTextIndexCount to DB::ISourceStep`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128223&sha=434d9a14d1d3f9096e95862b8e9d6bb09df73704&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29 PR: #128223
Index analysis listed the indexes that it leaves to the read (`use_skip_indexes_on_data_read`), so a projection that replaces the read reported an index that is never read. The join runtime filter indexes were not listed at all. `ReadFromMergeTree::initializePipeline` now lists the indexes of `MergeTreeSkipIndexReader`, the top-K index of the dynamic filter and `runtime_skip_indexes` if a part that is read has the index. `ReadFromTextIndexCount` lists the text index that it reads. Tests 05463 (cases 8, 9) and 05465 give the expected lists now. PR: #128223
… analysis The reconstruction of `parts_with_ranges` copied the parts before analysis, so `filterPartsByProjection` subtracted nothing and the parent drops in parts that a projection reads were counted twice. Test 05463 case 11 gives `0 3 4` now (before: `0 3 6`). PR: #128223
…n-adaptive granularity
…ections The AI review of a57a8d3 found two reporting errors. 05466: when the first read-time index excludes every granule, `MergeTreeSkipIndexReader::read` does not evaluate the next ones, but `used_data_skipping_indices` lists them (static and join runtime filter indexes). 05467: a chosen normal or aggregate projection that excludes every granule loses its analysis (`GranulesDroppedByPrimaryKey` 0 instead of 8), and the drops of the table key in the parts it excludes are counted with it. Both tests fail on the a57a8d3 binary: 05466 cases 1 and 4 list `idx_b`, 05467 gives `0 0 0`, `4 3 0` and `0 0 0` instead of `0 8 0`, `4 4 0` and `0 4 0`. PR: #128223
`initializePipeline` listed every index of `MergeTreeSkipIndexReader` whose file exists in a part that is read. `MergeTreeSkipIndexReader::read` stops when an earlier index excludes every granule, so the later indexes were listed but never evaluated. The reader now reports each index once through `setOnIndexApplied` when `filterMarksUsingIndex` evaluates it (static and join runtime filter indexes), or when the top-K index is loaded for granules that are read. Test 05466 passes (before: cases 1 and 4 listed `idx_b`); 05459-05465 still pass. PR: #128223
When the chosen normal or aggregate projection selects no ranges, `readFromParts` returns nothing and a `ReadFromPreparedSource` replaces it, so no projection read reported its analysis. The replacing step now reports it too: `ISourceStep` keeps a list of callbacks (`addOnInitializePipeline`), so the step can also report the parent read that it replaces. Also, the parent drops were removed only for the parts that the projection reads, not for the parts that it excludes entirely, so those parts were counted twice. `analyzeProjectionCandidate` now records the parent drops of every part that the projection analyzes, and `filterPartsByChosenProjection` removes them for the chosen projection. Test 05467 passes (cases 1, 3-6 before: `0 0 0`, `4 3 0`, `0 0 0`, `4 3 0`, `0 0 0`); 05459-05466 still pass. PR: #128223
…d-skip-indices # Conflicts: # src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp
A concurrent test can clear the whole query condition cache between the first two queries, then the second query reads all granules through the index and lists it. Seen with a refreshable materialized view refresh, which calls `Context::clearCaches` (issue #131985); tables created with an explicit UUID and tables without a UUID do the same. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128223&sha=b5bb04051009f970c06ea996461d1f574bc8442d&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20distributed%20plan%2C%20targeted%29 #128223 #131985
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #26778
This change adds:
system.query_log.used_data_skipping_indicesб data skipping indexes that the index analysis applied, asdatabase.table.index, next to the existingprojectionscolumnGranulesDroppedByPartitionKey,GranulesDroppedByPrimaryKey,GranulesDroppedBySkipIndexes- how many marks each index layer excluded during index analysis ofMergeTreetables. Indexes applied at read time (use_skip_indexes_on_data_read) are not counted, the same as inEXPLAIN indexes = 1The walk over the per-query index layers is shared with
system.predicate_statistics_log, and the synthetic<Combined skip indexes>entry gets a named constant.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add the column
used_data_skipping_indicestosystem.query_logand the ProfileEventsGranulesDroppedByPartitionKey,GranulesDroppedByPrimaryKeyandGranulesDroppedBySkipIndexes, which show which data skipping indexes a query applied and how many marks each index layer excluded.Workflow [PR]
Sync PR [sync-upstream/pr/128223]
Version info
26.11.1.2708-master(included in26.11and later)