Skip to content

Read hashed dictionary attributes from typed columns while loading - #130965

Merged
alexey-milovidov merged 2 commits into
masterfrom
hashed-dictionary-typed-load
Nov 12, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
hashed-dictionary-typed-load

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

HashedDictionary::blockToAttributes reads every attribute value through a virtual IColumn::get into a Field, followed by Field::safeGet. When the source column has the attribute type, this change reads the value directly from ColumnVector, ColumnDecimal or ColumnString, using the null map of ColumnNullable for nullable attributes. Other columns still go through Field: Array, Map, Object, and a source that returns a different type than the attribute (e.g. UInt16 for a UInt64 attribute).

Median reload time of a 3M-key simple-key dictionary on Neoverse V2, alternating binaries:

binary SPARSE_HASHED HASHED
CI master f9e6c60e 0.337-0.348 s 0.334-0.340 s
CI build of #119685 (pac-ret) 0.404-0.411 s 0.334-0.338 s
local build, pac-ret, before this change 0.333-0.342 s 0.335-0.341 s
local build, pac-ret, this change 0.202-0.206 s 0.200-0.202 s

This recovers the hashed_dictionary_sharded #3 and hashed_dictionary_load_factor #3 regressions that #119685 shows on ARM. They come from signing these per-row calls in a loop bound by cache misses; the analysis is in #119685 (comment).

The new test compares every kind of attribute with the source table. It covers numbers, UInt256, Decimal, DateTime64, UUID, IPv4, IPv6, String, Nullable with NULLs, Array (the Field path), duplicate keys, HASHED, SPARSE_HASHED, shards, and complex keys. Its reference was produced with the master binary.

Related: #119685

Changelog category (leave one):

  • Performance Improvement

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

Faster loading of HASHED and SPARSE_HASHED dictionaries: attribute values are read directly from the source columns instead of through a generic value per row.

🤖 Generated with Claude Code


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

Version info

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

`HashedDictionary::blockToAttributes` read every attribute value through a
virtual `IColumn::get` into a `Field`, followed by `Field::safeGet`. When the
column has the attribute type, read the value directly from `ColumnVector`,
`ColumnDecimal` or `ColumnString` (with the null map of `ColumnNullable`).
Other columns (`Array`, `Map`, `Object`, or a source returning a different
type than the attribute) still go through `Field`.

Reloading a 3M-key simple-key dictionary takes 0.20 s instead of 0.34 s on
Neoverse V2, for both `HASHED` and `SPARSE_HASHED`. This also recovers the
`hashed_dictionary_sharded` and `hashed_dictionary_load_factor` regressions
of `-mbranch-protection=pac-ret` on ARM, which come from signing these
per-row calls in a loop bound by cache misses.

Related: #119685
Related: #119685 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2030fbe]

Summary: ✅


AI Review

Summary

PR #130965, reviewed at 2030fbe612bc0ce865b67cb0f1153746ac568cd7, speeds up HASHED and SPARSE_HASHED dictionary loading by reading matching typed columns directly while retaining Field conversion for other columns. No actionable findings. The supplied Neoverse V2 measurements support the performance claim, and 05621_hashed_dictionary_load_attribute_types passed in the Fast test. Validation used source inspection and existing CI evidence; no local build or test rerun was performed.

Final Verdict

✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). labels Nov 12, 2026
…efault database

A `QUERY` dictionary source runs in the default database of the session, so
`SELECT * FROM src_05621` failed with `UNKNOWN_TABLE` when the test ran in its
own database, as in the Fast test. Use `TABLE` sources, which take the current
database, and read the ordered rows through a view.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130965&sha=7207c2e2e59e75fd6ab12fe2f37dc11f3e3786ba&name_0=PR&name_1=Fast%20test
#130965

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

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

⚠️ Significant changes: object file sizes.

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 (+1.44 MiB total), 0 added.

Object file Master PR Δ
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/HashedDictionary.cpp.o 19.79 MiB 20.56 MiB +795.55 KiB (+3.93%)
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/SparseHashedDictionary.cpp.o 21.11 MiB 21.78 MiB +683.10 KiB (+3.16%)

711 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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.68, programs/clickhouse-keeper ×0.66 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.8 s 14.2 s +10.3 s (+261%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.4 s +5.2 s (+228%)
Compile time of recompiled translation units

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

Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 86.68 KiB 164.38 KiB +77.69 KiB (+89.63%)

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.

@alexey-milovidov alexey-milovidov self-assigned this Nov 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 12, 2026
Merged via the queue into master with commit 4072329 Nov 12, 2026
203 checks passed
@alexey-milovidov
alexey-milovidov deleted the hashed-dictionary-typed-load branch November 12, 2026 22:12
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). 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.

2 participants