Repository navigation
Conversation
group_by_use_nulls together with GROUPING SETS makes grouping keys
Nullable, but the function_base nodes (plus/bitCount/equals) were resolved
against the original non-nullable types and not re-resolved, leaving a node
whose declared argument/result type is non-nullable while its actual child
column is Nullable.
In the JIT path IFunction::compile's default-implementation-for-nulls
inspects the actual argument and emits a nullable LLVM value { T, i1 },
but CompileDAG::compile labels it with the stale non-nullable
getResultType(). A downstream compiled function (bitCount) then matches the
value to its scalar branch and BitCountImpl<double>::compile aborts with
LOGICAL_ERROR "BitCountImpl compilation expected native integer or
floating-point type" on the struct type. The interpreter re-derives
nullability at runtime and returns the correct NULL row, so the bug is
JIT-only.
Decline to JIT-compile a function node when a non-skipped argument's
declared nullability disagrees with the actual child's nullability, so the
node falls back to the interpreter. This follows the existing
isCompilableFunction bail pattern and cannot change query results.
Found by the AST fuzzer (amd_tsan) on PR ClickHouse#107129, STID 2649-32ef;
reproduces on pure master.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-0:20260611-165800 |
|
cc @novikd @KochetovNicolai — could you review this? It fixes a debug-build server abort ( |
|
Workflow [PR], commit [7459d26] Summary: ✅
AI ReviewSummaryThis PR prevents Missing context / blind spots
Final VerdictStatus: ✅ Approve No code-review changes requested; wait for pending CI to finish before merge. |
The CI old-analyzer stateless job ran this regression test with enable_analyzer=0, where the correlated scalar subquery / QUALIFY / GROUPING SETS query cannot be resolved at all (Code 47 UNKNOWN_IDENTIFIER, "Missing columns: 'number'"). The JIT crash being regressed only exists in the new analyzer's group_by_use_nulls nullable-rewrite path, so the test must always run there. Add SET enable_analyzer = 1; which overrides the runner's session-level injection. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 4/4 (100.00%) | Lost baseline coverage: none · Uncovered code |
Algunenano
left a comment
There was a problem hiding this comment.
Are you sure we are fixing this in the right place? If the function declared a type and then passed a different one that's a bug that needs to be fixed in the function, not in the callee.
|
@Algunenano you're right, thanks. This is a query-tree consistency bug, not a JIT issue. With I'll move the fix to where that inconsistency is produced (re-resolve the function so its declared argument/result types match the Nullable argument) and drop the JIT-side guard. There is already precedent for this concern in the analyzer (the aggregate-function handling around |
|
@Algunenano I traced where the inconsistent type is introduced. It is the planner (decorrelation), not the analyzer, and the subquery is actually consistent in isolation. Evidence for
There is already a rebuild for exactly this Two ways to fix the function:
I lean to (1). Which do you prefer before I implement? |
|
@groeneai Please investigate if this is reported and open an issue if it's not, then involve the experts in the analyzer/planner. They should be the ones deciding how to address this better. And let's close this PR since it turned out to be the wrong way forward |
|
@Algunenano you're right, this is the wrong layer. Closing it. It is already reported: #106377, assigned to the analyzer/planner experts, with @ novikd's diagnosis and a candidate fix in #102597. Same decorrelation type-mismatch you pointed at: decorrelation injects I added our fuzzer reproducer and EXPLAIN traces to #106377 so the experts have the full picture. Closing this PR in favor of that issue. |
Related: #107129 (the AST fuzzer run on that PR surfaced this crash; the crash is a pre-existing trunk bug, not caused by #107129). No related open issue found.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
LOGICAL_ERROR(BitCountImpl compilation expected native integer or floating-point type) and server abort in debug builds when a JIT-compiled expression combinedgroup_by_use_nullswithGROUPING SETS, causing a compilable function to receive aNullableargument that its resolved signature treated as non-nullable.Description
Found by the AST fuzzer (
AST fuzzer (amd_tsan)) on PR #107129, STID 2649-32ef. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107129&sha=123f29e39f974650ddc91f0dd9edc474ea399678&name_0=PR&name_1=AST%20fuzzer%20%28amd_tsan%29 . Reproduces on pure master (no dependency on #107129).Reproducer:
Root cause:
group_by_use_nulls+GROUPING SETSmakes grouping keysNullable, but theplus/bitCount/equalsfunction_basenodes were resolved against the non-nullable types and never re-resolved, so a node ends up with a non-nullable declared argument/result type wired to aNullablechild.IFunction::compile's default-implementation-for-nulls path inspects the actual argument and emits a nullable LLVM value{ double, i1 }, butCompileDAG::compilelabels it with the stale non-nullablegetResultType(). A downstream compiled function (bitCount) then matches the value to the scalarFloat64branch andBitCountImpl<double>::compileaborts on the struct type. The interpreter (compile_expressions = 0) re-derives nullability at runtime and returns the correctNULLrow, so this is JIT-only.Fix: in
isCompilableFunction, decline to JIT-compile a function node when a non-skipped argument's declared (function_base) nullability disagrees with the actual child's nullability, deferring that node to the interpreter. This is the conservativeisCompilableFunctionbail pattern already used for other non-compilable cases and cannot change results (worst case: a rare malformed expression is not JIT-accelerated). Verified the guard is surgical: it fires only for the malformed nodes in the reproducer and not for normally-resolved nullable arguments (JIT output stays bit-identical to the interpreter across the reproducer and 11 variants; existing JIT tests01072_nullable_jit,01852_jit_if,01855_jit_comparison_constant_result,01457_compile_expressions_fuzzer,00745_compile_scalar_subquerystill pass).Question for reviewers: the deeper fix would be in the analyzer, so a
plus(etc.)function_basewired to aNullablechild is re-resolved to a nullable signature rather than left inconsistent, which would also makeCompileDAG's type labelling honest. That has a much wider blast radius. Is the JIT-layer guard here the preferred fix, or would you rather pursue the analyzer-side re-resolution? Happy to follow up either way.Regression test:
tests/queries/0_stateless/04330_jit_nullable_arg_type_mismatch.sql(crashes on master, passes with this change).