Repository navigation
Do not eliminate aggregators of GROUPING SETS keys with group_by_use_nulls - #125575
Merged
alexey-milovidov merged 4 commits intoOct 14, 2026
Merged
alexey-milovidov merged 4 commits into
alexey-milovidov merged 4 commits into
Conversation
…se_nulls` With `group_by_use_nulls` the keys of `GROUPING SETS` become `Nullable` in the output of the aggregation, even with a single set, while the argument of the aggregate function keeps its type. `optimize_aggregators_of_group_by_keys` replaced `any(k)` with `k`, so the column typed as `UInt64` was `Nullable(UInt64)`, and an outer `sum` read it as a plain column: a wrong result in release builds, and the `Bad cast from type DB::ColumnNullable to DB::ColumnVector<unsigned long>` exception in debug and sanitizer builds. Skip the optimization in this case in both the analyzer and the old interpreter. Found by the stress test of #123531: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123531&sha=808640fa34da62bf52e599b53b13ae30ab1de3c2&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Workflow [PR], commit [15fca46] Summary: ✅
AI ReviewSummaryThe PR disables Final VerdictStatus: ✅ Approve |
Contributor
Build profile diff (arm_release)Commit See the job log for details. |
`TreeRewriter::normalize` already rewrites single-set `GROUPING SETS` into a plain `GROUP BY` before `TreeOptimizer::apply`, and multi-set ones were already skipped, so the guard in `TreeOptimizer` never changed anything. The query with `enable_analyzer = 0` ran on the analyzer anyway, because the setting is rewritten to `1`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
deleted the
fix/aggregators-of-group-by-keys-grouping-sets-use-nulls
branch
October 14, 2026 20:54
This was referenced Oct 14, 2026
clickhouse-gh Bot
added a commit
that referenced
this pull request
Oct 14, 2026
Backport #125575 to 26.9: Do not eliminate aggregators of `GROUPING SETS` keys with `group_by_use_nulls`
clickhouse-gh Bot
added a commit
that referenced
this pull request
Oct 14, 2026
Backport #125575 to 26.8: Do not eliminate aggregators of `GROUPING SETS` keys with `group_by_use_nulls`
clickhouse-gh Bot
added a commit
that referenced
this pull request
Oct 15, 2026
Backport #125575 to 26.7: Do not eliminate aggregators of `GROUPING SETS` keys with `group_by_use_nulls`
alexey-milovidov
added a commit
that referenced
this pull request
Oct 15, 2026
Backport #125575 to 26.3: Do not eliminate aggregators of `GROUPING SETS` keys with `group_by_use_nulls`
strtgbb
pushed a commit
to Altinity/ClickHouse
that referenced
this pull request
Oct 15, 2026
…GROUPING SETS` keys with `group_by_use_nulls`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
group_by_use_nulls, the keys ofGROUPING SETSbecomeNullablein the output of the aggregation, even when there is only one set. The argument of the aggregate function keeps its original type.optimize_aggregators_of_group_by_keysreplacedanyHeavy(b)with the keyb, so a column typedUInt64actually heldNullable(UInt64). An outer aggregation then read it as a plain column. In release builds that gives a wrong result. In debug and sanitizer builds it throws theBad cast from type DB::ColumnNullable to DB::ColumnVector<unsigned long>exception.This change skips the optimization in that case in the analyzer. The old interpreter is not affected: it rewrites a single-set
GROUPING SETSinto a plainGROUP BYbefore the optimization, and it already skipped multi-setGROUPING SETS.The stress test of #123531 found it: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123531&sha=808640fa34da62bf52e599b53b13ae30ab1de3c2&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29
Related: #123531
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a wrong result, or an exception in debug builds, when
optimize_aggregators_of_group_by_keyseliminatedany,minormaxof aGROUPING SETSkey withgroup_by_use_nulls.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125575]
Version info
26.10.1.2406-master(included in26.10and later)26.9.20.10,26.8.28.11,26.7.31.11,26.3.52.6