Skip to content

Cherry pick #114624 to 25.8: Find a LowCardinality needle equal to the type's default value - #115709

Merged
robot-clickhouse-ci-1 merged 3 commits into
backport/25.8/114624from
cherrypick/25.8/114624
Aug 22, 2026
Merged

robot-clickhouse-ci-1 merged 3 commits into
backport/25.8/114624from
cherrypick/25.8/114624

Conversation

@robot-ch-test-poll4

Copy link
Copy Markdown
Contributor

Original pull-request #114624

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 2 commits August 13, 2026 10:41
has, indexOf and countEqual over Array(LowCardinality(T)) compare dictionary
indexes, so they first resolve the constant needle to an index. That lookup went
through the dictionary's reverse index, which does not contain the reserved
prefix slots, so a needle equal to the element type's default value resolved to
nothing and every row answered "not found" even when the array held that value.
Map(LowCardinality(K), V) key lookups and mapContainsValue share the helper and
answered the same way.

Match the default slot explicitly in getOrFindValueIndex, which is the read path
that the write path (which folds a default element onto that slot) already
assumed.

Answering from the default slot requires the constant to be representable in the
element type, because the cast that brings the needle into the element type
narrows without reporting loss: UInt64(256) arrives as UInt8(0) and would
otherwise match a UInt8 array's default entry. The guard therefore asks whether
the element type can represent the value, by comparing the constant against its
own cast image in the type the two types compare through. A round trip back into
the needle's type would answer a different and wrong question for a pair that
compares through a common type rather than by narrowing: Enum8 -> FixedString
pads on the way out and rejects that padding on the way back, so a value the
element type holds exactly would read as lost and a present element would be
reported missing. Pairs with no common type only compare as numbers, which is
the narrowing case, so there the needle's own type is where they meet.

A float zero is left to the value-comparing path: -0.0 and 0.0 are equal but
occupy two byte-distinct dictionary entries, and one index cannot denote both.
The needle types this decline names are the ones that can reach the site. IPv4 is
also admitted beside a float element, but an IPv4 needle throws NOT_IMPLEMENTED
in the cast before the lookup is reached, unchanged by this commit.
…alue-needle

Find a LowCardinality needle equal to the type's default value
@robot-ch-test-poll4 robot-ch-test-poll4 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 Aug 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

All three conflicting cherry-picks in this wave (25.8, 26.3, 26.5) fail for one shared reason: src/Functions/LowCardinalityExecutionHelpers.h does not exist on those branches, and it carries 95 of the 99 added source lines. It is present on 26.6 and 26.7 (blob be0cae0c), which is exactly the clean/conflicting split. It arrived on master in d911d9c1ce74 and 7613471e2b9c, neither backported.

One correction to my description on #114624, which said the bug reproduces on 26.5 to 26.7. It reproduces on all five active release branches. The merged test is self-oracling, each row printing the LowCardinality answer beside the same query over a plain array, so it runs directly against each release binary from builds.clickhouse.com. On 25.8.32.4, 26.3.21.6, 26.5.8.8, 26.6.4.6 and 26.7.5.9 alike:

has(CAST(['', 'a'], 'Array(LowCardinality(String))'), '')  ->  0
has(CAST(['', 'a'], 'Array(String)'), '')                  ->  1

So closing the older three leaves the silent wrong result in 25.8, 26.3 and 26.5.

I am not hand-resolving these, per the standing no-manual-backport rule. Flagging the measurement so the disposition is an informed one.

Resolve the `modify/delete` conflict on `src/Functions/LowCardinalityExecutionHelpers.h`: that header
does not exist on `25.8`, where the constant-needle dictionary lookup still lives inline in
`FunctionArrayIndex::executeArrayLowCardinality` in `src/Functions/array/arrayIndex.h`.

Drop the header and port `isConstantCastDecline` and `targetTypeRepresentsValue` into a new
`ArrayIndexLowCardinalityHelpers` namespace in `arrayIndex.h`, and guard the inline lookup with
`find_in_dictionary`, matching the resolutions of the sibling backports #115710 (26.3) and #115711 (26.5).
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Resolved the conflict: src/Functions/LowCardinalityExecutionHelpers.h does not exist on 25.8, so the cherry-pick hit a modify/delete. On this branch the constant-needle dictionary lookup still lives inline in FunctionArrayIndex::executeArrayLowCardinality in src/Functions/array/arrayIndex.h, so I dropped the header and ported isConstantCastDecline and targetTypeRepresentsValue into a new ArrayIndexLowCardinalityHelpers namespace there, wrapping the inline lookup in find_in_dictionary. ColumnUnique.h and the two test files merged cleanly, and the net diff against the base branch is exactly the four files of #114624.

Same resolution as the sibling backports #115710 (26.3) and #115711 (26.5). Verified with a single-TU -fsyntax-only compile of src/Functions/array/has.cpp (only pre-existing float-conversion warnings). The PR is now MERGEABLE / CLEAN; CI will run on the downstream backport pull request.

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