Skip to content

Fix exception in IN/NOT IN with LowCardinality column arguments#98443

Merged
alexey-milovidov merged 4 commits intomasterfrom
fix-low-cardinality-in-column
Mar 3, 2026
Merged

Fix exception in IN/NOT IN with LowCardinality column arguments#98443
alexey-milovidov merged 4 commits intomasterfrom
fix-low-cardinality-in-column

Conversation

@alexey-milovidov
Copy link
Member

Summary

  • Fix ILLEGAL_TYPE_OF_ARGUMENT exception when using column IN (other_column) or column NOT IN (other_column) where the left-hand column is LowCardinality(T)
  • The bug was in convertTupleToArray which transforms a IN (b) into has(array(CAST(b, NullableType)), a) — it used makeNullable producing the invalid Nullable(LowCardinality(T)) instead of LowCardinality(Nullable(T))
  • Replaced with makeNullableOrLowCardinalityNullable / isNullableOrLowCardinalityNullable which properly handle the LowCardinality wrapper

Closes #92828

Test plan

  • Added stateless test 04007_low_cardinality_in_column covering LowCardinality(String) and LowCardinality(Bool) with both IN and NOT IN column arguments
  • Verified results match non-LowCardinality equivalents

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix exception "cannot be inside Nullable type" when using IN/NOT IN with LowCardinality column arguments (e.g. a NOT IN (b) where a is LowCardinality(String)).

🤖 Generated with Claude Code

When resolving `column IN (other_column)` expressions, `convertTupleToArray`
wraps the common type in Nullable. For `LowCardinality(T)` types, `makeNullable`
produced the invalid `Nullable(LowCardinality(T))` instead of the correct
`LowCardinality(Nullable(T))`, causing an "cannot be inside Nullable type"
exception.

Use `makeNullableOrLowCardinalityNullable` and
`isNullableOrLowCardinalityNullable` which properly handle the LowCardinality
wrapper.

Closes #92828

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clickhouse-gh
Copy link
Contributor

clickhouse-gh bot commented Mar 1, 2026

Workflow [PR], commit [8b6492f]

Summary:

@clickhouse-gh clickhouse-gh bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 1, 2026
Copy link
Member Author

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Mar 1, 2026
Copy link
Member

@novikd novikd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but the test fails with disabled analyzer

@novikd novikd self-assigned this Mar 2, 2026
@alexey-milovidov alexey-milovidov merged commit a0bde6c into master Mar 3, 2026
148 of 149 checks passed
@alexey-milovidov alexey-milovidov deleted the fix-low-cardinality-in-column branch March 3, 2026 17:41
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LowCardinality bad cast?

3 participants