Skip to content

Fix exception in applyDeterministicDagToColumn with LowCardinality key column - #97669

Closed
alexey-milovidov wants to merge 1 commit into
masterfrom
fix-has-low-cardinality-key-condition
Closed

alexey-milovidov wants to merge 1 commit into
masterfrom
fix-has-low-cardinality-key-condition

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 22, 2026 •

Copy link
Copy Markdown
Member

See #97668.

Summary

  • Fix "Bad cast from ColumnVector<unsigned int> to ColumnLowCardinality" exception in applyDeterministicDagToColumn when has() is used with a LowCardinality column whose ORDER BY key involves a CAST.
  • The ExpressionActions DAG from the key expression retains LowCardinality types, but applyDeterministicDagToColumn strips LowCardinality from the input before executing it, causing a type mismatch.
  • Fix by re-wrapping the column in LowCardinality before executing the DAG when dag.input_type is LowCardinality.

Reproducer found by AST fuzzer:

CREATE TABLE t (d LowCardinality(DateTime('America/New_York')))
ENGINE = MergeTree ORDER BY CAST(d, 'String');

INSERT INTO t VALUES (toDateTime(1730611800, 'America/New_York'));

-- This crashes:
SELECT toUnixTimestamp(d) FROM t WHERE has([toDateTime(1730611800, 'America/New_York')], d);

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97568&sha=9785d6ea5d327f0a7671c45dada310eb44e63044&name_0=PR&name_1=AST%20fuzzer%20%28amd_msan%29
#97568

Test plan

  • Added regression test 03402_has_low_cardinality_key_condition
  • CI green

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...

🤖 Generated with Claude Code

@clickhouse-gh

clickhouse-gh Bot commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [55131b9]

Summary: ⏳

job_name test_name status info comment
AST fuzzer (amd_ubsan) failure
Logical error: Bad cast from type A to B (STID: 0250-3d53) FAIL cidb

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Feb 22, 2026
@ClickHouse ClickHouse deleted a comment from CLAassistant Feb 22, 2026
@alexey-milovidov
alexey-milovidov marked this pull request as draft February 22, 2026 22:03
@alexey-milovidov
alexey-milovidov force-pushed the fix-has-low-cardinality-key-condition branch from f602040 to 17d5c7c Compare February 22, 2026 22:03
…key column

The `ExpressionActions` DAG built from the key expression retains the
original types, which may include LowCardinality. Functions like `CAST`
handle LowCardinality internally and expect to receive LowCardinality
columns. However, `applyDeterministicDagToColumn` strips LowCardinality
from the input column and type before executing the DAG, causing a type
mismatch that leads to "Bad cast from ColumnVector to
ColumnLowCardinality" exception.

Fix by re-wrapping the column in LowCardinality before executing the DAG
when `dag.input_type` has LowCardinality.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97568&sha=9785d6ea5d327f0a7671c45dada310eb44e63044&name_0=PR&name_1=AST%20fuzzer%20%28amd_msan%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants