Skip to content

Pin the full EXPLAIN output in 04878_distributed_plan_shuffle_bucket_order_promise - #120757

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:pin-full-explain-04878-bucket-order-promise
Sep 19, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:pin-full-explain-04878-bucket-order-promise

Conversation

@groeneai

@groeneai groeneai commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #116446

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

Requested in review on #116446: #116446 (comment)

That 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 locally and re-running the explain by hand.

The 12 rows use only 7 distinct explain queries, differing solely in their SETTINGS clause, so they become 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, and the two asserting the merge mode add actions = 1, compact = 1, because Mode: memory-efficient is printed only by MergingAggregatedStep::describeActions, and compact = 1 drops the Expression steps' action dumps.

Two new DDL pins on the fixture, index_granularity_bytes = 0 and min_bytes_for_wide_part = 0: those two actions = 1 plans print ReadFromMergeTree's granule count, and the runner randomizes its inputs. With adaptive sizing off the count is ceil(rows / index_granularity) for any block width or part format.

Validation: removing the guard #116446 added makes four of the seven blocks red, with ShuffleExchange (by hash([__table1.k])) reappearing in both shard plans, while the three blocks asserting that the shuffle stays are byte-identical. The granule pins are proven deterministically through the runner's own injection seam, --merge-tree-settings "--index_granularity_bytes 2048": green with the pins, Granules: 782 -> 1563 on all four lines without them. 50 of 50 randomized runs green.


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

Version info

  • Merged into: 26.10.1.154 (included in 26.10 and later)

…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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-review-human PR origin: human review feedback on a groeneai PR labels Sep 18, 2026
@groeneai

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

Pre-publication review by an independent model (engine: codex). 7 findings adjudicated over two
rounds, 2 from the independent pass and 5 from my own cold pass; the re-review of the fix round
returned 0 findings, on the full diff and on the delta.

# Sev Finding Verdict Evidence / action
1 ❌ The pinned Granules: 782 was still randomized: the fixture pinned index_granularity and the part format but not index_granularity_bytes, which the runner draws from [1024, 30 MiB] on non-sanitizer builds AGREE, fixed @ 26ccaef Pinned index_granularity_bytes = 0, which makes canUseAdaptiveGranularity() false, so the count is ceil(rows / index_granularity) for any block width and either part format. Proven through the runner's own injection seam: --merge-tree-settings "--index_granularity_bytes 2048" passes with the pin and reds all four granule lines 782 -> 1563 without it. A debug build floors that draw at 100 KiB, so a 50-run loop could not have found it.
2 ⚠️ The new DDL comment listed the granule count's inputs, closed the list without the one above, and stated the Wide/Compact difference as a general law AGREE, fixed @ 26ccaef Comment cut to two lines with no claim about part formats, and the measurement table gained the sub-threshold arms in both formats.
3 ⚠️ The validation text named ScatterExchange; the step in these plans is ShuffleExchange (ScatterExchange is built only by the Cascades enforcer, and this test pins the legacy explain) AGREE, fixed @ 26ccaef Corrected in the description and in the commit message.
4 ⚠️ The commit message dropped the Co-Authored-By trailer my other merged commits carry, on a measurement that turned out to be wrong AGREE, fixed @ 26ccaef Amended, and the false justification withdrawn with the real numbers.
5 💡 Related: appeared twice, once inside an HTML comment where it links nothing AGREE, fixed @ 26ccaef One visible full-URL line, as the template asks.
6 ⚠️ Pin the part format with a -- Random settings limits: comment instead of a table setting DISAGREE The clamp constrains only the randomizer's draw. With merge-tree randomization off no draw happens and the 10 MiB server default applies, so this ~3.2 MiB fixture becomes Compact and a reference pinned at 782 granules reds. A table setting beats the injection and the default alike.
7 💡 The surviving source comment says the granule count has two randomized inputs; it has three, and all three are pinned in that same SETTINGS clause. It also credits min_bytes_for_wide_part = 0 with fixing the format at Wide, which index_granularity_bytes = 0 already does AGREE, noted, not blocking Corrected in this description. Left as it is in the source: I prescribed that wording myself in the fix round, and it is a phrasing imprecision over correct code. Say the word and I will make it exact.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal
per finding.

Two things that are not defects but are worth knowing. The pinned shape is more brittle than the
counts it replaces, and that is the price of the debuggability: the churn surface is now the
analyzer-generated Keys:/Aggregates: text plus Parts:/Granules: in the two actions = 1
blocks, while the five plain blocks carry step names and descriptions only. And the negative control
measured specificity as well as sensitivity, so the reference is not merely a photograph of the
current binary.

Session id: cron:clickhouse-review-slot-8:20260918-075300

@clickhouse-gh clickhouse-gh Bot closed this Sep 18, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 18, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The test reds on demand whenever the guard hunk from #116446 is absent, and the randomization divergence reproduces on demand through the runner's own injection seam, --merge-tree-settings "--index_granularity_bytes 2048", not as a rate.
b Root cause explained? Reported: a count() over ILIKE projects the plan onto one bit and discards it before the comparison, so a red row prints 1 -> 0 and no plan. Found while validating: Granules: depends on adaptive granule sizing and on the part format, and the runner randomizes both.
c Fix matches root cause? Yes. The counting wrapper is deleted and the plan itself pinned, which is what the failure output lacked; the divergence is pinned at the two table properties the printed number depends on, not with a blanket no-random-settings tag.
d Test intent preserved / new tests added? Preserved and strengthened: all 12 original claims still have a carrier, each now asserted against the whole plan rather than one bit. No behavioural row, SET pin or DDL property relaxed.
e Both directions demonstrated? Yes. Green with the guard, single run and 50/50 randomized; red without it, with per-block attribution and the Build ID asserted on the server both ways. Granule pins likewise: green with them, Granules: 782 -> 1563 on all four lines without them.
f Fix is general across code paths? 04367, the other test #116446 touched, already pins a plain EXPLAIN, and 04878 is the only test combining remote() + make_distributed_plan + EXPLAIN distributed = 1, so no sibling carries this counting shape. The behavioural FORMAT Null and HAVING rows are untouched: they are not pattern counts.
g Fix generalizes across inputs (params/datatypes/wrappers)? The input space here is the settings matrix, and the 7 blocks span the same one the 12 rows spanned: distributed_aggregation_memory_efficient x enable_memory_bound_merging_of_aggregation_results x distributed_plan_force_shuffle_aggregation x local/remote(). The randomized dimension is covered by 50/50.
h Backward compatible? (maintainer-approved exception only) N/A. No setting default, no format change, no SettingsChangesHistory.cpp entry; the only settings added are per-table DDL properties on the test's own fixture.
i Invariants and contracts preserved? Yes. Removing the guard reds 4 of the 7 blocks, with ShuffleExchange (by hash([__table1.k])) reappearing in both shard plans, while the 3 blocks asserting that the shuffle STAYS are byte-identical. That specificity half rules out a reference that merely photographs the binary.

Session id: cron:clickhouse-impl-slot-5:20260918-072500

@clickhouse-gh

clickhouse-gh Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [26ccaef]

Summary: ✅


AI Review

Summary

This PR rewrites 04878_distributed_plan_shuffle_bucket_order_promise from bit-count checks over EXPLAIN output to pinned plan snapshots, while keeping the runtime FORMAT Null and result-equality checks that cover the duplicate-bucket symptom. I reviewed the current diff, the touched test and reference, the relevant planner guard in makeDistributed.cpp, and the prior PR discussion, and I do not see an actionable correctness, stability, or metadata issue in the current version.

Missing context / blind spots
  • ⚠️ I did not rerun the stateless test locally because this checkout does not contain a ready build tree; the current CI workflow for this PR was still in progress during the review, so this verdict is based on code inspection and the existing validation evidence in the PR.
Final Verdict

✅ No actionable review findings. No inline comments were posted.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 18, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 18, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 19, 2026
Merged via the queue into ClickHouse:master with commit 0c11578 Sep 19, 2026
349 of 523 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 Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... 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-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... groeneai-origin-review-human PR origin: human review feedback on a groeneai PR 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.

3 participants