Repository navigation
Conversation
…tant
`KeyCondition::applyFunctionChainToColumn` strips outer `LowCardinality`
from the result of `func->execute` but not outer `Const`. For partition
expressions whose monotonic function chain collapses to a single constant
value (e.g. `floor(NULL, x)` always yields NULL), `func->execute` returns
`ColumnConst(ColumnNullable(...))` of size 1.
`ColumnConst::isNullable` reports the wrapped column's nullability, so
the `isNullable()` guard accepted the column while the subsequent
`assert_cast<const ColumnNullable &>` aborted the server with:
Bad cast from type DB::ColumnConst to DB::ColumnNullable
(STID: 3520-4237 in the AST fuzzer infra)
Strip the outer `Const` after `convertToFullColumnIfLowCardinality` so
the column shape matches `result_type` and the post-strip invariant
established at the top of the function
(`convertToFullColumnIfConst()->convertToFullColumnIfReplicated()->convertToFullColumnIfSparse()->convertToFullColumnIfLowCardinality()`).
Apply the same defensive unwrap after `castColumnAccurateOrNull` to
cover the structurally identical sibling site — `FunctionCast` wrappers
can also return `ColumnConst` for 1-row inputs by the same mechanism,
so this prevents a class of fuzzer findings rather than just the one
reported.
Closes ClickHouse#104840
|
Pre-PR validation gate (session a) Deterministic repro? ✅ Yes. The b) Root cause explained? ✅ Yes. c) Fix matches root cause? ✅ Yes. Strip the outer d) Test intent preserved? / New test added? ✅ Yes. New stateless test e) Both directions demonstrated? ✅ Yes.
f) Fix is general, not a narrow patch? ✅ Yes.
Tracking task: |
|
cc @alesapin @CurtizJ @KochetovNicolai — could you review this? It fixes a chronic AST-fuzzer |
|
Workflow [PR], commit [00df6f1] Summary: ✅ AI ReviewSummaryThis PR fixes the partition-pruning Final Verdict
|
…ion FAIL
The bugfix-validation framework needs the regression test to FAIL on
master HEAD (status `FAIL`, an output diff vs `.reference`) so that the
inversion logic in `ci/jobs/functional_tests.py` can flip it to `OK`
and report "bug reproduced".
The previous `.sql` form crashed the server on master HEAD via the
`assert_cast<const ColumnNullable &>(ColumnConst &)` abort in
`KeyCondition::applyFunctionChainToColumn`. The test runner then
classified that as `SERVER_DIED`/`ERROR`-shaped failure caught by the
outer hung-check, and the framework refused to invert it ("Failed to
reproduce the bug").
Reshape into a `.sh` test that runs the bug-triggering scenario inside
a `clickhouse-local` subprocess. On master HEAD the subprocess aborts
(SIGABRT, exit 134); the `if` branch is taken and we print `BUG`,
diverging from the `OK` reference -> `FAIL`. On the PR branch the
subprocess succeeds and we print `OK` -> `OK`. The server stays alive
either way, so the framework sees a clean output diff that it can
invert.
Verified locally on debug builds:
* master HEAD KeyCondition.cpp (no fix): `[ FAIL ]`, stdout `BUG`,
server unaffected.
* PR HEAD with fix: `[ OK ]` (5/5 runs).
Bugfix validation CI log:
https://s3.amazonaws.com/clickhouse-test-reports/PRs/104861/42fc1aef6e10b6e9241e54bdebe2ea37c8dd416c/bugfix_validation_functional_tests/job.log
PR: ClickHouse#104861
Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Pushed fix-up Why the previous test didn't drive a
|
LLVM Coverage Report
Changed lines: 100.00% (9/9) · Uncovered code |
The previous `.sql` form relied on `{ serverError ILLEGAL_TYPE_OF_ARGUMENT }`
directives, but on master HEAD (without the fix) the bug-triggering
queries reach the `LOGICAL_ERROR` guard in `ColumnTuple::create` and
abort the server under `abort_on_logical_error = true` (the default
in CI test environments). The bugfix-validation framework saw the
parent server crash as `ERROR` / `SERVER_DIED` and reported "Failed
to reproduce the bug" because that result is not invertible.
This commit wraps the bug-triggering queries in a `.sh` script that
runs each query inside a `clickhouse-local` subprocess. The abort
on master HEAD now stays contained: `clickhouse-local` returns a
non-43 exit code, the script prints `BUG`, the output diff fails,
and the bugfix-validation framework can invert that `FAIL` into a
"bug reproduced" signal. On the PR branch the queries return
`ILLEGAL_TYPE_OF_ARGUMENT` (Code 43) cleanly and the script prints
`OK`.
See PR ClickHouse#104861 for an earlier example of this `.sh` wrapper pattern
for a contained-abort regression test.
Session: cron:clickhouse-ci-task-worker:20260516-114500
|
Backporting, because there are crashes in 26.4. |
Cherry pick #104861 to 26.4: Fix `LOGICAL_ERROR` in partition pruning when chain collapses to constant
…en chain collapses to constant
Backport #104861 to 26.4: Fix `LOGICAL_ERROR` in partition pruning when chain collapses to constant
…pruning when chain collapses to constant
…4861 Backport ClickHouse#104861 to 26.4: Fix `LOGICAL_ERROR` in partition pruning when chain collapses to constant
Fix
LOGICAL_ERROR("Bad cast from typeDB::ColumnConsttoDB::ColumnNullable") in partition pruning forMergeTreetables when the partition expression's monotonic function chain collapses to a single constant value.Root cause
KeyCondition::applyFunctionChainToColumnstrips outerLowCardinalityfrom the result offunc->executebut not outerConst. When the chain collapses to a constant (e.g.floor(NULL, x)always yields NULL),func->executereturnsColumnConst(ColumnNullable(...))of size 1.ColumnConst::isNullablereports the wrapped column's nullability, so the existingisNullable()guard accepts the column while the subsequentassert_cast<const ColumnNullable &>aborts the server.Reproducer (
floor(NULL, toRelativeYearNum(myDay))partition key — taken from the fuzzer report in #104840):Before this PR the
SELECTaborts withBad cast from type DB::ColumnConst to DB::ColumnNullable; after this PR it returns the matching row.Fix
Strip the outer
Constright afterconvertToFullColumnIfLowCardinalityso the column shape stays in sync withresult_typeand with the post-strip invariant established at the top of the function (which already stripsConst,Replicated,Sparse, andLowCardinality).Apply the same defensive unwrap to the sibling
assert_castsite aftercastColumnAccurateOrNull—FunctionCastwrappers can also returnColumnConstfor 1-row inputs by the same mechanism. This prevents a class of fuzzer findings rather than just the one reported.A new stateless regression test
04237_104840_partition_pruner_floor_null_nullable_keyaborts the server on master and passes after the fix.Closes: #104840
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
Bad cast from type DB::ColumnConst to DB::ColumnNullableserver abort during partition pruning forMergeTreetables when the partition expression contains a function chain that collapses to a single constant value (such asfloor(NULL, toRelativeYearNum(...))).Version info
26.5.1.63426.4.3.27