Repository navigation
Cherry pick #104861 to 26.4: Fix LOGICAL_ERROR in partition pruning when chain collapses to constant - #105177
Merged
robot-clickhouse-ci-2 merged 4 commits intoMay 17, 2026
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 #104840
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: #104861
Co-Authored-By: Claude Opus 4.7 <[email protected]>
…-keycondition Fix `LOGICAL_ERROR` in partition pruning when chain collapses to constant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #104861
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job