Repository navigation
Cherry pick #117018 to 26.8: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries) - #130457
Merged
robot-ch-test-poll merged 17 commits intoNov 11, 2026
Conversation
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
…geneous-literals-batch
…geneous-literals-batch
…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
…geneous-literals-batch
…geneous-literals-batch
…geneous-literals-batch
…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)
Resolve conflicts in `convertColumnToType` by adapting the change to the 26.8 tree, which lacks the master-only prerequisites (`DataTypes/TypeTree.h`, the wide-integer fast path, the `strict` parameter of `tryConvertNumericColumnNative`): - `tryConvertNumericColumnNative` now converts native numbers directly via `accurate::convertNumeric` instead of building a CAST, takes `strict`, and serves `convert_inexact_floats` with the same exactness predicate as `convertNumericTypeImpl`. - The identity short-circuit for equal types not containing `Bool` is added; `containsBool` uses the recursive `IDataType::forEachChild` instead of `anyInTypeTree`. - The `DynamicHoldingRawBoolIsNormalized` gtest is dropped: on 26.8 `ColumnVariant::get` erases the `Bool` tag, so the `Field` path cannot normalize a raw `Bool` inside `Dynamic` (unchanged pre-existing behavior; the identity path is still skipped for it). The stateless test output was checked against `clickhouse/clickhouse-server:26.8`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job