Repository navigation
Use projections with parallel replicas when optimize_aggregation_in_order is enabled - #123098
Conversation
…rder is enabled `canUseProjectionForReadingStep` rejected every projection of a parallel replicas read when `optimize_aggregation_in_order` or `force_aggregation_in_order` was set (added by ClickHouse#82807). It keyed on the setting, so aggregate and normal projections, `_minmax_count_projection` and the exact count were lost for every parallel replicas query of a user who keeps the setting on, and the whole table was read. The check stood in for one asymmetry. With a full aggregate projection the aggregation becomes `only_merge`, and `optimizeAggregationInOrder` may then aggregate in order over the projection read, which is sorted by the projection's keys. The local plan's root aggregation then uses memory-bound merging, so `enableMemoryBoundMerging` enforces aggregation in order on the followers. With `force_aggregation_in_order` the followers' aggregation has a sort description, `AggregatingStep::canUseProjection()` is false there, and they read the base table on the same coordinator stream as the initiator's projection read: a different coordination mode, or parts the initiator never announced. Without the setting check and without the skip below, a `GROUP BY k` over a 1M-group projection of a table `ORDER BY v` fails with `LOGICAL_ERROR` "Got read request from replica N for unknown stream" every time. So instead of rejecting projections, do not aggregate in order over an aggregate projection read when reading with parallel replicas, like the other parallel replicas skips in `optimizeReadInOrder.cpp` (JOIN, LIMIT BY, UNION). The initiator and the followers then build the plan they build with `optimize_aggregation_in_order = 0`; `EXPLAIN PLAN` and `EXPLAIN PIPELINE` are identical. The `!support_projection` half of the check is unchanged. Closes ClickHouse#123061. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the only_merge read-in-order skip comment to one line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding), plus my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260930-145600 |
|
Workflow [PR], commit [9b5bad2] Summary: ✅
AI ReviewSummaryThis PR removes the blanket Final Verdict
LLVM Coverage ReportMeasured on commit 9b5bad2.
Changed lines: Changed C/C++ lines covered: 18/18 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 42 s compile time in total, 9 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…jobs The pin worked around #123061: with parallel replicas, `optimize_aggregation_in_order` rejected every projection, including `_minmax_count_projection`. It was added on 2026-09-30, one day before the fix #123098 was merged, and is obsolete now, so the setting is randomized again in both halves of the jobs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #123061
Related: #82807
Related: #122853
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
With parallel replicas,
optimize_aggregation_in_orderno longer disables projections: aggregate and normal projections, and_minmax_count_projectionforcount()with a partition predicate, are used as withoptimize_aggregation_in_order = 0. Closes #123061.Description
With parallel replicas,
canUseProjectionForReadingSteprejected every projection whenoptimize_aggregation_in_orderorforce_aggregation_in_orderwas set (#82807), even when nothing is aggregated in order. In the issue's repro the aggregation reads 1,000,000 rows instead of 10 and the partitioncount()33,334 instead of 1; withforce_optimize_projection/max_rows_to_readthey fail withPROJECTION_NOT_USED/TOO_MANY_ROWS, as 22 tests did in theParallelReplicasjob of #122853 (report).The check covered one case: with a full aggregate projection the initiator's local plan can aggregate in order over the projection read; memory-bound merging then sends
force_aggregation_in_orderto the followers, which cannot use the projection in that mode and read the base table on the same coordinator stream (@ nickitat on #82807: either the projection or memory-bound merging).This PR removes the setting check and, for parallel replicas, skips aggregation in order over an aggregate projection read (
only_merge), like the other parallel-replicas skips inoptimizeReadInOrder.cpp. Initiator and followers then build theiroptimize_aggregation_in_order = 0plan (identicalEXPLAIN). Without the skip, a 1M-group projection query hitsLOGICAL_ERROR(... for unknown stream) 10 of 10 times.The new test fails on master, and its
EXPLAINline fails without the skip; 50/50 randomized runs, also in theParallelReplicasconfiguration. Withoptimize_aggregation_in_order = 1forced there, the 23 tests from the issue and #122853 fail on master and pass here, and none of 465 projection, aggregation-in-order and parallel-replicas tests goes from OK to FAIL, so these tests do not need the #122853 pin.If you prefer to keep aggregation in order over the projection, the alternative is to skip memory-bound merging there instead; I did not, as that plan shape does not exist today.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123098]
Version info
26.10.1.1139-master(included in26.10and later)