Repository navigation
Conversation
With group_by_use_nulls = 1, a GROUPING SETS key's declared type is promoted to Nullable(UInt8) by FunctionNode::getResultType (src/Analyzer/FunctionNode.h:193) and the ActionsDAG node stores that type. FunctionIn declares plain UInt8 (src/Functions/in.cpp:58), and its executeImpl discarded the result_type argument entirely by forwarding to a private overload that had no such parameter. The framework's own reconciliation wrappers do not cover this: the constant wrapper is disabled (:66), and the Nullable wrapper only ever reacts to nullability in the arguments, which this promotion is not. For GLOBAL IN over a table the set is a FutureSet still unfilled while the header is computed, so future_set->get() returns null and the dry-run path returned a bare ColumnUInt8 where Nullable(UInt8) was declared. columnMatchesType compares type indexes first (src/Columns/validateColumnType.cpp:70-71): a bare ColumnUInt8 reports TypeIndex::UInt8 while DataTypeNullable reports TypeIndex::Nullable, so the check in executeActionForPartialResult (src/Interpreters/ActionsDAG.cpp:1341) threw LOGICAL_ERROR, aborting debug and sanitizer builds: Unexpected return type from globalIn. Expected Nullable(UInt8). Got UInt8 Thread result_type into the private executeImpl and reconcile the produced column against it once, at the single return chokepoint. That covers all seven exits, including the two returning a ColumnConst and the Set::execute main path which returns a bare ColumnUInt8 (src/Interpreters/Set.cpp:416). makeNullable preserves constness and is a no-op on an already-nullable column. Nullability driven by the arguments is resolved before executeImpl is reached, either by returning a NULL constant outright or by passing removeNullable(result_type) down and wrapping the result afterwards (src/Functions/IFunction.cpp:215, :232), so a Nullable type arriving here can only come from the promotion above and no row of the result can be NULL. Every variant registered by REGISTER_FUNCTION(In) shares this class, so globalNotIn, globalNullIn and globalNotNullIn are fixed with it. Behaviour is unchanged whenever the declared type is not Nullable, which is every ordinary query. This follows the established convention: FunctionAnyArityLogical reads result_type->isNullable() for exactly this promotion (src/Functions/FunctionsLogical.cpp:786), which is why an AND of comparisons works as a GROUPING SETS key under group_by_use_nulls. Fixing the assertion instead would leave the identical check in ExpressionActions::execute (src/Interpreters/ExpressionActions.cpp:694) and would mask genuine declared-versus-actual mismatches in every other function. Instrumenting the six exits reachable for these registrations (the ignore_set exit is not reachable without the IgnoreSet variants) shows the dry-run "set not ready" exit is the only one reached with a Nullable declared type: 6 of 195 invocations across 13 query shapes. The chokepoint placement therefore rests on the Set::execute return type above rather than on a currently reachable second exit. Release builds surface this as a query error rather than an abort. The abort is gated on debug_or_sanitizer_build or the abort_on_logical_error server setting (src/Common/Exception.cpp:112). Reported on ClickHouse#109455, where the failing query was an AST-fuzzer mutation. It is reachable from ordinary SQL, and the new test's first arm is that query.
Internal second-model review (click to expand)Three review rounds, each an independent cold review plus a separate reviewing model, adjudicated
Also verified, no change needed: all seven returns are covered by the single chokepoint, including |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-review-slot-49:20260806-235800 |
|
cc @Algunenano @Avogar, could you review this? |
|
Workflow [PR], commit [3923f59] Summary: ❌
AI ReviewSummaryThis PR fixes Final Verdict✅ No findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 9/9 (100.00%) · Uncovered code |
Build profile diff (arm_release)No arm_release build profile data for commit 3923f59 - the build was skipped, reused from cache, or predates profile upload. |
The `low cardinality left` arm of
04812_group_by_use_nulls_grouping_sets_global_in failed in
`Stateless tests (amd_asan_ubsan, distributed plan, parallel)` with
Code: 117. DB::Exception: Deserialized function globalIn has invalid type.
Expected LowCardinality(UInt8), deserialized UInt8. (INCORRECT_DATA)
thrown by the plan consistency check in `ActionsDAG::deserialize`. The
mismatch is `LowCardinality(UInt8)` against `UInt8`, with no `Nullable` on
either side, so it is not the mismatch this test covers.
It is issue ClickHouse#112028, an unrelated pre-existing defect: a `LowCardinality`
argument to `IN` loses that wrapper when the query plan is serialized to a
remote replica. Measured on an unpatched server, the same error appears with
`group_by_use_nulls` absent and with a plain local `IN`, and it needs a
`LowCardinality` left argument, a non-local replica and
`serialize_query_plan = 1`. Neither `GLOBAL`, `GROUPING SETS` nor
`group_by_use_nulls` takes part in it. Removing any one of those three
ingredients makes the query return `UInt8` and `1`.
Pinning `serialize_query_plan = 0` on that single arm therefore removes only
the unrelated interference. The arm keeps its own coverage: on an unpatched
server it still aborts with `Unexpected return type from globalIn. Expected
Nullable(UInt8). Got UInt8`, and it passes with the fix. The other nine arms
are unchanged and run with plan serialization active, including the five that
reproduce the reported failure. Thirty stateless tests already pin the
setting the same way, for example 03400_explain_distributed_bug.sql and
03303_distributed_explain.sql.
CI fix pushed:
|
| configuration | unpatched | this PR |
|---|---|---|
10 arms, prefer_localhost_replica = 0, serialize_query_plan = 1 |
6 arms abort, 4 controls pass | all 10 pass |
| the pinned arm alone | aborts | passes |
the test at --prefer_localhost_replica 0 |
5 of 5 fail without the pin | 20 of 20 pass |
| the test, default randomization | - | 50 of 50 and 50 of 50 pass |
CI reported 20 of 20 failures under the drawn settings with
Culprit settings: --prefer_localhost_replica 0, so that fourth row is the same
configuration in both directions.
Thirty stateless tests already pin this setting the same way, for example
03400_explain_distributed_bug.sql and 03303_distributed_explain.sql.
Source is unchanged in this push: the diff is three added and one removed line, all in
the test.
Session id: cron:clickhouse-maint-slot-15:20260807-105600
CI finish ledger - 400b6afEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
CI is fully finished on this head: 175 check-runs from the paginated check-runs API, 0 incomplete, I will fix the old-analyzer failure on this PR and push; the other three are owned as listed. I am not re-pinging reviewers. Session id: cron:our-pr-ci-monitor:20260807-190001 |
04812_group_by_use_nulls_grouping_sets_global_in failed in
`Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated,
WasmEdge, parallel, 2/3)`, the only stateless failure on this branch's head.
Nine of its ten arms lose the `Nullable` wrapper the reference expects:
-Nullable(UInt8) 1
+UInt8 1
and the only unchanged arm is `control no group_by_use_nulls`. The job's own
diagnostics step reports `Failed 3 out of 3 reruns`, so it is deterministic.
That `UInt8` is correct on the old analyzer, so nothing in src/ needs
changing. `group_by_use_nulls` promotes a GROUPING SETS key only where the
analyzer arms the promotion. The new analyzer arms it at a single grouping set
(src/Analyzer/Resolve/IdentifierResolveScope.cpp:55). The old analyzer's
equivalent is `appendGroupByModifiers`, whose first statement returns unless
ROLLUP or CUBE (src/Interpreters/ExpressionAnalyzer.cpp:1597), and its
classifier reaches GROUPING_SETS only when there is more than one set (:312).
Every arm here uses GROUPING SETS with exactly one set, so no key is promoted
and the declared type stays `UInt8`.
The divergence is a property of the analyzer rather than of `IN`: a plain
column key with no `IN` anywhere reads `UInt8` on the old analyzer and
`Nullable(UInt8)` on the new one. Where the old analyzer's gates do admit the
promotion (two grouping sets, ROLLUP, CUBE) it already yields
`Nullable(UInt8)` on the unpatched binary, so extending the fix there would be
dead code.
Declaring the precondition keeps every arm running and asserting on every
lane. It does not silence the test: with the pin applied and src/Functions/in.cpp
reverted to master, the test still aborts on its first witness arm with
`Unexpected return type from globalIn. Expected Nullable(UInt8). Got UInt8`.
On a new-analyzer server the pinned and unpinned files produce byte-identical
output, so the line is inert there. Deleting it again reproduces the failure.
A session-level `SET` covers every later statement because clickhouse-test
runs a .sql file as one --multiquery client session (tests/clickhouse-test:3680)
and `InterpreterSetQuery::execute` applies the change to that session
(src/Interpreters/InterpreterSetQuery.cpp:48). It also overrides the profile
form CI installs for this lane (tests/config/install.sh:297). 974 of the 10007
stateless .sql tests on master carry a line exactly equal to
`SET enable_analyzer = 1;`, the nearest sibling being
03794_global_in_nullable_type_mismatch.sql:9, which pins the same
`GLOBAL IN`/Nullable mismatch family the same way.
`-- Tags: no-old-analyzer` was rejected because it skips the whole file
(tests/clickhouse-test:2861), dropping all ten arms from the five old-analyzer
stateless check-runs. A `.oldanalyzer.reference` was rejected because it would
record `UInt8` as an expected outcome of the fixed build.
After the pin: 50 of 50 randomized runs on a new-analyzer server and 50 of 50
on the old-analyzer profile. A 43-test group_by_use_nulls slice on that
profile, pin present against pin removed on the same binary, moves only this
test and shows no regressions.
The reference file is unchanged and src/ is untouched.
Internal second-model review: round 4 (CI fix), 0 findingsThis push was reviewed by a cold second pass plus a separate reviewing model, both blind to the Scope. The delta is +4 / -0 lines in one test file: two comment lines and The question the review had to settle is not "does the pin make the red go away" but is Test liveness was checked structurally, not only from the implementer's log: the pin sets the Both rejected alternatives were re-checked.
All eleven Two safety claims in the original Also checked. The cloud lane cannot conflict: it force-passes the analyzer as a client option, 💡 One residual, disclosed and deliberately not chased: with the pin in place no stateless test Session id: cron:clickhouse-review-slot-49:20260807-221100 |
CI fix: pin the new test to the analyzer whose promotion it asserts
and the only unchanged arm is That I confirmed that the divergence is a property of the analyzer and not of The push adds one line,
The second row is the one that matters: with the pin in place an unpatched server still Randomized runs after the pin: 50 of 50 on a new-analyzer server and 50 of 50 on the I preferred this to the two alternatives. Source is unchanged in this push: the diff is four added lines, all in the test, and the Session id: cron:clickhouse-impl-slot-41:20260807-212900 |
The `various` style sub-check rejects "new analyzer" tree-wide: the analyzer has been the default since 24.3, so the wording rule asks for "the analyzer" or "Analyzer" instead. The comment added by the previous commit tripped it. The sentence contrasts the analyzer's GROUPING SETS key promotion with the old analyzer's `appendGroupByModifiers`, which returns early for GROUPING SETS, so "the analyzer's" carries the intended meaning unchanged. "The old analyzer's" in the same sentence stays: the rule bans only "new analyzer"/"new query analyzer". Comment-only: stripping `--` comments leaves the file byte-identical to the previous commit, so the committed reference file cannot be affected. The word was removed rather than the line reflowed, because the rule has a second pass that also matches "new" ending one line with "analyzer" continuing on the next.
CI finish ledger - 3923f59CI is fully finished on this head: 175 check-runs, 0 queued/in_progress, Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Scoping note on the STID 6726-6444 row: this PR changes The earlier deterministic failure on Session id: cron:our-pr-ci-monitor:20260808-060000 |
|
This is a wrong fix. The error was real and wrapping the output with Nullable just caused it to run without errors, but introduced wrong results if the aggregation returned any Nulls (f.e. with empty GROUPING SET), with the fix in this PR these Nulls were then replaced by the non-null result of the recomputed IN. Closing this PR, see the correct fix here: #116980. |
|
You are right, and the wrong-results half is worse than I would have guessed. Measured on a debug build (26.8.1),
The same three queries with a local Two things in that matrix I had missed entirely. The non-constant left operand is still broken with my change, byte-identical to master, so The last column is your mechanism on my tree: Not reopening. I have posted a correction on #109455, where the arm_debug report came from, and I am tracking #116980 for that signature. |
The dedup map in `buildQueryTreeForShard` was keyed on an alias-sensitive tree hash, but every occurrence already carries its own `__tableN` from `createUniqueAliasesIfNecessary`, so each one built a separate temporary table. The differing `__set_` action node names then kept the projection from recognising a repeated GROUP BY key: it rebuilt the expression after aggregation instead of reading the aggregated column, losing the NULL the aggregator writes for super-aggregate rows and failing the declared-versus- produced type check before that. Closes: #114254 Related: #113750 Co-Authored-By: Claude Opus 5 <[email protected]>
The dedup map in `buildQueryTreeForShard` was keyed on an alias-sensitive tree hash, but every occurrence already carries its own `__tableN` from `createUniqueAliasesIfNecessary`, so each one built a separate temporary table. The differing `__set_` action node names then kept the projection from recognising a repeated GROUP BY key: it rebuilt the expression after aggregation instead of reading the aggregated column, losing the NULL the aggregator writes for super-aggregate rows and failing the declared-versus- produced type check before that. Closes: #114254 Related: #113750 Co-Authored-By: Claude Opus 5 <[email protected]>
Related: #109455
Related: #110551
Closes: #114254
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
LOGICAL_ERROR: Unexpected return type from globalIn. Expected Nullable(UInt8). Got UInt8when aGLOBAL INover a table is used as aGROUPING SETSkey withgroup_by_use_nulls = 1.inand its seven sibling functions now return a column matching the result type they are given.Description
Reported on #109455 as a
Stress test (arm_debug)failure unrelated to that PR. The failing query was an AST-fuzzer mutation, but the defect is reachable from plain SQL.Root cause.
group_by_use_nullspromotes a grouping key's declared type toNullable(UInt8)viaFunctionNode::getResultType(src/Analyzer/FunctionNode.h:193), and the DAG node stores it;FunctionIndeclares plainUInt8(src/Functions/in.cpp:58) and discarded theresult_typehanded to it. Neither framework wrapper covers this: the constant one is disabled (:66) and the Nullable one reacts only to argument nullability. WithGLOBAL INover a table the set is still unfilled while the header is computed, so the dry-run path returned a bareColumnUInt8whereNullable(UInt8)was declared, andcolumnMatchesTypefailed atsrc/Interpreters/ActionsDAG.cpp:1341.Change.
result_typeis threaded into the privateexecuteImpland the produced column is reconciled against it once, at a chokepoint above all seven returns. Argument-driven nullability is resolved beforeexecuteImplis reached (src/Functions/IFunction.cpp:215,:232), so aNullablehere can only come from the promotion above and no row can be NULL. Allinvariants share this class, and behaviour is unchanged whenever the declared type is notNullable.FunctionsLogical.cpp:786reads the same predicate.Validation. New stateless test whose first arm is the reported query: six witness arms and four controls, each asserting a value and a type. Every witness aborts an unpatched debug server and passes with the change; the controls read identically on both. 100/100 runs pass (50 randomized, 50 without) and a 197-test slice shows 0 regressions. A release build gives a query error, not an abort. The test pins
enable_analyzer = 1, the analyzer whose promotion it asserts: the old analyzer returns early forGROUPING SETS(src/Interpreters/ExpressionAnalyzer.cpp:1597), soUInt8is correct there, and an unpatched server still aborts on the first witness arm with the pin in place.