Skip to content

Fix inconsistent AST formatting for GROUP BY CUBE(...) WITH ROLLUP#100376

Open
alexey-milovidov wants to merge 8 commits intomasterfrom
fix-group-by-cube-with-rollup-ast-formatting
Open

Fix inconsistent AST formatting for GROUP BY CUBE(...) WITH ROLLUP#100376
alexey-milovidov wants to merge 8 commits intomasterfrom
fix-group-by-cube-with-rollup-ast-formatting

Conversation

@alexey-milovidov
Copy link
Copy Markdown
Member

GROUP BY CUBE(x) WITH ROLLUP was parsed into an AST with both group_by_with_cube and group_by_with_rollup flags set. The formatter then produced GROUP BY x WITH ROLLUP WITH CUBE, but the parser could not parse this back because the second WITH clause only accepted TOTALS. This caused an "Inconsistent AST formatting" exception in debug builds.

Fix by replacing the two separate WITH parser blocks in ParserSelectQuery with a single loop that accepts any combination of WITH ROLLUP, WITH CUBE, and WITH TOTALS modifiers (rejecting duplicates).

Fixes #100320

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):

Fix "Inconsistent AST formatting" exception in debug builds when using GROUP BY CUBE(...) WITH ROLLUP or similar combinations.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

`GROUP BY CUBE(x) WITH ROLLUP` was parsed into an AST with both
`group_by_with_cube` and `group_by_with_rollup` flags set. The formatter
then produced `GROUP BY x WITH ROLLUP WITH CUBE`, but the parser could
not parse this back because the second `WITH` clause only accepted
`TOTALS`. This caused a "Inconsistent AST formatting" exception in
debug builds.

Fix by replacing the two separate `WITH` parser blocks with a single
loop that accepts any combination of `WITH ROLLUP`, `WITH CUBE`, and
`WITH TOTALS` modifiers (rejecting duplicates).

Fixes #100320

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Mar 22, 2026

Workflow [PR], commit [83fe17a]

Summary:

job_name test_name status info comment
Stress test (arm_msan) failure
MemorySanitizer: use-of-uninitialized-value (STID: 1003-358c) FAIL cidb, issue
AST fuzzer (arm_asan_ubsan) failure
Server unresponsive: memory limit exceeded FAIL cidb

AI Review

Summary

This PR fixes a real parser/formatter round-trip inconsistency for GROUP BY ... WITH modifiers by replacing split WITH handling with a single loop that accepts valid combinations and rejects duplicates. The change is narrow, test coverage includes the reported regression and duplicate-modifier syntax errors, and I did not find correctness, safety, or compatibility issues in the touched logic. High-level verdict: ✅ approve.

ClickHouse Rules
Item Status Notes
Deletion logging
Serialization versioning
Core-area scrutiny
No test removal
Experimental gate
No magic constants
Backward compatibility
SettingsChangesHistory.cpp
PR metadata quality
Safe rollout
Compilation time
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 22, 2026
…ests

Syntax errors are caught by the client-side parser before being sent
to the server, so they must use `clientError` instead of `serverError`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alexey-milovidov
Copy link
Copy Markdown
Member Author

#100298

alexey-milovidov added a commit that referenced this pull request Mar 29, 2026
The test checked specific part names after `OPTIMIZE`, but with
randomized settings (e.g. `enable_parallel_replicas`), the merge
selector can pick different pairs of parts to merge, resulting in
different part names. Check the count of active parts instead, which
is always 2 regardless of merge order.

Seen in #100376

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
alexey-milovidov added a commit that referenced this pull request Mar 29, 2026
The test checked specific part names after `OPTIMIZE`, but with
randomized settings the merge selector can pick different pairs of
parts to merge, resulting in different part names. Check the count
of active parts instead, which is always 2 regardless of merge order.

Seen in #100376

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Mar 31, 2026

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.70% 76.70% +0.00%

Changed lines: 88.89% (24/27) · Uncovered code

Full report · Diff report

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

Labels

pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

executeQueryImpl_aborted

1 participant