Repository navigation
Do not instantiate the range_hashed dictionary lookup for every attribute type - #126978
Conversation
…bute type `getItemsImpl` and `getItemsShortCircuitImpl` ran the whole key + range lookup (key extraction, hash map find, `IntervalTree::find` with the min/max callback) inside the `callOnRangeType` lambda, so the lookup loop was instantiated for 2 key types x 2 nullability x 25 attribute types x 20 range column types: 4000 copies, plus 8800 `IntervalTree` callback copies, although nothing in the lookup depends on the attribute type. Move the lookup into one non-template member `findValueIndexes`, which stores the value index of each key (or `value_index_not_found`), and make the two getItems functions plain copy loops over these indexes. Measured on 2ad32ae (local builds of the CI AMD_MSAN / AMD_BINARY cmake lines; the local MSan base matches the CI artifact within 0.01 MiB): - amd_msan: .text 1650.25 -> 1602.68 MiB (-47.57), 2 GiB reach headroom 208.48 -> 257.73 MiB. - release without LTO: .text 470.90 -> 464.49 MiB (-6.41). - The 12 RangeHashedDictionary TUs compile in 132 s instead of 700 s (MSan) and 100 s instead of 368 s (release), summed per-file time. A pinned release benchmark (15 rounds with an A/A control) shows no slowdown for simple and complex-key dictGet, lazy-default dictGetOrDefault and a Nullable(String) attribute. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ound row from a default The found row's value is NULL and the old default `intDiv(NULL, id)` was NULL too, so the case passed whether or not the found row was masked; with `intDiv(1, id)` the found row must stay NULL without evaluating `intDiv(1, 0)`, and the missing row gets 1. 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 (2 nits).
Severity: ❌ blocker / |
Pre-PR validation (a-i)
|
|
Workflow [PR], commit [5641e6a] Summary: ✅
AI ReviewSummaryThe PR extracts the shared key and range lookup into Missing context / blind spots
Final Verdict✅ Approve. No new inline findings; normal CI completion remains pending. |
|
cc @Algunenano @vdimir, could you review this and add the |
CI finish ledger - 74714a5Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Session id: cron:our-pr-ci-monitor:20261020-193013 |
|
Fixing PR for |
|
|
||
| SELECT 'Range hashed dictionary'; | ||
| SELECT dictGetOrDefault('range_hashed_dictionary', 'val', id, toDate('2023-01-02'), intDiv(NULL, id)) | ||
| SELECT dictGetOrDefault('range_hashed_dictionary', 'val', id, toDate('2023-01-02'), intDiv(1, id)) |
There was a problem hiding this comment.
@groeneai I don't like this. Please add a extend the test instead of changing it, otherwise we can think that the behaviour was changed by this PR which would be wrong
There was a problem hiding this comment.
Done in 5641e6a: the intDiv(NULL, id) query and its reference are back as on master, and the intDiv(1, id) query is added after it as a new case.
… and add the intDiv(1, id) one next to it The behaviour is unchanged, so the existing query and reference stay as on master; the added query uses `intDiv(1, id)` as the lazy default, which throws if it is evaluated for the found row `id = 0`, and returns 1 for the missing row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
|
| Binary | Master | PR | Δ |
|---|---|---|---|
programs/clickhouse-stripped |
782.65 MiB | 760.60 MiB | -22.05 MiB (-2.82%) |
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.
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 ⚠️
16 object files changed (-28.77 MiB total), 0 added.
| Object file | Master | PR | Δ |
|---|---|---|---|
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryGetItemsShortCircuitIm… |
4.07 MiB | 74.84 KiB | -4.00 MiB (-98.21%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryGetItemsImplOthers.cpp… |
4.06 MiB | 76.46 KiB | -3.99 MiB (-98.16%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryGetItemsShortCircuitIm… |
3.34 MiB | 42.80 KiB | -3.30 MiB (-98.75%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryGetItemsShortCircuitIm… |
3.34 MiB | 42.71 KiB | -3.30 MiB (-98.75%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryGetItemsImplInt.cpp.o |
3.33 MiB | 41.47 KiB | -3.29 MiB (-98.78%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryGetItemsImplUInt.cpp.o |
3.33 MiB | 41.36 KiB | -3.29 MiB (-98.79%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryGetItemsShortCircuitIm… |
2.82 MiB | 38.36 KiB | -2.78 MiB (-98.67%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryGetItemsImplDecimal.cp… |
2.81 MiB | 37.47 KiB | -2.77 MiB (-98.70%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryGetItemsShortCircuitIm… |
1.19 MiB | 23.20 KiB | -1.17 MiB (-98.10%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryGetItemsImplFloat.cpp.o |
1.19 MiB | 21.37 KiB | -1.17 MiB (-98.24%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionaryComplex.cpp.o |
1.56 MiB | 1.72 MiB | +160.24 KiB (+10.03%) |
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/RangeHashedDictionarySimple.cpp.o |
1.47 MiB | 1.60 MiB | +129.93 KiB (+8.63%) |
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
20 translation units recompiled, 105 s compile time in total, 20 of them have a recent master baseline.
Median compile-time ratio to the baselines is ×0.44 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -107.7 s (-51%) in total before that adjustment.
| Translation unit | Master | PR | Δ vs median |
|---|---|---|---|
src/Dictionaries/RangeHashedDictionaryComplex.cpp |
17.2 s | 18.3 s | +10.7 s (+143%) |
src/Dictionaries/RangeHashedDictionarySimple.cpp |
16.5 s | 17.9 s | +10.7 s (+149%) |
src/Dictionaries/registerRangeHashedDictionary.cpp |
8.1 s | 8.7 s | +5.1 s (+146%) |
Slowest changed entities of src/Dictionaries/RangeHashedDictionaryComplex.cpp:
- InstantiateFunction
DB::callOnIndexAndDataType<void, (lambda at /ClickHouse/src/Dictionaries/RangeHashedDictionary.h:30…: +2.7 s - InstantiateFunction
DB::callOnIndexAndDataType<void, (lambda at /ClickHouse/src/Dictionaries/RangeHashedDictionary.h:30…: -1.0 s (-100%) - InstantiateFunction
DB::impl::callOnRangeType<(lambda at /ClickHouse/src/Dictionaries/RangeHashedDictionary.h:952:56)>: +1.1 s
Slowest changed entities of src/Dictionaries/RangeHashedDictionarySimple.cpp:
- InstantiateFunction
DB::callOnIndexAndDataType<void, (lambda at /ClickHouse/src/Dictionaries/RangeHashedDictionary.h:30…: +2.7 s - InstantiateFunction
DB::callOnIndexAndDataType<void, (lambda at /ClickHouse/src/Dictionaries/RangeHashedDictionary.h:30…: -0.9 s (-100%) - InstantiateFunction
DB::impl::callOnRangeType<(lambda at /ClickHouse/src/Dictionaries/RangeHashedDictionary.h:952:56)>: +1.2 s
Symbol sizes
| Binary | Symbol | Master | PR | Δ |
|---|---|---|---|---|
programs/clickhouse-keeper |
COW<DB::IColumn>::immutable_ptr<DB::IColumn> DB::FunctionNumericIndexedVectorHelper<DB::FunctionNum… |
86.01 KiB | removed | -86.01 KiB (-100.00%) |
programs/clickhouse-keeper |
COW<DB::IColumn>::immutable_ptr<DB::IColumn> DB::FunctionNumericIndexedVectorHelper<DB::FunctionNum… |
85.73 KiB | removed | -85.73 KiB (-100.00%) |
programs/clickhouse |
COW<DB::IColumn>::immutable_ptr<DB::IColumn> DB::FunctionNumericIndexedVectorHelper<DB::FunctionNum… |
85.55 KiB | removed | -85.55 KiB (-100.00%) |
programs/clickhouse |
COW<DB::IColumn>::immutable_ptr<DB::IColumn> DB::FunctionNumericIndexedVectorHelper<DB::FunctionNum… |
85.18 KiB | removed | -85.18 KiB (-100.00%) |
CI finish ledger - 5641e6aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261021-160007 |
On the azure lane the default MergeTree storage policy is a write-through filesystem cache. The test's valid native-protocol INSERT writes a one-row part, and every file of that part reserves cache space under the cache's priority write lock. In Stateless tests (arm_asan_ubsan, azure, parallel) on PR ClickHouse#126978 that INSERT spent 34.07 s of 34.43 s waiting on the lock (FilesystemCachePriorityWriteLockMicroseconds), so the server's correct End of stream arrived 4.4 s after the python client's hard-coded 30 s socket timeout and the test failed with TimeoutError in readStrict. The storage is incidental to a native-protocol LowCardinality test, so pin the table to storage_policy = 'default' (the local disk on every lane). The part write stays MergeTree, the 30 s hang guard and the .reference are unchanged. Same shape as ClickHouse#122567 (04344) and ClickHouse#126252 (04949) for this lock. Co-Authored-By: Claude Opus 5.5 <[email protected]>
d879e48
Related: #126314
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
range_hashedandcomplex_key_range_hasheddictionary lookup is no longer instantiated for every attribute type, which removes about 47 MiB of code from the MSan build and about 6 MiB from a release build.Description
RangeHashedDictionary::getItemsImplandgetItemsShortCircuitImplran the key + range lookup (hash map find andIntervalTree::find) inside thecallOnRangeTypelambda. So the loop was compiled for every key type, nullability, attribute type and range column type, 2000 copies in each of the two functions under MSan plus 8800IntervalTreecallback copies, although nothing in it depends on the attribute type. The lookup is now one non-template member,findValueIndexes, returning each key's value index; the two getItems functions copy values by these indexes.Built locally on
2ad32ae943cfewith the CIamd_msanandamd_binarycmake lines (the MSan base matches the CI artifact within 0.01 MiB):.text.textRangeHashedDictionary{Simple,Complex}.cppand the 10RangeHashedDictionaryGetItems*.cpp, MSan / releaseValidation: an equivalence probe (simple and complex keys, 11 attribute types, 9 range types,
min/maxstrategy, open bounds, everydictGet*variant,query_count) gives byte-identical output on master and on this branch (debug and MSan), and each of three mutations of the new code changes it. Of 295 dictionary stateless tests the same 278 pass on master and here, and the 15range_hashedtests pass 50 of 50 randomized runs. A pinned release benchmark (15 rounds, A/A control) shows no slowdown for simple and complex-keydictGet, lazy-defaultdictGetOrDefaultand aNullable(String)attribute.02950_dictionary_short_circuitgains arange_hashedquery withintDiv(1, id)as the lazy default, which throws if evaluated for the found rowid = 0.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126978]
Version info
26.11.1.501-master(included in26.11and later)