Skip to content

Backport #116446 to 26.6: Do not use the distributed-plan Shuffle aggregation when bucket order is promised - #120640

Merged
clickhouse-gh[bot] merged 2 commits into
26.6from
backport/26.6/116446
Sep 17, 2026
Merged

clickhouse-gh[bot] merged 2 commits into
26.6from
backport/26.6/116446

Conversation

@robot-ch-test-poll2

@robot-ch-test-poll2 robot-ch-test-poll2 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #116446
Cherry-pick pull-request #120637

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.6.9.15

@robot-ch-test-poll2 robot-ch-test-poll2 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default labels Sep 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [00cc675]

Summary: ✅

@groeneai

Copy link
Copy Markdown
Collaborator

The only red here is my own new test, and it cannot pass on 26.6 or 26.7.

Its first row asserts that the plan text contains memory-efficient:

SELECT count() > 0 FROM (EXPLAIN PLAN actions = 1, distributed = 1 <query>)
    WHERE explain ILIKE '%memory-efficient%';

Mode: memory-efficient is printed by MergingAggregatedStep::describeActions only since 9fcc79675d4d (2026-08-07). 26.8 contains that commit, 26.6 and 26.7 were cut before it, so the row is 0 on both. Not randomization: the runner re-ran it 15/15 and 19/19 failing, and the reference diff is that single line, 1 to 0, with the 7 600056 result rows and every other row matching.

Minimal adaptation for 26.6 and 26.7: drop that row plus the final count() = 0 ... ILIKE '%memory-efficient%' row, which is vacuous on a branch that never prints the marker, and their two reference lines. The guard's own coverage survives untouched: at f0e146ea the rows asserting by hash( is absent with the bucket-order promise on, and present with it off, all passed.

@PedroTadim, do you want me to open that against backport/26.6/116446 and backport/26.7/116446, or would you rather pin it yourself? #120639 (26.8) is unaffected.

`Mode: memory-efficient` is printed by `MergingAggregatedStep::describeActions` only from 26.8 on, so
the arming row and the closing boundary row that match `%memory-efficient%` read 0 on this branch and
cannot be satisfied there. Both are dropped along with their two reference lines. The guard's own
coverage is untouched: the rows asserting that `by hash(` is absent under the bucket-order promise and
present without it all pass here.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh
clickhouse-gh Bot merged commit 1eb407c into 26.6 Sep 17, 2026
40 of 41 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.6/116446 branch September 17, 2026 23:31
pull Bot pushed a commit to SINHASantos/ClickHouse that referenced this pull request Sep 19, 2026
…order_promise

Requested in review on the merged PR ClickHouse#116446:
ClickHouse#116446 (comment)

The test asserted its plan claims with 12 rows of the form
`SELECT count() ... FROM (EXPLAIN ...) WHERE explain ILIKE '%...%'`. Each row
projects the plan onto one bit and discards it before the comparison, so a red
row prints `1 -> 0` and nothing about the plan, and reading the failure means
rebuilding and re-running the explain by hand. The same test is red on the 26.6
backport ClickHouse#120640 right now, with exactly that output.

Those 12 rows use only 7 distinct explain queries, differing solely in their
`SETTINGS` clause, so they collapse onto 7 pinned plans, each behind a
`SELECT '-- label';` marker line so the reference stays navigable. Every `SET`
pin and every behavioural row is unchanged: the three `FORMAT Null` rows that
must not hit the duplicate-bucket rejection, and the two `HAVING k = 7`
result-equality rows.

Each block keeps the smallest flag set its claims need. Five are a plain
`EXPLAIN`, since the step descriptions they read (`by hash(...)`, `partial`,
`merge`) are printed without `actions = 1`. The two asserting the merge mode do
need it, because `Mode: memory-efficient` is printed only by
`MergingAggregatedStep::describeActions`; those two add `compact = 1`, which
makes `skip_expressions` walk past every `Expression` step in the initiator plan
and, through `ExplainPlanOptions::toSettingsChanges`, in both shard plans, so
their `Actions:`/`Positions:` dumps stay out of the reference. `pretty = 1` is
not usable here, as it cannot represent per-shard plans.

`index_granularity_bytes = 0` and `min_bytes_for_wide_part = 0` are new in the
DDL. The two `actions = 1` plans print `ReadFromMergeTree`'s granule count, and
the runner randomizes both of that number's inputs.
`index_granularity_bytes` is drawn from `[1024, 30 MiB]`
(`tests/clickhouse-test:2006`), and once it falls below `index_granularity`
times the row size the adaptive byte quotient replaces the fixed 256 rows per
granule: measured on this 16-byte fixture, 2048 prints `Granules: 1563` and 1024
prints 3125, against 782 at 4096 and above. The 100 KiB floor that hides the
window applies only to sanitizer, debug and coverage builds (`:2096-2103`), so a
release-flavour run is the exposed one. `min_bytes_for_wide_part` moves the same
number by one between the two part formats. With adaptive sizing off the count is
`ceil(rows / index_granularity)` for any block width and either format, which
also closes the row-width exposure through the randomized
`enable_block_number_column` and `enable_block_offset_column`. A table setting in
the DDL holds against the runner's injection, which skips settings the query
already sets, and against the server default alike, which is why the
`index_granularity = 256` this reference also depends on already survives there.

Validation: removing the guard hunk ClickHouse#116446 added at
`makeDistributed.cpp:715-721` makes 4 of the 7 blocks red, with
`ShuffleExchange (by hash([__table1.k]))` reappearing once per shard plan, while
the 3 blocks asserting that the shuffle stays when nothing promises bucket order
are byte-identical; the reference reds on that regression and only there. The
granule pins are proven through the runner's own merge-tree injection seam:
`--merge-tree-settings "--index_granularity_bytes 2048"` passes with them and
reds `Granules: 782 -> 1563` on all four lines without them. 50 of 50 runs green
with settings randomization on (161-196 settings drawn per query, 50 distinct
randomized merge-tree tails, part format Wide in all 50). The reference is
generated from the runner's own stdout, not pasted by hand.

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

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants