Repository navigation
Avoid building stream names and substreams cache keys for every block in MergeTreeReaderWide - #124816
Conversation
`MergeTreeReaderWide` computed `IMergeTreeDataPart::getStreamNameForColumn` up to four times per substream on every `readRows` call: building the name with escaping and splitting of nested names, then looking it up in the checksums. The substreams caches were keyed by a string that was also built on every lookup. Now the stream names are memoized for the lifetime of the reader, and the keys of the substreams caches are `SipHash` hashes of the same rendering of the substream path, computed without building the string. With `max_block_size = 1` this was 7-15% of the time of ClickBench queries. Related: #124792 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hashing the key with `SipHash` still took a noticeable time for every lookup. Now the key is hashed with a cheap hash and compared exactly. Also, the stream name computed by the callers is passed to `getStream`, and the element of `avg_value_size_hints` for a stream is remembered, so the callbacks for the size hints don't search the map by name. Related: #124792 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Storages/MergeTree/MergeTreeReaderWide.cpp # src/Storages/MergeTree/MergeTreeReaderWide.h
|
Workflow [PR], commit [2484fda] Summary: ✅
AI ReviewSummaryThis PR memoizes stream-name lookups in Final VerdictStatus: ✅ Approve |
|
📊 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
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes71 object files changed (+23.74 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 units3160 translation units recompiled, 16783 s compile time in total, 3160 of them have a recent master baseline. |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124816&sha=706c1ec64373407746fba9b4110377fdb43ad79a&name_0=PR&name_1=Stateless%20tests%20(arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel) and provide a fix in a separate PR. If the fix is already in progress, link it here.
The I merged master into this branch to refresh CI. |
|
Not caused by this PR. The fix is #123121 (mine, open). The failed run ( |
|
I want to revert this PR. The idea is fine, but the implementation makes the code worse, and the use case does not justify it. The main problem is The rest of the change does not help readability either: a hand-rolled hash, a multimap with manual equality, a mutex and raw pointers into And all of it is for a strange use case. By the numbers in the description the gain exists only with If this speedup is wanted, it should be done properly or not at all. |
…tream-names" This reverts commit 46a479e, reversing changes made to 1e6f88e. The conflicts with the later changes of ClickHouse#127000 to the same code (the cache-key rendering of the SHARED paths of JSON and the sub-column sizes in getAllColumnsSubstreams) are resolved by keeping their behaviour over the pre-ClickHouse#124816 mechanics: stream names built per call and string keys of the substreams caches. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…am cache key Master reverted the change that made `ISerialization::getSubstreamsCacheKeyForStream` return a 128-bit hash (3013a37, the revert of ClickHouse#124816), so the key is a `String` again and `ISerialization::SubstreamsCacheKeyHash` no longer exists. The key is the same injective rendering of the substream path, so every substream still gets its own stream. Co-Authored-By: Claude Opus 5.5 <[email protected]>
MergeTreeReaderWidecomputedIMergeTreeDataPart::getStreamNameForColumnup to four times per substream on everyreadRowscall: in the data getter, again ingetStream, and in both callbacks for the average value size hints. Every computation builds the name (escapeForFileName,Nested::splitName,fmt::format), and then looks it up in thestd::mapof checksums. The substreams caches (ISerialization::SubstreamsCacheandSubstreamsDeserializeStatesCache) were keyed by a string, which was also built for every lookup.Now:
getStream, and the element ofavg_value_size_hintsis remembered.SipHashof exactly the same rendering of the substream path that was used before.SipHashis a streaming hash, so the pieces are fed into it without building the string, and two paths share a cache entry exactly when their rendered strings are equal, as before.getNameForSubstreamPathbecame a template over the sink of the pieces.readRowsno longer destroys the per-column cache entries after every call, only clears them.With
max_block_size = 1the inclusive time ofgetStreamNameForColumnwas 7-15% of ClickBench queries; for Q3 it went from 14% to about 5% (getStreamInfo).Measured on ClickBench
hits(a 1% subset, 1M rows), single-threaded, together with the other PRs for the same issue (#124791): withmax_block_size = 16, queries Q3, Q10, Q19, Q30, Q34 are 13-25% faster; with the defaultmax_block_sizethe times are unchanged.A performance test with small blocks is added.
Related: #124792
Related: #124791
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reduce the per-block overhead of reading
MergeTreetables inWideparts: the names of the column streams and the keys of the substreams caches are no longer built for every block. Queries with small blocks (a lowmax_block_size) became faster.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124816]
Version info
26.10.1.2211-master(included in26.10and later)