Repository navigation
Cherry pick #124931 to 26.7: Fix slow planning of queries with skip indexes on tables with pending patch parts - #125112
Merged
Conversation
… skip index `collectTextIndexReadInfos` called `getAlterConversionsForPart` for every part of the table to collect the columns updated on the fly (#99543) and to find whether any part has a pending patch (#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: #123334 Related: #124085 Related: #118496 Related: #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]>
…_patches Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…rt-patches Fix slow planning of queries with skip indexes on tables with pending patch parts
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]>
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.
Original pull-request #124931
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job