Skip to content

Apply skip indexes at analysis time on tables with max_partitions_to_read - #126792

Merged
nickitat merged 5 commits into
masterfrom
qcc-pruning
Oct 21, 2026
Merged

nickitat merged 5 commits into
masterfrom
qcc-pruning

Conversation

@nickitat

@nickitat nickitat commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix TOO_MANY_PARTITIONS for queries on tables with max_partitions_to_read whose filter rules out partitions only through a skip index: with use_skip_indexes_on_data_read enabled and a cold query condition cache, parts that the skip index would drop were counted against the limit. Skip indexes are now applied during index analysis when max_partitions_to_read is set.


max_partitions_to_read is checked in ReadFromMergeTree::initializePipeline, before the read. With use_skip_indexes_on_data_read = 1 (the default), index analysis leaves skip indexes to the read, so parts that a skip index would drop still count against the limit. A query that relies on a skip index to stay under the limit therefore fails with TOO_MANY_PARTITIONS on a cold query condition cache, even without parallel replicas.

The failure was hidden for users with parallel replicas and parallel_replicas_min_number_of_rows_per_replica > 0: the planner's row estimate runs first, applies skip indexes during its own analysis and fills the query condition cache, so the executed read then drops those parts from the cache. Automatic parallel replicas analyze the executed read before that estimate, or skip the estimate for plan shapes without a probe plan, which exposed it.

supportsSkipIndexesOnDataRead already turns read-time skip indexes off for max_rows_to_read with read_overflow_mode = 'throw', a limit that is also checked before the read. max_partitions_to_read (query setting if changed, otherwise the table setting, as in checkLimits) is now treated the same way. The cost is that tables with a partition limit no longer get read-time skip indexes.


Workflow [PR]
Sync PR [sync-upstream/pr/126792]

Version info

  • Merged into: 26.11.1.438-master (included in 26.11 and later)
  • Backported to: 26.10.2.68

`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]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8095104]

Summary: ✅


AI Review

Summary

PR #126792 applies skip indexes during analysis when max_partitions_to_read is effective, so partitions excluded by those indexes do not cause TOO_MANY_PARTITIONS. Followers delegate the partition check only when the initiator runs a local plan. At commit 80951047e12f0b03f5d451bd1bdaf40d76332d40, all three previous findings are addressed and no new actionable findings remain. The added stateless regression passed in CI's Fast test.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 19, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Oct 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 80951047e with master 88a5db8e7 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 9e11e12d8; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

124 translation units recompiled, 1526 s compile time in total, 124 of them have a recent master baseline.

Job report

…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]>
nickitat and others added 2 commits October 20, 2026 09:23
# 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]>
@nickitat
nickitat added this pull request to stack #126950 October 20, 2026 12:58
@nickitat
nickitat marked this pull request as ready for review October 20, 2026 13:11
@nickitat
nickitat requested a review from devcrafter October 20, 2026 15:03
@devcrafter devcrafter self-assigned this Oct 20, 2026
@nickitat
nickitat added this pull request to the merge queue Oct 21, 2026
Merged via the queue into master with commit e635548 Oct 21, 2026
179 checks passed
@nickitat
nickitat deleted the qcc-pruning branch October 21, 2026 17:03
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 21, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 21, 2026
nickitat added a commit that referenced this pull request Oct 21, 2026
Cherry pick #126792 to 26.10: Apply skip indexes at analysis time on tables with `max_partitions_to_read`
robot-clickhouse added a commit that referenced this pull request Oct 21, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants