Skip to content

Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries) - #117018

Merged
alexey-milovidov merged 15 commits into
ClickHouse:masterfrom
raimannma:fix-in-set-heterogeneous-literals-batch
Nov 8, 2026
Merged

alexey-milovidov merged 15 commits into
ClickHouse:masterfrom
raimannma:fix-in-set-heterogeneous-literals-batch

Conversation

@raimannma

@raimannma raimannma commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #115803
Related: #113051

Since #113051, every member of the right-hand side of IN is converted with convertColumnToTypeOrNull, whose native-number path built and executed a CAST function per single-row conversion. A direct dictionary sends WHERE `id` IN (...) with up to 65409 literals of mixed types (UInt8/UInt16/UInt32) per block, so the existing homogeneous batch path did not apply and dictGet became up to 2x slower. Now convertColumnToTypeOrNull converts native scalars directly with accurate::convertNumeric (the same conversion convertFieldToType uses, pinned by gtest_convert_column_to_type) and returns the value untouched when the types are equal; this also benefits every other caller, such as the values table function.

Local timings (release build, tests/performance/direct_dictionary.xml setup): simple key value_int, 75k lookups: 0.332 s -> 0.183 s; complex key value_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):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed a performance regression of dictGet with direct dictionaries (and of x 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

  • Merged into: 26.11.1.1645-master (included in 26.11 and later)

raimannma and others added 2 commits August 29, 2026 07:54
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
@raimannma raimannma changed the title Batch-convert heterogeneously typed IN set members Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries) Aug 29, 2026
@m-selmi m-selmi added the can be tested Allows running workflows for external contributors label Sep 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e21abca]

Summary: ✅


AI Review

Summary

PR #117018 replaces per-scalar CAST construction with direct accurate::convertNumeric calls and adds a same-type shortcut while retaining normalization for Bool carriers. Reviewed head e21abca9ffb5b7641d53e0b4704abddf51347c66, the complete diff, surrounding conversion code, consumers, and all prior discussion. No actionable findings remain. The supplied direct_dictionary measurements support the performance claim; the current Fast test report confirms that 05059_convert_column_to_type_bool_identity passes.

Missing context / blind spots
  • ⚠️ No local build or executable is available, so tests and performance measurements were not independently rerun. Validation uses source tracing, the supplied before/after timings, and the current CI report. Executing the conversion unit tests would close the remaining runtime verification gap.
Final Verdict

Status: ✅ Approve. No new inline findings or changes to existing review threads are required.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 39 queries analysed

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
  • StressHouse run: 10c35193-8221-44dc-86f9-3b816e62a28c
  • MIRAI run: c8d11d6d-84fc-4eb2-96ab-c9ebd084f783
  • PR check IDs:
    • clickbench_176398_1789403386
    • clickbench_176404_1789403386
    • clickbench_176410_1789403386
    • tpch_adapted_1_official_176420_1789403386
    • tpch_adapted_1_official_176432_1789403386
    • tpch_adapted_1_official_176469_1789403386

`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
@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e21abca9f with master 7b5f2bf32 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

4 object files changed (+224.98 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Interpreters/convertColumnToType.cpp.o 186.07 KiB 411.05 KiB +224.98 KiB (+120.92%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline.

Job report

…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
raimannma and others added 2 commits September 2, 2026 20:26
…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
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 4, 2026
…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
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 8, 2026
Merged via the queue into ClickHouse:master with commit 2ec0318 Nov 8, 2026
187 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 8, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 10, 2026
robot-ch-test-poll added a commit that referenced this pull request Nov 11, 2026
Cherry pick #117018 to 26.8: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
robot-clickhouse added a commit that referenced this pull request Nov 11, 2026
…olumnToType (fix dictGet regression with direct dictionaries)
alexey-milovidov added a commit that referenced this pull request Nov 11, 2026
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]>
robot-ch-test-poll added a commit that referenced this pull request Nov 11, 2026
Cherry pick #117018 to 26.9: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
robot-clickhouse added a commit that referenced this pull request Nov 11, 2026
…olumnToType (fix dictGet regression with direct dictionaries)
robot-ch-test-poll added a commit that referenced this pull request Nov 11, 2026
Cherry pick #117018 to 26.10: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
robot-clickhouse added a commit that referenced this pull request Nov 11, 2026
…ColumnToType (fix dictGet regression with direct dictionaries)
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 11, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 11, 2026
Backport #117018 to 26.8: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
clickhouse-gh Bot added a commit that referenced this pull request Nov 11, 2026
Backport #117018 to 26.10: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
clickhouse-gh Bot added a commit that referenced this pull request Nov 11, 2026
Backport #117018 to 26.9: Convert native scalars directly in convertColumnToType (fix dictGet regression with direct dictionaries)
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…olumnToType (fix dictGet regression with direct dictionaries)
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…olumnToType (fix dictGet regression with direct dictionaries)
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…ColumnToType (fix dictGet regression with direct dictionaries)
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 comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. external Author is not a member of the ClickHouse organization pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dictGet with direct dictionaries is up to 2x slower after column-native IN/set constant handling

8 participants