Repository navigation
Speed up dictGetDescendants and dictGetChildren for blocks with many parent keys - #131775
Algunenano merged 3 commits into
Conversation
detail::getDescendants reserves its loop-detection set to the block's row count (65409 rows -> 131072 cells, 1 MiB) and clears it after every requested key that has children. HashSet::clear() zeroes the whole buffer, so the cost is (keys with children in the block) x (block size). In tests/performance/hierarchical_dictionaries.xml the 50,000 keys with children are all in the first block: 52 GB of memset per query, 89% of its CPU samples. Use ClearableHashSet, whose clear() bumps a version counter, as arrayUniq and arrayDistinct do for a set reused per row. Measured with perf.py over the unchanged test on release builds of master 6ea176f, 8 pinned cores, both seat orders: the five dictGetDescendants queries go from 0.98-1.04 s to 0.13-0.18 s (ratio 0.134-0.174), the five dictGetHierarchy queries stay at a ratio of 0.975-1.053. dictGetChildren over the same 1M keys: 973 ms -> 79 ms. The cost no longer follows the block size: 959 ms at max_block_size = 65409 vs 232 ms at 8192 before, 98 vs 126 ms after. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reword the loop-set comment: clearing runs only for requested keys that have children. 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; 1 finding) plus my own cold review (1 finding).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261115-100500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261115-084201 |
|
Workflow [PR], commit [a27a9ce] Summary: ✅
AI ReviewSummaryReplacing the temporary loop-detection Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units14 translation units recompiled, 152 s compile time in total, 14 of them have a recent master baseline. |
CI finish ledger - 7df1b6cEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The amd_release shards 1/6 (which ran Session id: cron:our-pr-ci-monitor:20261115-143011 |
Related: #129258
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
dictGetDescendantsanddictGetChildrenare faster when many keys of a block have children: the set that detects loops in the hierarchy no longer zeroes a buffer sized for the whole block once per such key. ThedictGetDescendantsqueries of thehierarchical_dictionariesperformance test run about 6x faster.Description
detail::getDescendants(src/Dictionaries/HierarchyDictionariesUtils.h) keeps a set that detects loops in the hierarchy. It is reserved to the block's row count and cleared after every requested key that has children, andHashSet::clearzeroes the whole buffer: 1 MiB per such key at the default block size. Intests/performance/hierarchical_dictionaries.xmlthe first block holds 50,000 keys with children, so eachdictGetDescendantsquery zeroes 52 GB, and memset takes 89% of its CPU samples. That is why these five queries take 1.1-1.2 s on amd CI and about half that on arm (#129258, long queries).The set is now a
ClearableHashSet, whoseclearis O(1) (a version counter), as inarrayUniqandarrayDistinct. Lookups, inserts, the reserve and the loop handling are unchanged; cells grow from 8 to 16 bytes.Validation on release builds of master with and without the change:
perf.pyover the unchanged test, 8 pinned cores, both seat orders: the fivedictGetDescendantsqueries go from 0.98-1.04 s to 0.13-0.18 s (ratio 0.13-0.17); the ratio of the fivedictGetHierarchyqueries stays at 0.98-1.05.dictGetChildrenover the same 1M keys: 973 ms to 79 ms. One key with 1M descendants, and 950k keys without children: unchanged within noise.dictGetDescendants(all levels, levels 1 and 2) anddictGetChildrenover flat, hashed, hashed with 16 shards and hashed_array dictionaries with self-loops and cycles, at block sizes 1, 7, 1000 and 65409. TheHierarchyDictionariesUtilsgtest and the hierarchical dictionary stateless tests (50 randomized runs each) pass.The performance test is unchanged.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131775]
Version info
26.11.1.2714-master(included in26.11and later)