Skip to content

Cherry pick #126792 to 26.10: Apply skip indexes at analysis time on tables with max_partitions_to_read - #127243

Merged
nickitat merged 7 commits into
backport/26.10/126792from
cherrypick/26.10/126792
Oct 21, 2026
Merged

nickitat merged 7 commits into
backport/26.10/126792from
cherrypick/26.10/126792

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #126792

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

nickitat and others added 6 commits October 19, 2026 19:12
`max_partitions_to_read` is checked in `ReadFromMergeTree::initializePipeline`, before the read. With
`use_skip_indexes_on_data_read = 1` the index analysis leaves skip indexes to the read, so parts a skip
index would drop still count against the limit, and a query that relies on a skip index to stay under
it fails with `TOO_MANY_PARTITIONS` on a cold query condition cache.

This was hidden when parallel replicas were enabled with
`parallel_replicas_min_number_of_rows_per_replica > 0`: the planner's row estimate ran a full analysis
with skip indexes first and filled the query condition cache. Automatic parallel replicas analyze the
executed read before that estimate (or skip it), which exposed the failure.

Treat `max_partitions_to_read` like `max_rows_to_read` with `read_overflow_mode = 'throw'` in
`supportsSkipIndexesOnDataRead`: skip indexes are applied during index analysis when the limit is set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nalysis

With `parallel_replicas_local_plan = 1` and `parallel_replicas_index_analysis_only_on_coordinator = 1`
a follower skips index analysis and keeps every part, leaving range assignment to the coordinator.
`checkLimits` then counted those parts against `max_partitions_to_read`, so the follower failed with
`TOO_MANY_PARTITIONS` even though the coordinator pruned the read to fewer partitions. The initiator
tolerated the failed replica, which silently lost its share of the work. The initiator still checks
the limit on the coordinator's analysis.

The test now disables the row limits of the test profile, which already turned read-time skip indexes
off and made it pass without the fix, and the query condition cache, so earlier queries cannot prune
the parts for later ones. It also covers the follower case.

Addresses the AI review: #126792 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	src/Processors/QueryPlan/ReadFromMergeTree.cpp
#	src/Processors/QueryPlan/ReadFromMergeTree.h
…_done_on_initiator`

The old name read like a mirror of `parallel_replicas_index_analysis_only_on_coordinator`, while the
field is set only on a follower that skipped its own analysis.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… plan

A follower skipped its own index analysis whenever `parallel_replicas_local_plan` was set, but the
initiator builds no local plan with `parallel_replicas_prefer_local_replica = 0`, inside a `Distributed`
sub-query, or when the leaf timeout disables it. Then nobody analyzed the indexes, and since the
previous commit nobody checked `max_partitions_to_read` either: a remote-only parallel read went past
the limit. Use `ClusterProxy::canUseLocalPlanForParallelReplicas`, which decides whether the
initiator runs a local plan, so in the other cases the followers analyze and check the limit
themselves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Apply skip indexes at analysis time on tables with `max_partitions_to_read`
@robot-ch-test-poll3 robot-ch-test-poll3 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 21, 2026
@nickitat

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ nickitat
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@nickitat
nickitat merged commit b3c176f into backport/26.10/126792 Oct 21, 2026
1 check passed
@nickitat
nickitat deleted the cherrypick/26.10/126792 branch October 21, 2026 17:55
Copilot AI restored the cherrypick/26.10/126792 branch October 21, 2026 17:55

Copilot AI commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

🕵 Resolved and pushed in 49259ccaa.

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.

5 participants