Repository navigation
Conversation
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-23:20260610-225430 |
|
cc @novikd @vdimir — could you review this? It rebases #39574 and ports the |
|
Workflow [PR], commit [15bce85] Summary: ✅
AI ReviewSummaryReviewed PR #107106 at Nullable-output consumers traced:
Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings or thread-state changes are needed; the remaining CI checks must complete through the normal merge gates. |
7507ca2 to
a54354e
Compare
Pre-PR validation gate (updated after addressing review)
Session id: cron:clickhouse-worker-slot-15:20260611-020200 |
a54354e to
a458d3e
Compare
Pre-PR validation gateRe-run for the test coverage update (a458d3e), which adds expression-level cases to
Session id: cron:clickhouse-worker-slot-31:20260611-030000 |
a458d3e to
878b0ce
Compare
Pre-PR validation gate (docs follow-up, head 878b0ce)This commit is a docs-only follow-up to the clickhouse-gh[bot] change-request: align the user-facing docs with the new
Session id: cron:clickhouse-worker-slot-4:20260611-042300 |
878b0ce to
a7eba4d
Compare
Pre-PR validation gateFor the
Session id: cron:clickhouse-worker-slot-8:20260611-051100 |
a7eba4d to
92e774a
Compare
Rebase and port of ClickHouse#39574 (original author @novikd) to the analyzer. With group_by_use_nulls enabled, GROUP BY keys are reported as Nullable for GROUPING SETS, ROLLUP and CUBE, but plain GROUP BY ... WITH TOTALS was left out: the keys stayed non-nullable and the TOTALS summary row showed 0 instead of NULL. The original PR fixed this in the old interpreter by converting the keys inside AggregatingStep. The analyzer is now the default and needs the same behavior, so this ports the fix to the analyzer in two places that gate the group_by_use_nulls handling on the GROUP BY modifier and previously listed only GROUPING SETS / ROLLUP / CUBE: * IdentifierResolveScope: include WITH TOTALS so the query tree resolves the GROUP BY keys (and expressions over them) as Nullable. Without this the planner-side conversion below produces a Nullable key column at runtime while query-tree analysis still treats the key as non-nullable, e.g. 'k IS NULL' over the TOTALS row folds to 0 and toTypeName(k) reports the non-nullable type, and a wrapping subquery sees the wrong key type. * PlannerExpressionAnalysis: include WITH TOTALS so the result type of the keys is analyzed as Nullable, consistent with the scope above. * Planner: insert a toNullable conversion for the GROUP BY keys right before the TotalsHaving step. The TOTALS row is built from default values, so a Nullable key column yields NULL there. This runs for CUBE/ROLLUP WITH TOTALS as well, because their own nullable conversion happens after TotalsHaving and would otherwise leave the TOTALS row non-NULL. Keys that cannot be made Nullable are skipped. GROUP BY ALL needs an extra step. Its key list is empty until expandGroupByAll collects the keys from the projection, and that normally runs near the end of resolveQuery, after resolveGroupByNode is the only place that registers keys in nullable_group_by_keys. So with the new WITH TOTALS gate, GROUP BY ALL took the delayed-resolution path with no registered keys: the projection was typed non-nullable while validateAggregates compared it against keys it had converted to Nullable, raising NOT_AN_AGGREGATE. resolveQuery now expands GROUP BY ALL before resolveGroupByNode when group_by_use_nulls is set. The expansion uses a throwaway clone of the projection so the real projection keeps its aliases and is not constant-folded against the pre-nullable types; the clone's resolved key nodes still match the real keys structurally, because nullable_group_by_keys ignores aliases and types. GROUP BY ALL WITH TOTALS then behaves exactly like the explicit GROUP BY case, and GROUP BY ALL WITH ROLLUP/CUBE (which had the same NOT_AN_AGGREGATE error before) works too. Constant GROUP BY keys are folded away before aggregation and are not real key columns, so they keep their constant value in the TOTALS row instead of becoming NULL. This is the same as CUBE/ROLLUP/GROUPING SETS WITH TOTALS, where a folded constant key likewise stays constant in the summary rows. 02373 covers the raw key value in the TOTALS row, a pure constant key, and a mixed real plus constant key. It also covers the expression level so the IdentifierResolveScope typing is protected: toTypeName(k) over the WITH TOTALS result, 'k IS NULL' which is 1 in the TOTALS row, and a wrapping subquery that selects the TOTALS row with WHERE k IS NULL. Without the IdentifierResolveScope change these report the non-nullable type and fold 'k IS NULL' to 0 while the raw value cases still pass, so they are the regression guard for that part of the fix. The same expression-level cases are added for GROUP BY ALL WITH TOTALS as the regression guard for the expansion-order fix above. Documentation: the group_by_use_nulls setting text in src/Core/Settings.cpp and the WITH TOTALS section in docs/en/sql-reference/statements/select/group-by.md now state that with group_by_use_nulls = 1 the real GROUP BY keys in the WITH TOTALS row are reported as NULL, qualified to only keys whose types can be wrapped in Nullable. Keys whose types cannot be made Nullable (for example Array and Map, which fail canBeInsideNullable) keep their default value, as does a folded constant key. The behavior is analyzer-only; the affected tests set enable_analyzer = 1. Co-authored-by: Dmitry Novik <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]>
92e774a to
0d313cb
Compare
Pre-PR validation gateThis round addresses the clickhouse-gh[bot] change-request on
Session id: cron:clickhouse-worker-slot-2:20260611-063900 |
|
CI finished on
The remaining red marks (Mergeable Check, PR) are derivative aggregators of the above. All other checks pass. Session: cron:our-pr-ci-monitor:20260611-120000 |
|
CI finished on HEAD Session id: cron:our-pr-ci-monitor:20260611-160000 |
|
@groeneai, as the bad integration test is fixed, update the branch in this PR, so we will have a chance to merge it. |
|
@alexey-milovidov done. Branch updated to the latest master (merged |
…74-group-by-use-nulls-totals
Every regression case for the WITH TOTALS key nullification was local, so the initiator's second stage went untested. There the keys are converted after MergingAggregated, i.e. the header the conversion looks them up in comes from merging the shards' aggregation states rather than from a local AggregatingStep. Measured against master 7d76bcd over two shards via remote('127.0.0.{2,3}'): the TOTALS row there reports 0 / UInt64 / IS NULL = 0, so this arm is a regression guard and not a restatement of the local cases. It holds on 8 of 8 combinations of the randomized distributed settings (prefer_localhost_replica, distributed_aggregation_memory_efficient and the two group_by_two_level_threshold* floors), and 40 randomized runs of the file pass. The group_by_use_nulls = 0 twin pins that the keys stay non-Nullable there. Co-Authored-By: Claude Opus 5 <[email protected]>
CI finish ledger - 94f1c8eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Not caused by this pull request. Both signatures predate it and neither touches the code it Session id: cron:our-pr-ci-monitor:20260911-093124 |
# Conflicts: # src/Planner/Planner.cpp
…r `group_by_use_nulls` in `WITH TOTALS` The test was added on master after this PR and pinned the old behaviour, where `group_by_use_nulls` did not reach the keys of the totals row. With this PR the key is `Nullable` under `WITH TOTALS` and is `NULL` in the totals row, so the two `WITH TOTALS` cases move out of the "unchanged" guard section and the reference is updated accordingly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ulls docs The old query analyzer was removed in 26.10 and `enable_analyzer = 0` is now accepted and replaced with `1`, so the sentences saying that the old analyzer keeps the default key value in the totals row described behavior that no longer exists. Describe the behavior unconditionally in the `GROUP BY` statement documentation and in the `group_by_use_nulls` setting text, and drop the stale "analyzer-only" comment in 03912. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tive-unwrap pass
With this PR `group_by_use_nulls` also promotes the `GROUP BY` keys of a plain
`WITH TOTALS` query to `Nullable`, but `OptimizeLimitByInjectiveFunctionsPass`
registered the `Nullable` shape of a key only for `GROUPING SETS`, `ROLLUP` and
`CUBE`. So `LIMIT BY` was unwrapped past the key, for example:
SELECT toString(number) AS s FROM numbers(3) GROUP BY toString(number)
WITH TOTALS ORDER BY s LIMIT 1 BY s
SETTINGS group_by_use_nulls = 1, optimize_injective_functions_in_group_by = 0
failed with NOT_FOUND_COLUMN_IN_BLOCK. Use the same condition as
`IdentifierResolveScope` and cover it in 05213. Also drop the stale
"only supported by the analyzer" setup from 02373.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
FunctionToSubcolumnsPass already opts out for ROLLUP, CUBE and GROUPING SETS when group_by_use_nulls is set, because the rewrite is not prepared for keys whose post-GROUP BY type is wrapped in Nullable. WITH TOTALS now takes the same nullable-key path, so it needs the same opt-out. Without it a key spelled as tupleElement(tup, 'a') was rewritten to tup.a in GROUP BY only and the query failed with NOT_FOUND_COLUMN_IN_BLOCK (master returns the rows, and the same query with WITH ROLLUP works). Co-Authored-By: Claude Opus 5.5 <[email protected]>
enable_analyzer is frozen at 1, so the pins select nothing and only widened the diff against master; the queries are back to master's text. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 6368520Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 146 check runs completed and Session id: cron:our-pr-ci-monitor:20261002-230431 |
…compatibility setting Add `group_by_use_nulls_with_totals` (default `true`, `26.10` entry in the settings history with previous value `false`). When disabled, or with `compatibility` set to a version before `26.10`, `group_by_use_nulls` does not affect `WITH TOTALS`, which keeps the previous result shape. This allows mixed-version `remote` / `Distributed` queries to keep working during a rolling upgrade. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ING SETS With `group_by_use_nulls_with_totals = 0`, `ROLLUP`, `CUBE` and `GROUPING SETS` still make the keys `Nullable` through `group_by_use_nulls`; only the totals row falls back to default values. The setting description said the keys keep their types unconditionally. Also mention the new setting in the `WITH TOTALS` paragraph of the `GROUP BY` statement documentation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The 26.10 release branch has already been cut, so the new setting first ships in 26.11. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - a600b80Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261028-063004 |
…74-group-by-use-nulls-totals Resolve the conflict in `src/Planner/Planner.cpp`: master moved the planner step helpers into `src/Planner/PlannerSteps.cpp`/`PlannerSteps.h`. Take master's `Planner.cpp`, move `addConvertGroupByKeysToNullableStep` into `PlannerSteps.cpp` (declared in `PlannerSteps.h`), and keep its call before `addTotalsHavingStep` in `Planner.cpp` together with the `group_by_use_nulls`/`group_by_use_nulls_with_totals` setting declarations. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
GROUP BY ... WITH TOTALSnow respects thegroup_by_use_nullssetting: the GROUP BY keys in the TOTALS summary row are reported asNULLinstead of their default values, consistent withGROUPING SETS,ROLLUPandCUBE. Keys whose types cannot be wrapped inNullable(for exampleArrayorMap) keep their default value. Disabling the new settinggroup_by_use_nulls_with_totals(orcompatibilitybefore26.11) restores the previous behavior.Description
Port of #39574 (original author @ novikd) to current master.
With
group_by_use_nulls = 1, GROUP BY keys are already reported asNullableforGROUPING SETS,ROLLUPandCUBE, but plainGROUP BY ... WITH TOTALSwas left out: the keys stayed non-nullable and the TOTALS summary row showed0(the default value) instead ofNULL.This ports the original fix to the analyzer and planner:
IdentifierResolveScope: resolve the keys, and the expressions over them, asNullableforWITH TOTALStoo.PlannerExpressionAnalysis: includeWITH TOTALSin thegroup_by_use_nullscondition so the result type of the keys is analyzed asNullable.Planner: insert atoNullableconversion for the GROUP BY keys before theTotalsHavingstep. The TOTALS row is filled from default values, so aNullablekey column yieldsNULLthere. This also coversCUBE/ROLLUP WITH TOTALS, whose own conversion runs afterTotalsHaving.OptimizeLimitByInjectiveFunctionsPass: register theNullableshape of theWITH TOTALSkeys too, as forROLLUP/CUBE/GROUPING SETS, soLIMIT BYis not unwrapped past a key (that failed withNOT_FOUND_COLUMN_IN_BLOCK).FunctionToSubcolumnsPass: skip the subcolumn rewrite forWITH TOTALS, as forROLLUP/CUBE/GROUPING SETS(a key spelledtupleElement(tup, 'a')failed withNOT_FOUND_COLUMN_IN_BLOCK).group_by_use_nulls_with_totals(default1,0withcompatibilitybefore26.11) gates all of the above; when disabled, the previous result shape is kept.Example (before this change the last row was
0):Upgrade note: a single-shard
remote/Distributedquery withgroup_by_use_nulls = 1andWITH TOTALSfrom an older initiator fails withCANNOT_INSERT_NULL_IN_ORDINARY_COLUMNunless the upgraded servers setgroup_by_use_nulls_with_totals = 0until every node is upgraded.Tests: new
02373_group_by_use_nulls_with_totals(from #39574) and05355_group_by_use_nulls_with_totals_setting; updated references of seven existing tests.Workflow [PR]
Sync PR [sync-upstream/pr/107106]