Repository navigation
Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries) - #117018
Conversation
Since the column-native set builder (ClickHouse#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: ClickHouse#115803 Related: ClickHouse#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
|
Workflow [PR], commit [e21abca] Summary: ✅
AI ReviewSummaryPR #117018 replaces per-scalar Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings or changes to existing review threads are required. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
`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: ClickHouse#117018 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VQHGp9bMyRAi9w5TyBpGU4
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+224.98 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline. |
…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 ClickHouse#117018 (comment) Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01VkdUU1A38U3kGxPcZdUVP8
Cherry pick #117018 to 26.8: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
…olumnToType (fix dictGet regression with direct dictionaries)
Resolve conflicts in `convertColumnToType.cpp`, `convertColumnToType.h` and `gtest_convert_column_to_type.cpp`. The 26.9 release lacks the master-only column-native paths (wide integers, `Decimal` targets, `Date`/`DateTime`) and `DataTypes/TypeTree.h`, so the backport keeps the release code and applies only the change of #117018: - `tryConvertNumericColumnNative` converts native numbers directly with `accurate::convertNumeric` (taking `strict` and `convert_inexact_floats`) instead of building a CAST per value; the scope stays native numbers only. - identical types not containing `Bool` are returned untouched; `containsBool` is implemented with `IDataType::forEachChild` instead of `anyInTypeTree`. - gtest cases added by #117018 that apply to native numbers and identity, and the `Dynamic` raw-`Bool` test, are kept. Both translation units pass a `-fsyntax-only` check against the release tree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #117018 to 26.9: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
…olumnToType (fix dictGet regression with direct dictionaries)
Cherry pick #117018 to 26.10: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
…ColumnToType (fix dictGet regression with direct dictionaries)
Backport #117018 to 26.8: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
Backport #117018 to 26.10: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
Backport #117018 to 26.9: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
…olumnToType (fix dictGet regression with direct dictionaries)
…olumnToType (fix dictGet regression with direct dictionaries)
…ColumnToType (fix dictGet regression with direct dictionaries)
Closes: #115803
Related: #113051
Since #113051, every member of the right-hand side of
INis converted withconvertColumnToTypeOrNull, whose native-number path built and executed a CAST function per single-row conversion. A direct dictionary sendsWHERE `id` IN (...)with up to 65409 literals of mixed types (UInt8/UInt16/UInt32) per block, so the existing homogeneous batch path did not apply anddictGetbecame up to 2x slower. NowconvertColumnToTypeOrNullconverts native scalars directly withaccurate::convertNumeric(the same conversionconvertFieldToTypeuses, pinned bygtest_convert_column_to_type) and returns the value untouched when the types are equal; this also benefits every other caller, such as thevaluestable function.Local timings (release build,
tests/performance/direct_dictionary.xmlsetup): simple keyvalue_int, 75k lookups: 0.332 s -> 0.183 s; complex keyvalue_int, 75k lookups: 0.827 s -> 0.726 s.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
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a performance regression of
dictGetwith direct dictionaries (and ofx IN (<many literals>)in general): constant literals are converted to the column type directly instead of through a CAST function per value. Closes #115803.Workflow [PR]
Sync PR [sync-upstream/pr/117018]
Version info
26.11.1.1645-master(included in26.11and later)