Skip to content

Expand CUBE and ROLLUP over the GROUP BY list as written - #120671

Closed
navneet83 wants to merge 4 commits into
ClickHouse:masterfrom
navneet83:fix-cube-rollup-repeated-keys
Closed

navneet83 wants to merge 4 commits into
ClickHouse:masterfrom
navneet83:fix-cube-rollup-repeated-keys

Conversation

@navneet83

@navneet83 navneet83 commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

The key list was deduplicated before the grouping sets were expanded, so CUBE(x, x) produced the sets of CUBE(x). The positions of repeated keys are now passed to the Cube/Rollup transforms and serialized under a new per-step version; a peer too old to read them fails with SUPPORT_IS_DISABLED instead of returning wrong results.

Closes: #117904
Supersedes: #118186

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed GROUP BY CUBE and GROUP BY ROLLUP losing grouping sets when an expression is repeated in the list, e.g. CUBE(x, x) returned the sets of CUBE(x).


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

The key list was deduplicated before the grouping sets were expanded, so
`CUBE(x, x)` produced the two sets of `CUBE(x)` and `ROLLUP(x, x)` those of
`ROLLUP(x)`, while the same sets spelled out as `GROUPING SETS` were kept.
The positions of the repeated keys are now carried to the transforms, which
expand the list as written, and serialized under a new per-step version; a
peer that would drop them gets `SUPPORT_IS_DISABLED` instead of wrong results.

ClickHouse#117904
@clickhouse-gh

clickhouse-gh Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d3ba0b4]

Summary: ✅


AI Review

Summary

This PR keeps repeated GROUP BY positions through planner analysis, Rollup/Cube execution, and query-plan serialization so ROLLUP / CUBE expand the key list as written instead of collapsing to the deduplicated key set. I reviewed the current diff, the touched execution and serialization code, the added tests, and the prior discussion, and I do not have an actionable correctness finding on the current revision.

Final Verdict

✅ No actionable findings.

LLVM Coverage Report

Measured on commit d3ba0b4.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 216/218 (99.08%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 17, 2026
Comment thread src/Planner/Planner.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d3ba0b4ea with master 655dd416c (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

10 object files changed (+52.18 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/QueryPlan/CubeStep.cpp.o 187.61 KiB 206.18 KiB +18.57 KiB (+9.90%)
src/CMakeFiles/dbms.dir/Processors/QueryPlan/RollupStep.cpp.o 159.92 KiB 177.95 KiB +18.04 KiB (+11.28%)

716 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

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

Job report

@navneet83
navneet83 marked this pull request as ready for review September 17, 2026 23:36
@navneet83

Copy link
Copy Markdown
Member Author

This is ready from my side. The two red checks are on the CI side: Build profile diff fails on its logs-cluster query, and the perf shard's 10 errors is the compare script miscounting log lines (#116491), 0 slower queries across all six shards.

@navneet83

Copy link
Copy Markdown
Member Author

Merged master to pick up #120932, which fixes the Upgrade check failure here: the Code: 344 Keeper feature-flag error on DROP TABLE that has been failing the upgrade check on every PR since 09-18. Nothing else changed.

@navneet83

Copy link
Copy Markdown
Member Author

@KochetovNicolai could you take a look when you have a moment? This touches CubeStep/RollupStep and the planner's GROUP BY expansion, which you reworked in #114950.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GROUP BY CUBE/ROLLUP drops repeated grouping keys, losing grouping sets

2 participants