Skip to content

Evaluate followers' read-time skip indexes over the ranges analyzed on the initiator - #126954

Merged
nickitat merged 15 commits into
masterfrom
pr-skip-index-coordinator-ranges
Oct 22, 2026
Merged

nickitat merged 15 commits into
masterfrom
pr-skip-index-coordinator-ranges

Conversation

@nickitat

@nickitat nickitat commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

With parallel replicas and use_skip_indexes_on_data_read, follower replicas now evaluate skip indexes over the mark ranges analyzed on the initiator, received from the coordinator, instead of repeating the primary key analysis.


Related: #124628
Related: #126145
Related: #126955

Stacked on #126955, which reverts #126145; this PR does not contain the revert, so it can be backported to 26.10, which never had #126145.

With parallel_replicas_index_analysis_only_on_coordinator (the default), a parallel replicas follower skips its own index analysis and keeps every mark of every part. With use_skip_indexes_on_data_read (also the default), that whole-part input made MergeTreeSkipIndexReader::read evaluate the skip indexes over whole parts. #126145 fixed it by running the primary key analysis again on each follower, lazily, per part.

The coordinator already holds the ranges the initiator analyzed: the initiator's announcement registers them, and InitialAllRangesAnnouncementResponse carries them back to in-order followers. In Default mode that response was neither sent nor awaited. This change lets a follower ask for it, and evaluates the skip indexes over those ranges instead of repeating the analysis:

  • InitialAllRangesAnnouncement gets a trailing wants_analyzed_ranges field (parallel replicas protocol 8 -> 9). A follower sets it only when it skipped its own analysis and has a read-time skip-index reader. The initiator replies in Default mode only when the field is set, and the follower waits only when it set it and the initiator speaks version 9. Every other Default mode read keeps today's behaviour: no response, no round trip. The coordinator also stops copying the registered parts into a response that is not sent.
  • MergeTreeIndexBuildContext::addAnalyzedReadRanges replaces a part's skip-index input with the analyzed ranges before the first task. In-order followers do the same with the response they already receive. The initiator can split one part between in-order streams, and each stream's response carries only its own ranges, so the input of a part is the union over all of a follower's streams.
  • With the primary key step of Apply primary key pruning before read-time skip indexes on parallel replicas followers #126145 reverted in Revert "Apply primary key pruning before read-time skip indexes on parallel replicas followers" #126955, followers do not repeat the analysis, and a follower's input matches the initiator's exactly, partition minmax pruning included.

The protocol spec in docs/resources/develop-contribute/native-protocol/protocol.mdx is updated.

Results

Issue #124628 reproduction (200 parts, bloom filter on mapValues, 3 local replicas, caches dropped before each query, 3 runs), ReadCompressedBytes per follower:


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

Version info

  • Merged into: 26.11.1.546-master (included in 26.11 and later)
  • Backported to: 26.10.2.80

nickitat and others added 2 commits October 20, 2026 12:59
… on the initiator

With `parallel_replicas_index_analysis_only_on_coordinator`, a parallel replicas follower skips its own
index analysis and keeps every mark of every part. With `use_skip_indexes_on_data_read`, that whole-part
input made `MergeTreeSkipIndexReader::read` evaluate the skip indexes over whole parts. #126145 narrowed
the input by running the primary key analysis again on each follower.

The coordinator already holds the analyzed ranges: the snapshot announcement of the initiator registers
them, and `InitialAllRangesAnnouncementResponse` carries them back for in-order reads. A `Default` mode
follower that skipped analysis and has a read-time skip-index reader now asks for that response with a
new `wants_analyzed_ranges` field of `InitialAllRangesAnnouncement` (parallel replicas protocol 9), and
evaluates the skip indexes over those ranges. In-order followers use the response they already receive.
This replaces the primary key step of #126145, so followers do not repeat the analysis, and their input
matches the initiator's exactly, partition minmax pruning included.

Other `Default` mode reads still neither send nor wait for the response, and the coordinator no longer
copies the registered parts into a response that is not sent. With an initiator older than protocol 9
the follower does not ask and evaluates whole parts, as before #126145.

The test now runs with the initiator's local replica, the default: without a local plan no replica
analyzes, so the coordinator has no analyzed ranges to hand out.

Issue reproduction (200 parts, bloom filter, 3 local replicas, caches dropped before each query),
`ReadCompressedBytes` per follower: no fix 16-105 MiB (1073 selected marks), #126145 0.25-3.3 MiB,
this change 0.17-1.9 MiB (20 selected marks in both).

Related: #124628
Related: #126145

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test passed vacuously when the initiator's local replica took all the work before the followers
announced. `slowdown_parallel_replicas_local_plan_read` delays every request of the local replica, so the
followers get their segments, and the check again requires a finished follower in each mode. The failpoint
is server-wide, hence `no-parallel`.

Local runs: 30/30 with randomized settings, 30/30 with the server under CPU load (load average 40),
and 10/10 failures with the analyzed ranges not applied on followers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 20, 2026, 1:50 PM

@clickhouse-gh

clickhouse-gh Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0aedd94]

Summary: ✅

The revert of #126145 is now a separate PR, #126955, which this
one is stacked on. This branch already removed the same code, so its tree is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nickitat
nickitat changed the base branch from master to revert-126145 October 20, 2026 13:29
@nickitat
nickitat added this pull request to stack #126957 October 20, 2026 13:30
nickitat and others added 2 commits October 20, 2026 13:35
Away from `pk_condition_useful`, which 26.10 does not have, so the change cherry-picks onto 26.10
without conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `failpoint_tests_are_isolated` style check requires it: a fail point is server-global, so such a test
runs alone, and tests that run alone are kept out of the fast test.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126954&sha=1737e4d26b4cf146e94dda769b195361b1f8cde3&name_0=PR&name_1=Style%20check
#126954

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). label Oct 20, 2026
An in-order read on the initiator can split one part between streams, and a
local-plan follower creates one pool per stream over a shared
`MergeTreeIndexBuildContext`. Each stream's announcement response carries only
that stream's ranges, so replacing the part's read-time skip-index input per
response left it with the last stream's ranges, and the rows of the other
streams were dropped (25 of 100 rows in the new test, ascending and descending).
`addAnalyzedReadRanges` now replaces the whole-part ranges once and extends
them with every later response.

05401 no longer requires a finished follower in each mode: a follower that got
no work before the local replica finished is cancelled, which made the flaky
check fail.

Flaky check: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126954&sha=15bbab5edc47d278e052f064e224b14512a20601&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29
Review: #126954 (comment)
PR: #126954

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0aedd94c5 with master c9141f345 (stripped binary size, per-symbol sizes and ThinLTO time; 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.

Object file sizes

38 object files changed (+32.96 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/MergeTree/MergeTreeSelectProcessor.cpp.o 325.62 KiB 356.47 KiB +30.85 KiB (+9.47%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

The flag is set on a follower that skipped its own index analysis and has a
read-time skip-index reader (`use_skip_indexes_on_data_read`, the join runtime
filter or the top-K primary key pruning); the comments now say so. In-order
announcements carry its real value instead of `false`: ordered modes always get
the response, so nothing changes on the wire. `addAnalyzedReadRanges` appends
with a range `insert`.

PR: #126954

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nickitat
nickitat marked this pull request as ready for review October 20, 2026 19:49
@devcrafter devcrafter self-assigned this Oct 21, 2026
Plan-based parallel replicas follow the top-level query's settings, so with the
`SETTINGS` on the subquery the plan-based query was a plain local read. With them
on the outer query, `query_plan_remove_redundant_sorting` drops the inner
`ORDER BY` in the plan-based case, so it is disabled there to keep the read in order.
Now all three queries run with two followers and fail without the stream union.

#126954 (comment)

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

@devcrafter devcrafter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also check behavior with disabled use_skip_indexes_on_data_read in the tests

nickitat and others added 4 commits October 21, 2026 22:37
…d` disabled

Without the read-time skip-index evaluation a follower requests no analyzed ranges
and reads only the marks the coordinator assigns. It still accounts the whole parts
it planned as `SelectedMarks`, so 05401 compares the rows read for these queries.

#126954 (review)

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

# Conflicts:
#	src/Processors/QueryPlan/ReadFromMergeTree.cpp
…analysis_skipped`

Master added the same flag, set at the same place, with the merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit staged the stale submodule checkouts with `git commit -a`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Base automatically changed from revert-126145 to master October 22, 2026 10:11
Algunenano pushed a commit to Algunenano/ClickHouse that referenced this pull request Oct 22, 2026
…rallel replicas followers"

This reverts ClickHouse#126145 (merge commit 1daec15): source
changes and the test `05401_parallel_replicas_follower_skip_index_primary_key`. The declaration of
`key_condition_not_applied` in `ReadFromMergeTree.h` was removed by hand, because `pk_condition_useful`
was added next to it afterwards.

A follower will take the ranges analyzed on the initiator from the coordinator instead of repeating
the primary key analysis: ClickHouse#126954

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nickitat
nickitat added this pull request to the merge queue Oct 22, 2026
Merged via the queue into master with commit c22c845 Oct 22, 2026
353 of 354 checks passed
@nickitat
nickitat deleted the pr-skip-index-coordinator-ranges branch October 22, 2026 14:27
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 22, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 22, 2026
@nickitat nickitat removed pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Oct 22, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 22, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 22, 2026
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Nov 4, 2026
…l plan

With `parallel_replicas_index_analysis_only_on_coordinator`, a follower skipped
its own index analysis whenever `parallel_replicas_local_plan` was set, relying
on the analysis of the initiator's local plan. Inside a `Distributed` subquery
and with `parallel_replicas_prefer_local_replica = 0` there is no local plan,
so nobody analyzed and every replica read whole parts: 1280000 rows instead of
384 for a primary key range of 3 granules through `Distributed`. The check now
uses `ClusterProxy::canUseLocalPlanForParallelReplicas`, which covers both.

Review: ClickHouse#126954 (comment)
Related: ClickHouse#126954

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-performance Pull request with some performance improvements 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.

Parallel replicas followers evaluate read-time skip indexes over whole parts (use_skip_indexes_on_data_read)

6 participants