Repository navigation
Conversation
|
Pre-PR validation gate (TASK.md Phase 4 Step 9): a) Deterministic repro? Yes. The reproducer in issue #91119 ( b) Root cause explained? Yes. The analyzer's c) Fix matches root cause? Yes — the fix is in the analyzer, not the planner. PR #100365 attempted a planner-side reconciliation ( d) Test intent preserved? / New tests added? Both. The new test e) Demonstrated in both directions? Yes. Without the fix the server crashes with f) Fix is general, not a narrow patch? Yes. The fix is in Session: cron:clickhouse-ci-task-worker:20260508-074500 |
|
cc @novikd @KochetovNicolai — could you review this? It fixes #91119 by extending the analyzer's |
|
cc @PedroTadim — invited me here. The reproducer from #91119 (and related cases — CUBE, GROUPING SETS, aggregate function over correlated outer column, HAVING/WHERE with correlated subqueries, Nullable source) all return correct results with this fix. Also non-regressed against the existing |
|
Workflow [PR], commit [20dfe0b] Summary: ❌
AI ReviewSummaryThe PR extends Findings
Tests
Final VerdictStatus: |
CI Status — covered SHA
|
| Check | Test | Disposition |
|---|---|---|
Fast test |
Server died |
Chronic Fast-test infra flake. The Fast-test runner reports WARNING: Timeout exceeded [300], sending SIGTERM followed by Hung check failed: server is not responding. CIDB 30d shows Server died is endemic across 100+ PRs (top: PR #104754=33, PR #100185=83) and master (20 hits). Last-test-before-hang on this run was 01548_uncomparable_columns_in_keys at 06:13:31, then a 42-second silence before the timeout — clearly not produced by the analyzer changes in this PR (analyzer/group-by-use-nulls). |
Mergeable Check / PR / CH Inc sync |
n/a | Aggregator/infra rollup of the above. |
Code change unchanged since 2026-05-08. The 22 related existing tests still pass; the comprehensive new test 04210_91119_correlated_subquery_group_by_use_nulls.sql (12 query shapes) verifies the analyzer-level fix. Awaiting @novikd / @KochetovNicolai re-review.
— cron:our-pr-ci-monitor:20260604-073000
The previous commit replaced the OR-accumulated aggregate-function check in
`resolveExpressionNode` with a per-scope check, intending to allow the walk to
continue past the enclosing `QUERY` scope for correlated subqueries. That
broke `* APPLY x -> agg(x, key)` queries under `group_by_use_nulls = 1`:
* The LAMBDA scope sees the aggregate on its `expressions_in_resolve_process_stack`
but its own `nullable_group_by_keys` is empty, so the per-scope check skips
that scope's lookup.
* The outer `QUERY` scope holds the keys but its own stack does not see the
aggregate (the aggregate lives inside the lambda body), so the per-scope
check finds the key and wraps the inner reference as `Nullable`.
* The aggregate's `addBatchSinglePlace` then runs on a `ColumnNullable` where
its signature expects `ColumnVector<UInt64>` (or `ColumnString` for the
`min` family), and the `assert_cast` faults inside `SingleValueDataFixed::set`.
Fast test on PR ClickHouse#104350 SHA `30c602753b` reproduced this on
`04067_group_by_use_nulls_apply_aggregate.sql` (server died, signal 11 in
`AggregateFunctionNullVariadic::addBatchSinglePlace`). The exact same shape
appears in the AST-fuzzer findings tracked under STID `0250-30be`,
`1499-22cb`, `3336-34e8`, and `3336-2f87`.
Restore the OR-accumulated `in_aggregate_function_scope` flag for scopes
within the same query nesting level, and reset it when crossing into an
outer `QUERY` scope. The reset preserves the new correlated-subquery
behaviour: an outer scope's GROUP BY keys are evaluated relative to the
outer scope's own resolution context, so an aggregate in an inner subquery
must not shield against the outer scope's `nullable_group_by_keys`.
Adds a regression test
`04326_91119_apply_lambda_aggregate_rollup.sql` covering nine variants of
`* APPLY <lambda>` plus an aggregate plus `ROLLUP` / `CUBE` / `GROUPING SETS`
under `group_by_use_nulls = 1`, including the regex-filtered APPLY shape from
issue ClickHouse#98190 (STID `1499-22cb`). The existing
`04067_group_by_use_nulls_apply_aggregate` continues to pass.
Local verification: master HEAD passes; PR HEAD without this fix aborts on
`04067` query 1; PR HEAD with this fix passes `04067`, `04210` (PR's own
test), and `04326` (new regression test).
Related: ClickHouse#91119
Related: ClickHouse#98190
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-ci-task-worker:20260608-134700 |
CI Ledger - covered SHA: 6f52db2Workflow
The Fast-test failure on Session: cron:our-pr-ci-monitor:20260608-193000 |
|
Merged Addressed both review threads in 62084af:
Verified locally: the #91119 reproducer now returns Remaining CI reds are all the BuzzHouse |
CI Ledger — covered SHA:
|
|
Pushed What changed per comment:
One honesty note on scope: the compound-key correlated shapes (C1/C2) are currently rejected by the planner before execution, on both master and this branch: So this part of the change fixes the analyzer's type, which is the correctness issue you flagged, but there is no runnable query that demonstrates a row-level difference for it yet. The reachable shapes (bare GROUP BY key, with bare or compound correlated references, plus the original Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-5:20260610-090200 |
|
Pushed What broke and why: Fix: take the clone-and-wrap branch for any non-correlated match ( Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-7:20260610-104500 |
CI Ledger — covered SHA:
|
| Check | Failure | Classification | Disposition |
|---|---|---|---|
Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6) |
test_refreshable_mat_view_replicated/test.py::test_circular_dependencies_survive_restart |
chronic flaky (NOT PR-caused) | 30-day cross-PR: 14+ distinct unrelated PRs + master. Tracked under issue #106651. This PR only touches QueryAnalyzer.cpp + group_by_use_nulls tests, nothing in refreshable-mat-view / ReplicatedMergeTree. |
Stateless tests (arm_asan_ubsan, azure, parallel) |
Server died / OOM in dmesg / Logical error: Expected 3 to 10 arguments in table function azureBlobStorage, got 1 |
infra outage (NOT PR-caused) | The arm_asan_ubsan, azure, parallel runner is in a broad failure window: 272 distinct tests across 41 unrelated PRs failed on this exact check in the last 12h (OOM / Server died). Independent of this PR's diff. |
Mergeable Check / PR / CH Inc sync |
aggregators | downstream | Reflect the two above; no independent signal. |
The two Fast test failures from the prior commit (be05b67e0cc: 03023_group_by_use_nulls_analyzer_crashes, 04001_logical_error_with_cube) were PR-caused regressions from the rework and are fixed in e8d62a69667 (both verified passing locally in both directions). No PR-caused failures remain on the current HEAD.
|
Pushed While reviewing the rework I rebuilt the PR on current
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-9:20260610-190100 |
|
CI fully finished on HEAD fd5dfbf (Finish Workflow passed). The new commit on this HEAD is test-only (2 String-aggregate cases added to
A test-only commit cannot introduce a String-serialization or disk-metadata crash; the immediately-prior build (same code, minus 2 test lines) finished CI clean. Not PR-caused. The fix (#91119 correlated ROLLUP cast) is verified in both directions; awaiting @novikd re-review. |
|
CI finished on HEAD
Fast test, Style check, and Bugfix validation are all green on this HEAD. The two stateless failures share the |
|
Resolved the merge conflict with master (branch was behind by ~978 commits). The only conflict was in |
CI Ledger covered SHA:
|
…d-rollup-cast-wrapper Conflicts in `src/Analyzer/Resolve/QueryAnalyzer.cpp`: - anonymous namespace: kept both the PR's `ownsCorrelatedSource` and master's new helpers. - `resolveMatcher`: kept the PR's `applyGroupByUseNullsToExpression` call for `APPLY` results before master's new projection-naming logic. - `resolveQuery`: master added a `GROUP BY ALL` branch under `group_by_use_nulls`. Its throwaway projection resolution already applies `REPLACE` mappings to the unresolved clauses, so `applyReplaceTransformersToUnresolvedClauses` now runs only in the non-`GROUP BY ALL` branch. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Merged
Local checks:
The previous head's reds ( As agreed above, we're still waiting for #118476 to land. It is open as of 2026-09-23. Once it lands, this branch will be cut down to the correlated-subquery subset, which drops the |
…TIL` under `group_by_use_nulls` The deferred pre-pass `applyReplaceTransformersToUnresolvedClauses` replayed the `SELECT * REPLACE` mappings into seven clauses but not into the `LIMIT AFTER` / `LIMIT UNTIL` boundaries, which the eager `resolveMatcher` path rewrites. With `group_by_use_nulls = 1`, `SELECT * REPLACE(a * 10 AS a) ... GROUP BY a WITH ROLLUP ORDER BY a LIMIT UNTIL a >= 30` raised `NOT_AN_AGGREGATE` instead of returning `0, 10, 20`. Rewrite both boundaries too and add the rollup/cube variant as a test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Dear @novikd, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Remove `applyReplaceTransformersToUnresolvedClauses` and its helper `collectMatcherProducedColumnNames`. They rewrote `IdentifierNode`s in the unresolved query tree, which the reviewer pointed out is incorrect, and the approximation of the matcher resolution kept diverging from `resolveQualifiedMatcher` / `resolveUnqualifiedMatcher` (qualified matchers, `ARRAY JOIN` aliases). The `SELECT * REPLACE` / `APPLY` ordering problem under `group_by_use_nulls` exists on `master` independently of the correlated subquery fix and is handled properly by ClickHouse#118476, which expands projection matchers before the other clauses. This PR is now cut down to the correlated subquery part: `applyGroupByUseNullsToExpression` and the `addCorrelatedColumn` deduplication, both working on resolved nodes only. The tests that covered only the `REPLACE` rewrite (04696, 05037, 05055, 05317 and the `REPLACE` sections of 04326) are removed together with it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Analyzer/Resolve/QueryAnalyzer.cpp
`GROUPING SETS (..., ())` without aggregate functions now emits the row of the empty grouping set (ClickHouse@1d48d4bf5f0), so the `GROUPING SETS` cases of these tests return one more row. Also sort the `max(if(1, 2, a.k))` case so its mixed `NULL`/non-`NULL` rows are deterministic. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=104350&sha=eb39e6c568d7cfcae17752cabbdaf7b7729bf2af&name_0=PR&name_1=Fast%20test PR: ClickHouse#104350 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
The Fast test failure in @novikd: as of |
…lated references `applyGroupByUseNullsToExpression` reset `is_aggregate_or_grouping_argument` when the walk crossed into an outer query for a correlated expression, but then OR-ed the outer query's expression stack into it again. When the correlated subquery is reached through an alias first resolved inside an aggregate (e.g. `covarSamp(x, y)` in a GROUP BY key branch that `if` with a constant condition drops), the correlated column stayed non-Nullable while decorrelation feeds it the outer post-aggregation Nullable column, causing the `Bad cast from type DB::ColumnNullable to DB::ColumnVector<char8_t>` exception. On `master` the aggregate guard was bypassed for correlated columns; restore that by not accumulating the flag after crossing into an outer query. Found by the stress test (amd_msan): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=104350&sha=f82eb9ed827f7642fb775c668fce124fe12f0878&name_0=PR&name_1=Stress%20test%20%28amd_msan%29 PR: ClickHouse#104350 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Status as of 2026-10-20:
|
…group_by_use_nulls` `applyGroupByUseNullsToExpression` called `convertToNullable` on a correlated `FunctionNode` that matched an outer `GROUP BY` key. Such a function is recomputed inside the subquery from its (already wrapped) arguments, and `FunctionNode::convertToNullable` only changes its declared result type, so for `isNull`, `ifNull`, `assumeNotNull` and similar the executed type did not match: `LOGICAL_ERROR: Unexpected return type from isNull. Expected Nullable(UInt8). Got UInt8`. Wrap only correlated columns in place, as before this PR. Replace the `EXPLAIN QUERY TREE` pin of a Nullable correlated `modulo` (that query is not executable anyway: the planner cannot find the correlated column `c` in the aggregated header) with execution regressions for `isNull`, `ifNull` and `assumeNotNull`. PR: ClickHouse#104350 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @novikd, your change request (2026-09-08: "It is incorrect to touch |
|
Dear @novikd, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
| -- (Nullable) arguments, so it must keep the result type inferred by the function. Declaring it Nullable | ||
| -- raised "Unexpected return type from isNull. Expected Nullable(UInt8). Got UInt8". | ||
| SELECT '-- correlated function matching an outer key keeps its own result type ---'; | ||
| SELECT a, (SELECT isNull(a)) |
There was a problem hiding this comment.
[Major] The new 04210 regression does not pass on the current head. Running the complete file with this PR's Fast test binary, both via clickhouse local and against a server, stops at this query with AMBIGUOUS_COLUMN_NAME: isNull(__table3.a) appears as both UInt8 and Nullable(UInt8) in the same block. The earlier Unexpected return type issue is fixed, but this is a different failure later in planning.
The reference also disagrees with earlier successful queries: the correlated tuple subtotal is now (1,NULL) rather than \N, and the last row of the 109509 function-argument case is 2 rather than \N. Running against base ed426a200679a7512bad37c61b17f49876fa3f8c reproduces these same failures, so these are existing behaviors exposed by the new fixture, rather than regressions introduced by this helper.
Please make the complete new test execute and match its reference on the current head while retaining its regression coverage. Update expectations where the behavior has intentionally changed; if the remaining planner exception is deferred, link its tracking issue and retain an executable regression for the type-handling fix.
There was a problem hiding this comment.
The AMBIGUOUS_COLUMN_NAME in 04210 on 20dfe0b comes from #129971, which reached this branch with the master merge: it joins the decorrelated subquery on a null-safe key, and that key's isNull(__table3.a) part takes the name of the outer GROUP BY key. Fix: #132567. The other changed values in 04210 (the subtotals for a NULL outer value) are #129971's intended semantics, so that part of the reference needs updating.
| { | ||
| if (AggregateFunctionFactory::instance().isAggregateFunctionName(func->getFunctionName())) | ||
| if (AggregateFunctionFactory::instance().isAggregateFunctionName(func->getFunctionName()) | ||
| || func->getFunctionName() == "grouping") |
There was a problem hiding this comment.
[Major] The new grouping exclusion misses named lambdas and SQL UDFs because it scans the unresolved call's surface name. For example:
WITH x -> grouping(x) AS g
SELECT * APPLY x -> g(x)
FROM numbers(1)
GROUP BY number WITH ROLLUP
ORDER BY 1
SETTINGS group_by_use_nulls = 1;This throws BAD_ARGUMENTS with GROUPING function argument number is not in GROUP BY keys, whereas direct APPLY x -> grouping(x) and the same named-lambda query with group_by_use_nulls = 0 both return 0, 1. The scan sees only g, so the key becomes Nullable before resolveFunction expands the lambda into grouping. A registered SQL UDF wrapping grouping has the same problem. This also exists in the scalar lambda-call path on the base; the new exclusion leaves that representation of the same operation uncovered.
Please preserve the original key type through callable expansion and add a named-lambda/SQL-UDF regression, or link a tracking issue if that part of the fix is intentionally deferred.
A correlated subquery references an outer column that is a GROUP BY key of an outer query under
group_by_use_nulls = 1withWITH ROLLUP/CUBE/GROUPING SETS. The actual values fed into the inner subquery are post-rollupNullables, but the analyzer used to leave the inner column reference at its non-Nullable type. The planner then built CAST wrappers and aggregate functions with the original signature, and at header inference (after decorrelation replacedPLACEHOLDERnodes withINPUTnodes of the actualNullabletypes) the precomputed wrappers raisedLogical error: 'Bad cast from type DB::ColumnNullable to DB::ColumnVector<...>'.The minimal reproducer from issue #91119 hits
createUInt8ToBoolWrapper:The same surface bug class also appears for plain numeric types (modulo, plus), aggregate functions over correlated outer columns (e.g.
(SELECT anyLastOrDefault(number))), correlatedHAVING/WHEREfilter steps, andNullablesource columns.The root cause is in
QueryAnalyzer::resolveExpressionNode: thenullable_group_by_keyswalk stops at the first enclosingQUERYscope, so the outer scope where the column was defined is never consulted for an inner correlated reference. This change makes the walk continue past the innerQUERYscope when thenodeis a column whose source table expression is registered in a deeper outer scope (i.e. the column is correlated). The aggregate-function exclusion is now evaluated against each scope'sexpressions_in_resolve_process_stack, so an outer scope'snullable_group_by_keysapplies even when the inner subquery is currently inside an inner aggregate (the inner aggregate operates on the outer's already-Nullablevalues).For correlated matches the existing node is mutated in place instead of being replaced with a clone of the GROUP BY key. The same
shared_ptris referenced by the enclosingQueryNode::correlated_columnslist (registered viaaddCorrelatedColumn); cloning would leave the planner'scorrelated_columns_setpointing to the original non-Nullablenode, andPlannerActionsVisitor::visitColumn(which uses type-sensitive equality) would then fail to identify the projected column as correlated and skip thePLACEHOLDERstep that the decorrelation pass replaces.The
SELECT * REPLACE/APPLYbinding issue inWHERE/HAVING/ORDER BYundergroup_by_use_nulls(projection matchers are resolved after the other clauses) is not part of this PR: it exists onmasterindependently and is fixed by #118476. This PR only works on resolved query tree nodes.Related: #118476
Closes #91119.
Closes #106377.
Closes #108931
Closes #109509
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Bad castexception in correlated subqueries that reference an outer column promoted toNullablebygroup_by_use_nulls = 1withGROUP BYWITH ROLLUP/CUBE/GROUPING SETS.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/104350]