Skip to content

Speed up CAST from Enum to LowCardinality(String) - #127241

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
evillique:enum-to-lowcardinality-cast
Oct 29, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
evillique:enum-to-lowcardinality-cast

Conversation

@evillique

@evillique evillique commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Casting Enum8/Enum16 to LowCardinality(String) copied the name of every row and inserted it into the dictionary with a hash lookup. Now the values are mapped to indexes in a dictionary of all enum names built once per query, and each block inserts only the names it uses. This also covers nested types, such as Map(Enum16(...), Int64) cast to Map(LowCardinality(String), Int64), which #127195 uses to read the keys of system.all_metric_log by name. For an Enum16 with 2000 values, the cast of 40M values on one thread takes 0.22 s instead of 3.7 s (17x faster), and reading a whole map column through such a Merge table takes 0.11 s instead of 0.9 s (8x faster).

Related: #127195

Changelog category (leave one):

  • Performance Improvement

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

Speed up CAST from Enum8 and Enum16 to LowCardinality(String), also inside Map, Array and Tuple.


Workflow [PR]
Sync PR [sync-upstream/pr/127241]

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [81e58ff]

Summary: ✅


AI Review

Summary

Speeds up CAST from Enum8 and Enum16 to LowCardinality(String), including nested types, by mapping values to a prepared dictionary and copying only names used by each block. Both previous findings are fixed in head 81e58ff26100e4f1d96394cd3f5d8b66a802f40c; no unresolved findings remain. All 11 focused checks passed against this head's CI binary, covering the supplied regression output, invalid values, full enum domains, nullable tuples, and parallel nested casts. The reported before/after measurements and added performance test support the claimed improvement.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 21, 2026
Comment thread src/Functions/FunctionsConversion.cpp Resolved
Comment thread src/Functions/FunctionsConversion.cpp Resolved
@thevar1able thevar1able self-assigned this Oct 21, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... label Oct 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 81e58ff26 with master 58077c99f (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 (+53.11 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Functions/FunctionsConversion.cpp.o 24.57 MiB 24.62 MiB +53.10 KiB (+0.21%)

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, 57 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 29, 2026
Merged via the queue into ClickHouse:master with commit 7fc4e86 Oct 29, 2026
178 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 Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants