Skip to content

Cherry pick #124931 to 26.7: Fix slow planning of queries with skip indexes on tables with pending patch parts - #125112

Merged
robot-ch-test-poll merged 8 commits into
backport/26.7/124931from
cherrypick/26.7/124931
Oct 11, 2026
Merged

robot-ch-test-poll merged 8 commits into
backport/26.7/124931from
cherrypick/26.7/124931

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

CurtizJ and others added 7 commits October 9, 2026 13:17
… 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
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Oct 10, 2026
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]>
@robot-ch-test-poll
robot-ch-test-poll merged commit df8174e into backport/26.7/124931 Oct 11, 2026
1 check passed
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.7/124931 branch October 11, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants