Skip to content

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 into
backport/26.4/104861from
cherrypick/26.4/104861
May 17, 2026
Merged

robot-clickhouse-ci-2 merged 4 commits into
backport/26.4/104861from
cherrypick/26.4/104861

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 4 commits May 13, 2026 14:32
…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
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels May 17, 2026
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit 02cdc1a into backport/26.4/104861 May 17, 2026
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/26.4/104861 branch May 17, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants