Skip to content

Find a LowCardinality needle equal to the type's default value - #114624

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-lowcardinality-default-value-needle
Aug 21, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-lowcardinality-default-value-needle

Conversation

@groeneai

@groeneai groeneai commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

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):

Fixes has, indexOf, countEqual, mapContainsKey, mapContainsValue and Map subscript returning "not found" for a constant LowCardinality needle equal to the element type's default value, such as an empty String or a zero number.

Description

The problem. A constant needle equal to the element type's default value is never found in an Array(LowCardinality(T)) or a Map with a LowCardinality key. No exception, so a WHERE on such a predicate silently drops rows:

CREATE TABLE t (a Array(LowCardinality(String))) ENGINE = Memory;
INSERT INTO t VALUES (['', 'a']);
SELECT has(a, '') FROM t;   -- 0, expected 1

Likewise for 0 over the numeric types, a NUL-padded FixedString and the 1970-01-01 Date, while m[''] returns '' instead of the stored value. Any non-default needle is correct. Reproduces on 26.5 to 26.7.

Root cause. A LowCardinality dictionary reserves prefix slots for the default and NULL values, and ReverseIndex is built with num_prefix_rows_to_skip, so the reserved slot is never indexed. ColumnUnique::uniqueInsertData compensates for that on the write path; the read path had no counterpart.

The change. ColumnUnique::getOrFindValueIndex now performs the same default-slot match as the write path. ReverseIndex is untouched, so no write behaviour moves.

That slot becoming reachable brings two equality details. The lookup casts the constant into the element type without reporting loss, so UInt64(256) arrived as UInt8(0) and would match the default; that slot now answers only if the element type can represent the constant. And a dictionary can hold -0.0 and 0.0 as separate entries while the shortcut has room for one index, so a zero constant over a float element type is left to the value-comparing path, as indexOfAssumeSorted already is.

The new test covers both call sites. Lookup timing is unchanged.

Overlap with #112953. That open PR declines this same shortcut for every float element type, subsuming the float-zero decline here, and the two conflict textually; whichever merges second should keep the broader decline and drop this one, collapsing the duplicated representability predicate to one copy. Non-float types are independent of it.

Version info

  • Backported to: 26.7.5.10, 26.6.4.7, 26.5.8.14, 26.3.23.7, 25.8.33.6

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-follow-up PR origin: groeneai's own out-of-scope finding during its PR work pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

6 participants