Skip to content

Keep 03008_optimize_equal_ranges off parallel replicas - #123695

Merged
nickitat merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-03008-optimize-equal-ranges-parallel-replicas
Oct 8, 2026
Merged

nickitat merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-03008-optimize-equal-ranges-parallel-replicas

Conversation

@groeneai

@groeneai groeneai commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #122853

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

03008_optimize_equal_ranges fails in the new Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) job from #122853 on unrelated PRs: one row of the final system.query_log check prints 0 instead of 1 (report). The GROUP BY results are always correct.

The test reads ProfileEvents['AggregationOptimizedEqualRangesOfKeys'] from the initiator's query_log row. With parallel replicas that row counts only what the initiator's local replica aggregated: remote replicas' ProfileEvents go to the client, not into that row, and the coordinator decides at runtime which replica reads the marks. In the failing job's own query_log, the initiator read 0 marks for the flipped query while a remote replica read all 90000 rows with the counter at 3. So the optimization works; only the assertion depends on where the aggregation runs.

The test now sets enable_parallel_replicas = 0 next to its other pins.

Validation: on a local three-replica cluster with the slowdown_parallel_replicas_local_plan_read failpoint, the unfixed test fails 50/50 runner runs in the ParallelReplicas configuration. With the change it passes 50/50 there (at both parallel_replicas_local_plan values) and 50/50 with randomized settings in the regular configuration.

If you prefer to keep the whole test out of this job, I can use the no-parallel-replicas tag instead.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.1849-master (included in 26.10 and later)

The test checks ProfileEvents['AggregationOptimizedEqualRangesOfKeys'] on the
initiator's query_log row. Under parallel replicas the ProfileEvents of remote
replicas are forwarded to the client only and are not merged into that row, so
it counts just what the initiator's local replica aggregated. When the
coordinator hands all marks to remote replicas, the row shows 0 although the
remote replica applied the optimization (in the failing ParallelReplicas job's
query_log: initiator 0 marks, remote replica 90000 rows, counter 3).

Pin enable_parallel_replicas = 0 for the session, next to the other pins. It is
a profile setting in the ParallelReplicas job, so a "Random settings limits"
clamp cannot reach it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 3, 2026
@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings), plus my own review (1 nit).

# Sev Finding Verdict Evidence / action
1 💡 The test comment should name the initiator's query_log row (remote replicas write their own rows) and put names in inline code AGREE nit, left as is: comment wording only, no behavior change

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-8:20261003-134300

@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? On a local three-replica cluster: with parallel_replicas_local_plan = 0 the unfixed test fails 5/5; with the default local plan and the slowdown_parallel_replicas_local_plan_read failpoint it fails 300/300 loop iterations and 50/50 runner runs (sum 16 prints 0). The natural trigger is replica announcement timing, which no setting forces.
b Root cause explained? The test reads AggregationOptimizedEqualRangesOfKeys from the initiator's query_log row, which does not include remote replicas' ProfileEvents. When remote replicas read all marks, the initiator aggregated nothing and the row shows 0, while the remote replica applied the optimization (counter 3 in the CI query_log).
c Fix matches root cause? Yes: the test pins enable_parallel_replicas = 0, so the server whose query_log row is checked is the one that aggregates. No widened bound, no blanket tag.
d Test intent preserved / new tests added? Yes: the test still asserts the optimization fires (max_threads = 1, and sum at 16 threads) and does not fire for uniqExact at 16 threads. Test-only change, .reference unchanged.
e Both directions demonstrated? Same server state: fixed 100/100 byte-identical to .reference while unfixed loops flipped 570/570. Runner, ParallelReplicas profile: unfixed 50/50 FAIL, fixed 50/50 OK at both parallel_replicas_local_plan values. Regular configuration, randomized: fixed 50/50 OK.
f Fix is general across code paths? The session SET covers all four measured queries. Other tests reading this counter use a Memory table or part_log and are not affected by parallel replicas.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only change).
h Backward compatible? (maintainer-approved exception only) N/A (no setting, format or engine change).
i Invariants and contracts preserved? N/A for engine code; the oracle's invariant (every measured query runs on the server that writes the checked row) now holds in every CI configuration.

Session id: cron:clickhouse-impl-slot-40:20261003-132100

@clickhouse-gh

clickhouse-gh Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [37db061]

Summary: ✅


AI Review

Summary

This PR makes 03008_optimize_equal_ranges deterministic in the ParallelReplicas CI profile by pinning enable_parallel_replicas = 0 before the test reads AggregationOptimizedEqualRangesOfKeys from the initiator's query_log row. I do not see a correctness gap in that approach: it matches the stated root cause, preserves the existing oracle, and follows the same pattern as other stateless tests that disable parallel replicas when they rely on initiator-local ProfileEvents.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 3, 2026
@groeneai
groeneai requested a review from nickitat October 3, 2026 14:11
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 3, 2026
@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 8a08e90

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build (amd_fuzzers) / Build ClickHouse not from this PR (it changes one test file): linking clickhouse_fuzzer overflows the 2 GiB R_X86_64_PC32 reach (.text to .bss, 2148738730); master itself is red on this job since 12:48Z today with the same overshoot #122521 (mine, open)
Mergeable Check, PR rollups, red only because of the row above #122521 (mine, open)

All 160 checks completed and Finish Workflow is done; CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261003-170255

@nickitat nickitat self-assigned this Oct 8, 2026
@nickitat
nickitat added this pull request to the merge queue Oct 8, 2026
Merged via the queue into ClickHouse:master with commit 1662f87 Oct 8, 2026
152 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 8, 2026
@clickhouse-gh clickhouse-gh Bot added comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants