Skip to content

Cherry pick #117018 to 26.10: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries) - #130459

Merged
robot-ch-test-poll merged 17 commits into
backport/26.10/117018from
cherrypick/26.10/117018
Nov 11, 2026
Merged

robot-ch-test-poll merged 17 commits into
backport/26.10/117018from
cherrypick/26.10/117018

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #117018

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.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

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

raimannma and others added 16 commits August 29, 2026 07:54
Since the column-native set builder (#113051), every member of a `Tuple`
collection on the right-hand side of `IN` is converted with a separate
`castColumnAccurateOrNull`, which builds a CAST function per member. The
existing batch path only applied when every member had the same exact
type, which is never the case for a literal list crossing 255 or 65535
(`UInt8`/`UInt16`/`UInt32` literals). A direct dictionary sends
`WHERE id IN (...)` with up to 65409 literals per block, so `dictGet`
became up to 2x slower.

Group the members by type and cast every native-number group once,
preserving the member order; other groups keep the per-member path.
The multi-key path converts key by key over the tuples still alive, so
the per-tuple short-circuit of the previous loop is preserved. Also let
`convertColumnToTypeOrNull` return the value untouched when the source
and target types are equal, as `convertFieldToType` does.

Local timings (release build, 50k-row source, best of 5):
simple key `value_int` 75k lookups: 0.332 s -> 0.161 s;
complex key `value_int` 75k lookups: 0.827 s -> 0.669 s.

Closes: #115803
Related: #113051
Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=29cf83dac1355231265f4893603d31dfcfb577f1&name_0=MasterCI&name_1=Performance%20Comparison%20%28arm_release%2C%20release_base%2C%203%2F6%29

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015vE8zKDB5gVhhkVvCHtXh8
Move the fix one layer down: `convertColumnToTypeOrNull` evaluates a
native-number-to-native-number conversion directly with
`accurate::convertNumeric` instead of building and executing a CAST
function per single-row call. This makes the original per-member loop
in the set builder fast on its own, so the type grouping in `SetUtils`
is reverted, and every other caller of `convertColumnToType` (e.g. the
`values` table function) benefits as well.

Local timings (release build): simple key `value_int` 75k lookups
0.332 s -> 0.183 s; complex key `value_int` 75k lookups 0.827 s -> 0.726 s.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015vE8zKDB5gVhhkVvCHtXh8
`convert_inexact_floats` only relaxes the exactness check when the target is
a floating-point type - `convertNumericTypeImpl` computes it as
`strict || !convert_inexact_floats || !is_floating_point<To>`. Skipping the
column-native fast path whenever the flag is set therefore disabled it for
conversions the flag does not affect at all, and `TableFunctionValues` passes
`convert_inexact_floats = true` for every single conversion it makes, so the
`values` table function kept going through the `Field` path.

Evaluate the same predicate per target type inside the fast path instead,
selecting the strict or non-strict `accurate::convertNumeric`, and thread
`strict` through for it. Conversions to an integer target stay exact in every
mode; a floating-point target rounds under the flag, as `CAST` does.

Also drop the `const` from the returned `full` local, which made the
`arm_tidy` build fail with `performance-no-automatic-move`.

The new `strict` / `convert_inexact_floats` combinations are pinned by
`gtest_convert_column_to_type` against `convertFieldToType`.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117018&sha=dfdfa4f675cf3216786573ffed3d879e7cf65334&name_0=PR
PR: #117018

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQHGp9bMyRAi9w5TyBpGU4
…Type

`IDataType::equals` ignores custom names, so `Bool` compares equal to its
storage type `UInt8` (and `Nullable(Bool)` to `Nullable(UInt8)`, and so on).
The identity fast path therefore aliased a `Bool` value byte-for-byte instead
of normalizing it through `retagBoolInField` as the `Field` path does:
`values('x UInt8', reinterpret(toUInt8(2), 'Bool'))` returned 2 instead of 1,
and the strict `IN` set builder accepted 2 as a `Bool` member.

Mirror the identity check of `CAST` and also require the custom names to
match, by comparing the full type names so nested custom names are covered.
Add a functional test with the pre-change results.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ed29xEavfAZtWSkjA9jr8K
…nToType

A `Bool` column is a plain `ColumnUInt8` and may hold a raw byte such as 2
(e.g. from `reinterpret`). The `Field` path normalizes it to `true` through
`retagBoolInField`, but the identity fast path returned the column untouched
for identical types, so `values('x Bool', reinterpret(toUInt8(2), 'Bool'))`
stored the raw byte and `x = true` became false; the same held for identical
`Nullable(Bool)`, `Array(Bool)`, `Tuple(Bool)` and `Map(..., Bool)` shapes.

Exclude any type containing `Bool` anywhere in its tree from the no-op, as
`CAST` treats `Bool -> Bool` as `UInt8 -> Bool` normalization rather than
identity. Extend the test with these cases, reference taken before the change.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ed29xEavfAZtWSkjA9jr8K
…geneous-literals-batch

# Conflicts:
#	src/Interpreters/convertColumnToType.cpp
…ToType

`containsBool` walks the type tree with `forEachChild`, but `DataTypeDynamic` exposes no
children and `DataTypeObject::forEachChild` visits typed paths only, so a `Bool` payload
inside `Dynamic` or `JSON` was invisible and a same-type conversion returned the column
untouched. Treat both as possibly containing `Bool`, so they keep going through the `Field`
path that normalizes a raw `Bool` byte, as before the identity fast path was added.

Adds a unit test that builds a `ColumnDynamic` holding a raw `Bool` byte 2 and checks that
`Dynamic -> Dynamic` conversion yields a value equal to a genuine `true`.

Addresses #117018 (comment)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VkdUU1A38U3kGxPcZdUVP8
…geneous-literals-batch

# Conflicts:
#	src/Interpreters/convertColumnToType.cpp
#	src/Interpreters/convertColumnToType.h
#	src/Interpreters/tests/gtest_convert_column_to_type.cpp
…terals-batch

Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
@robot-clickhouse robot-clickhouse 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 labels Nov 10, 2026
Conflict resolution: 26.10 lacks the wide-integer, `Decimal` and `Date`/`DateTime`
column-native fast paths that exist on master, so only the changes of the original
PR are applied on top of the release version: `tryConvertNumericColumnNative` keeps
the release's native-number-only filter but converts the scalar directly with
`accurate::convertNumeric` (taking `strict` and serving `convert_inexact_floats`),
and `containsBool` plus the identity short-circuit are added. In the gtest, the
`Decimal128` rescaling cases (which pin master-only `Decimal` fast-path behavior)
are dropped; the `convert_inexact_floats` matrix and identity cases are kept.
@robot-ch-test-poll
robot-ch-test-poll merged commit fa52309 into backport/26.10/117018 Nov 11, 2026
2 checks passed
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.10/117018 branch November 11, 2026 14:08
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!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants