Skip to content

Cherry pick #97831 to 25.11: Fix LOGICAL_ERROR exceptions from recursive convertToFullIfNeeded with LowCardinality inside compound types#97978

Merged
robot-ch-test-poll merged 7 commits intobackport/25.11/97831from
cherrypick/25.11/97831
Feb 25, 2026
Merged

Cherry pick #97831 to 25.11: Fix LOGICAL_ERROR exceptions from recursive convertToFullIfNeeded with LowCardinality inside compound types#97978
robot-ch-test-poll merged 7 commits intobackport/25.11/97831from
cherrypick/25.11/97831

Conversation

@robot-ch-test-poll
Copy link
Copy Markdown
Contributor

Original pull-request #97831

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

Algunenano and others added 7 commits February 24, 2026 11:00
…ntaining `LowCardinality`

Same bug as fixed for `concat` in #97654: `convertToFullIfNeeded` recursively
strips `LowCardinality` from inside compound column types like `Variant`, but
the argument type is not updated to match, so `SerializationLowCardinality`
tries to cast a non-LC column, triggering a LOGICAL_ERROR exception in
debug builds.

Fix by using only top-level column conversions (Const, Sparse, LowCardinality)
instead of the recursive `convertToFullIfNeeded`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ke `Tuple`

`convertToFullIfNeeded` (made recursive in #97493) strips `LowCardinality`
from inner subcolumns of compound types (Tuple, Array, etc.) in
`Set::insertFromColumns`, but `set_elements_types` in `Set::setHeader`
only stripped top-level `LowCardinality`. This created a column/type
mismatch: `ColumnVector<Int8>` in the column vs `LowCardinality(Int8)`
in the type.

When `KeyCondition::tryPrepareSetColumnsForIndex` unpacked the tuple to
build index conditions for `IN` subqueries, `castColumn` tried to
interpret the plain column as `ColumnLowCardinality`, causing a
LOGICAL_ERROR exception in debug builds.

Fix by using `recursiveRemoveLowCardinality` for `set_elements_types` in
both `Set::setHeader` and the static `Set::getElementTypes`, matching
what `convertToFullIfNeeded` does to columns.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97831&sha=6f56284303c16ecc5f5a437491c661d5019f2977&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…variant

Regression test for #97847:
`Dynamic` column with `LowCardinality` variant and `enable_join_runtime_filters`
caused LOGICAL_ERROR "Bad cast from type DB::ColumnVector<int> to
DB::ColumnLowCardinality" because `Set` stored columns with inner
`LowCardinality` stripped but `set_elements_types` still contained it inside
the `Dynamic` type. Already fixed by the previous commit.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…al corruption

`convertToFullIfNeeded` recursively strips `LowCardinality` from subcolumns,
including variant columns inside `ColumnDynamic`. But it cannot update
`ColumnDynamic::variant_info` type metadata, creating a mismatch: variant
columns have LC stripped from data while `variant_info` still references LC
types. This caused LOGICAL_ERROR in `Set::appendSetElements` when
`ColumnDynamic::insertRangeFrom` tried to serialize values using LC
serialization against non-LC column data.

Fix: override `convertToFullIfNeeded` in `ColumnDynamic` to return itself
without recursing into subcolumns. Dynamic is a self-contained typed container
that manages its own variant types.

Also add `max_threads=1` to the test for issue #97847 to reliably trigger the
runtime filter code path that exercises this bug.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…/type mismatches

Same issue as `ColumnDynamic`: `convertToFullIfNeeded` recursively strips
`LowCardinality` from `ColumnVariant`'s internal variant sub-columns, but
cannot update the corresponding `DataTypeVariant` (which sorts variants by
name). This creates column/type position mismatches that cause LOGICAL_ERROR
in `KeyCondition::tryPrepareSetColumnsForIndex` when casting set elements
for index conditions.

Fix: override `convertToFullIfNeeded` in `ColumnVariant` to return itself
without recursing into sub-columns, matching the approach for `ColumnDynamic`.

Closes #97854

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ormat-variant-low-cardinality

Fix LOGICAL_ERROR exceptions from recursive `convertToFullIfNeeded` with `LowCardinality` inside compound types
@robot-ch-test-poll robot-ch-test-poll 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-critical-bugfix labels Feb 25, 2026
@robot-ch-test-poll robot-ch-test-poll merged commit e634329 into backport/25.11/97831 Feb 25, 2026
137 of 140 checks passed
@robot-ch-test-poll robot-ch-test-poll deleted the cherrypick/25.11/97831 branch February 25, 2026 16:38
@clickhouse-gh clickhouse-gh bot added the ready-for-backport PR is eligible for backporting (merged 7+ days ago, not reverted) label Mar 27, 2026
@maxknv maxknv removed the ready-for-backport PR is eligible for backporting (merged 7+ days ago, not reverted) label Mar 27, 2026
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-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants