Repository navigation
Fix slow planning of queries with skip indexes on tables with pending patch parts - #124931
Conversation
… skip index `collectTextIndexReadInfos` called `getAlterConversionsForPart` for every part of the table to collect the columns updated on the fly (ClickHouse#99543) and to find whether any part has a pending patch (ClickHouse#118496). It ran for every query with any useful skip index, before checking whether one of them is a text index, over all parts of the table (they are not filtered by the index analysis yet), and the lookup of patches for a part is linear in the number of patch parts and builds the sorting key of every patch part. On tables with hundreds of parts and patch parts it added hundreds of milliseconds to the planning of point queries that use a `bloom_filter` index. Also, a single pending patch anywhere in the table turned the direct read from a text index off for the whole query. Now: - `collectTextIndexReadInfos` returns early if no useful index is a text index. - The planner rejects a text index whose columns are changed on the fly without building `AlterConversions` for every part: the columns updated by patch parts and data mutations are taken from the whole mutations snapshot, the columns changed by alter mutations are collected per part only when such mutations exist, and masking policies are parsed once. This check must stay in planning: the on-fly mutation steps are built from the columns of the query, which do not contain the indexed columns replaced by the virtual columns, and whether the preprocessor of the index is applied to the search functions must not depend on the part. - A part with pending patches (of other columns) does not read the virtual columns from the index: like a part without the materialized index, it computes them by their default expressions (the original predicates), because the patch key columns must be read in the first read step, which the reader of the text index cannot do. The other parts read the index. Related: ClickHouse#123334 Related: ClickHouse#124085 Related: ClickHouse#118496 Related: ClickHouse#99543 Related: ClickHouse/clickhouse-private#75816 Related: https://clickhouse-inc.slack.com/archives/C0B6DBVRPKJ/p1791474075046099 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…n skip index analysis `filterPartsByPrimaryKeyAndSkipIndexes` called `getAlterConversionsForPart` for every part when the query has useful skip indexes, also for the parts in which the primary key left no ranges, where skip indexes cannot filter anything. The lookup of patches for a part is linear in the number of patch parts, so on tables with many parts and patch parts (and no partition pruning) it added tens of milliseconds to the planning of point queries (e.g. 2000 parts and 50 patch parts in the performance test `skip_index_planning_with_patch_parts`). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`refreshStatistics` built the cached `ConditionSelectivityEstimator` from all active parts, including patch parts, but queries never read patch parts directly, so `isStale` always failed while a table had pending patch parts, and every query loaded the statistics of all its parts (taking the parts lock for each part). With 2000 parts and 50 patch parts it took about 80 ms of the planning of a point query. The performance test `skip_index_planning_with_patch_parts` refreshes the cached statistics every second, so that they are up to date after the fill. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`IMutationsSnapshot::getAllUpdatedColumns` collected only the columns of `UPDATE` commands, so the planner collected the columns changed by alter mutations (`MODIFY COLUMN`) for each part by itself. Now the snapshot collects the columns of all commands applied on the fly with the same rules as `AlterConversions`. The method is renamed to `getColumnsChangedOnFly`, so that other implementations fail to compile instead of silently missing alter mutations. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [c988f9e] Summary: ❌
AI ReviewSummaryThis PR removes the Findings
Tests
Final Verdict
|
…_patches Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: No query shows a performance change that can be traced to this PR. The only flagged row is clickbench Q31 at -12.1% (297 ms to 261 ms), and it was correctly marked no_change: 261 ms is within master's recent range of 241-357 ms, and the baseline for Q30/Q31 had to be re-fit because master itself shifted on 2026-10-09. The PR changes text-index direct reads, how columns changed by mutations and patches are collected, and skip-index filtering for parts already dropped by the primary key. ClickBench's hits table has no skip indexes and no pending patches, so none of that code runs there, and the small CPU drop is not enough to credit the PR. The planning speedup this PR targets should show up in the new skip_index_planning_with_patch_parts performance test, which neither of these benchmarks covers. clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
3740ea9
Resolve conflicts of the cherry-pick of #124931 to 26.7: - 26.7 has no `has_patched_parts` gate (#118496 is not backported), so only the per-part loop over `getAlterConversionsForPart` in `collectTextIndexReadInfos` is replaced by `getColumnsUpdatedOnFly`. - `MergeTreeReadTaskInfo` has no `data_part_info` on 26.7, so `getIndexReadTaskForReadStep` takes the part and its `AlterConversions` separately. - `getMaskingPolicyCommands` is placed before the 26.7 version of `getPatchPartMetadata`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Cherry pick #124931 to 26.7: Fix slow planning of queries with skip indexes on tables with pending patch parts
…xes on tables with pending patch parts
Backport #124931 to 26.9: Fix slow planning of queries with skip indexes on tables with pending patch parts
Backport #124931 to 26.8: Fix slow planning of queries with skip indexes on tables with pending patch parts
Backport #124931 to 26.7: Fix slow planning of queries with skip indexes on tables with pending patch parts
… skip indexes on tables with pending patch parts

Related: #99543
Related: #118496
Related: #123334
Related: #124085
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed slow planning of queries with skip indexes on tables with many parts and pending patch parts of lightweight updates.
Workflow [PR]
Sync PR [sync-upstream/pr/124931]
Version info
26.10.1.2081-master(included in26.10and later)26.9.16.10,26.8.24.9,26.7.27.4