Repository navigation
Deserialize complex dictionary keys in the reading streams - #123883
alexey-milovidov merged 2 commits into
Conversation
`read` of complex-key `hashed`, `hashed_array` and `range_hashed` dictionaries deserialized all keys into columns on the calling thread before any stream started, and every block then cut its range out of those columns. For a large dictionary this serial loop is a large part of a full scan. Pass the serialized keys to `DictionarySourceCoordinator` instead. Each block deserializes its own range of keys in the stream that reads it, so the work runs in parallel, the per-block copy of the key columns is gone, and a scan with `LIMIT` deserializes only the blocks it reads. Blocks keep the same rows, columns and `DictionaryBlockNumber`. The serialized keys point into the dictionary's arenas, and the coordinator holds the dictionary, which is immutable after loading. `CacheDictionary` keeps deserializing eagerly: its keys are only valid under the storage lock. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mory A full scan of a `hashed`, `hashed_array` or `range_hashed` dictionary with 32 MiB of complex keys now runs under `max_memory_usage = '16Mi'`. Before the per-block key deserialization, `read` materialized every key on the query's thread first and the same queries failed with `MEMORY_LIMIT_EXCEEDED`, so the test fails if the eager path comes back. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 rounds, 1 finding) plus my own review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261004-165600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261004-164400 |
|
Workflow [PR], commit [12df8fd] Summary: ✅
AI ReviewSummaryThis PR moves complex-key deserialization for Missing context / blind spots
Final Verdict
LLVM Coverage ReportMeasured on commit 12df8fd.
Changed lines: Changed C/C++ lines covered: 48/48 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units30 translation units recompiled, 335 s compile time in total, 30 of them have a recent master baseline. |
|
📊 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
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A full scan of a complex-key
hashed,sparse_hashed,hashed_arrayorrange_hasheddictionary (SELECT ... FROM <dictionary>or thedictionarytable function) is faster: each reading stream now deserializes only the keys of its own block instead of one thread deserializing all keys before reading starts. A scan withLIMITdeserializes only the blocks it reads. A full scan also no longer keeps all deserialized keys in memory at once.Description
Related: #119118
Failing job: Performance Comparison (arm_release, master_head, 4/6) on #119118,
hashed_dictionary #11(SELECT * FROM complex_key_hashed_dictionary FORMAT Null) +38.8%.readof a complex-keyhashed,hashed_arrayorrange_hasheddictionary deserialized all keys into columns on the calling thread beforeDictionarySourceCoordinatorstarted any stream, and every block then cut its range out of those columns. For the 5M-key perf dictionaries this serial loop is about half of the query, and the CPU profiles of the slow ARM runs put all of the extra time in it.Now the coordinator gets the serialized keys (views into the dictionary's own arenas, kept alive by the coordinator) and each stream deserializes its own
[start, end)range.CacheDictionaryis unchanged: its keys are only valid under its lock.Measured on x86 with the queries of the existing
tests/performancetests, base vs this PR:hashed_dictionary #11: 0.825 -> 0.608 shashed_array_dictionary #21: 0.498 -> 0.282 srange_hashed_dictionary #9: 0.269 -> 0.140 sSELECT * FROM complex_key_hashed_dictionary LIMIT 1: 0.311 -> 0.080 s#5,hashed_array #10,range_hashed #4: no difference provenI expect the ARM slow builds to lose most of the +38%; this PR's own ARM perf run is the first measurement there.
The new test
05321_complex_key_dictionary_read_per_blockchecks all five complex-key layouts and that a full scan of a dictionary with 32 MiB of keys runs undermax_memory_usage = '16Mi'(on master it fails withMEMORY_LIMIT_EXCEEDED).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123883]
Version info
26.10.1.1551-master(included in26.10and later)