Repository navigation
Conversation
|
Workflow [PR], commit [525e442] Summary: ❌
AI ReviewSummaryThis PR reroutes single-key Findings
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 188/238 (78.99%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: Release-transition baseline: compared against the last 26.8 master because no 26.9 master baseline exists at or before the trusted base-commit anchor. This PR adds dedicated wide-integer (UInt128/UInt256) LowCardinality GROUP BY aggregation methods plus a raw-index fast path and cache-size guard; the merge and two-level refactors are behavior-preserving for existing narrow and string LowCardinality keys. Standard ClickBench and TPC-H queries do not group by wide LowCardinality integer keys, so none exercise the changed hot path — every directional flag was downgraded as thin-base variance, most of it landing inside master's current variance bands. The dramatic TPC-H results (×20.5 and ×6.9 faster) come from a 2-config base that captured slow master runs, not a real speedup, and the +60.0% TPC-H Q17 swing is on extremely noisy measurements. The two borderline ClickBench aggregations (Q28, Q32) remain not_sure; there is no credible regression attributable to this change. clickbenchFlagged queries (11 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_officialFlagged queries (4 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
Build profile diff (arm_release)Comparing Binary sizes
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. Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Interpreters/Aggregator.cpp.o |
20.33 MiB | 23.07 MiB | +2.75 MiB (+13.52%) |
src/CMakeFiles/dbms.dir/Interpreters/AdaptiveAggregationKernels.cpp.o |
1.82 MiB | 1.93 MiB | +103.98 KiB (+5.57%) |
src/CMakeFiles/dbms.dir/Processors/Transforms/LimitByTransform.cpp.o |
1.16 MiB | 1.23 MiB | +75.23 KiB (+6.33%) |
src/CMakeFiles/dbms.dir/Processors/Transforms/NegativeLimitByTransform.cpp.o |
893.45 KiB | 949.22 KiB | +55.77 KiB (+6.24%) |
src/CMakeFiles/dbms.dir/Interpreters/AggregatedDataVariants.cpp.o |
724.85 KiB | 751.69 KiB | +26.84 KiB (+3.70%) |
src/CMakeFiles/dbms.dir/Interpreters/AggregationMethod.cpp.o |
422.50 KiB | 441.55 KiB | +19.05 KiB (+4.51%) |
737 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
127 translation units recompiled, 1368 s compile time in total, 127 of them have a recent master baseline.
994cdaf to
9a3c36d
Compare
| if (size_of_field == 16) | ||
| return Type::low_cardinality_key128; | ||
| if (size_of_field == 32) | ||
| return Type::low_cardinality_key256; |
There was a problem hiding this comment.
These new returns change LowCardinality(Nullable(UInt128)) / LowCardinality(Nullable(UInt256)) from the old nullable_serialized path to low_cardinality_key128 / low_cardinality_key256. That loses an existing external-aggregation safeguard: Aggregator::mergeBlocks upgrades nullable_serialized to nullable_serialized_hash64, but it has no corresponding *_hash64 remap for any low-cardinality numeric method (see src/Interpreters/Aggregator.cpp, around the APPLY_FOR_VARIANTS_THAT_MAY_USE_BETTER_HASH_FUNCTION block).
So once max_bytes_before_external_group_by spills, wide nullable LC keys now fall back to the CRC32-backed map in the merge stage, which is exactly the path the merge-side comment says needs a stronger hash for very large key counts. Please either add *_hash64 counterparts/remapping for these methods, or keep the nullable 128/256 LC path on nullable_serialized until the external-merge case is covered.
There was a problem hiding this comment.
I received the same remark from AI review; I think we can assume that low cardinality actually means low cardinality and 32-bit hash is enough.
|
|
9a3c36d to
34fce08
Compare
|
I added another commit, which gives (on top of the previous one):
|
dabb32b to
1f5ed40
Compare
|
Some numbers from the latest iteration in a sister PR: #114993 (comment). |
1f5ed40 to
defce26
Compare
|
Same as with #114993 and #115925, this too conflicted with #96630. cc @thevar1able |
defce26 to
80006c9
Compare
|
Updated to not balloon |
This is simply expanding what is done for narrower integers to wider ones. Comparing `column_low_cardinality_key_holder` to the previous commit: | Key type | Encoding | Before CPU time | After CPU time | Reduction | Speedup | |-----------|----------|----------------:|---------------:|----------:|--------:| | `UInt8` | Plain | 320,240 ns | 321,169 ns | -0.3% | 1.00x | | `UInt8` | LC | 1,366,296 ns | 1,369,728 ns | -0.3% | 1.00x | | `UInt16` | Plain | 320,863 ns | 322,198 ns | -0.4% | 1.00x | | `UInt16` | LC | 1,391,415 ns | 1,377,083 ns | 1.0% | 1.01x | | `UInt32` | Plain | 320,757 ns | 321,323 ns | -0.2% | 1.00x | | `UInt32` | LC | 1,388,380 ns | 1,385,711 ns | 0.2% | 1.00x | | `UInt64` | Plain | 326,842 ns | 325,383 ns | 0.4% | 1.00x | | `UInt64` | LC | 1,381,219 ns | 1,440,143 ns | -4.3% | 0.96x | | `UInt128` | Plain | 1,012,926 ns | 911,887 ns | 10.0% | 1.11x | | `UInt128` | LC | 8,019,216 ns | 1,452,770 ns | 81.9% | 5.52x | | `UInt256` | Plain | 8,149,345 ns | 8,132,693 ns | 0.2% | 1.00x | | `UInt256` | LC | 11,576,753 ns | 1,498,433 ns | 87.1% | 7.73x | For end-to-end benchmark in `group_by_integer_key_width.xml`: | Grouping key | Before median | After median | Reduction | Speedup | |-------------------------------|--------------:|-------------:|----------:|--------:| | `LowCardinality(UInt64)` | 2.0680 s | 2.1344 s | -3.2% | 0.97x | | `UInt64` | 0.6938 s | 0.6905 s | 0.5% | 1.00x | | `LowCardinality(UInt128)` | 2.8588 s | 2.5819 s | 9.7% | 1.11x | | `UInt128` | 1.0269 s | 1.0140 s | 1.3% | 1.01x | | `LowCardinality(UInt256)` | 3.3996 s | 2.9630 s | 12.8% | 1.15x | | `UInt256` | 1.7643 s | 1.6781 s | 4.9% | 1.05x | There's ~5% noise level if you look at the unaffected paths. There's now also a test to ensure that the right aggregation is used.
For UInt128 and UInt256 dictionary keys, cache the raw index-data pointer when the aggregation state is constructed. `getIndexAt` then reads the UInt8/UInt16/UInt32/UInt64 index directly with unalignedLoad avoiding repeated `IColumn` -> `ColumnVector` -> `PODArray` access. After decoding an index, emplaceKey and findKey pass that dictionary position directly to the base method. Previously, cache misses called getKeyHolder, which decoded the same index a second time. The raw-pointer path is compile-time restricted to wide numeric keys. Narrow numeric and string keys retain the original implementation because the unrestricted version regressed their microbenchmarks by 5–8%. Results: * LC UInt128 key holder: 10.9% faster. * LC UInt256 key holder: 13.5% faster. * Narrow LC keys: neutral. * End-to-end LC UInt128 aggregation: 2.5910 -> 2.5093 seconds, 3.15% faster.
Compare the single-column LowCardinality aggregation method with the packed-key method for shared UInt128 and UInt256 dictionaries. Sweep dictionary size and active cardinality to identify where full-dictionary mapped and visit caches stop paying for themselves. Extend the SQL performance test with sparse shared-dictionary aggregation using one and eight workers to cover end-to-end latency and memory scaling.
HashMethodSingleLowCardinalityColumn allocates about 9 bytes per dictionary entry for its mapped and visit caches. For sparse wide dictionaries, this can consume tens of MiB per aggregation state. Limit these caches to 32 MiB for UInt128 and UInt256 keys. For larger dictionaries, hash values directly without initializing the dense caches or the shared-dictionary hash. Dispatch between cached and uncached implementations once per hashing state to avoid adding a branch to the per-row aggregation path. Extend the benchmark to report which path is selected.
Add focused benchmarks for `getIndexAt` across all index widths and for processing large shared dictionaries through one or 64 independent aggregation states. Cover sparse and dense active dictionaries for `UInt128` and `UInt256`, and report index width, state count, dictionary size, and cache usage.
`HashMethodSingleLowCardinalityColumn::getIndexAt` selected the index width for every processed row. Dispatch `UInt8`, `UInt16`, `UInt32`, or `UInt64` once per hashing state alongside the dictionary-cache decision. Update `ReadSharedDictionaryIndexes` to measure the dispatched typed reader. Standalone index reads remained flat because the simple loop was already unswitched by the compiler. For 64 aggregation states with a large uncached dictionary, the `UInt128` benchmark moved from 68.64 to 58.62 ms, or 14.6% faster. The `UInt256` benchmark moved from 95.38 to 80.38 ms, or 15.7% faster. `group_by_integer_key_width` remained neutral for wide keys, within -1.3% to +1.1%, while `LowCardinality(UInt64)` improved by 5.8%.
80006c9 to
525e442
Compare
| all_keys_are_const, | ||
| overflow_row); | ||
| }; | ||
| ColumnsHashing::dispatchLowCardinalityDictionaryCache(state, execute); |
There was a problem hiding this comment.
The new dispatchLowCardinalityDictionaryCache wiring here only covers the baseline / merge / bucket-selector loops. The default adaptive frozen path still constructs typename LocalMethod::StateNoCache and then drives it directly through getKeyHolder in src/Interpreters/AdaptiveAggregationKernels.cpp (for example at lines 352, 433, 527, and 594), so once a wide shared LowCardinality(UInt128/UInt256) aggregation freezes it never reaches UncachedUInt32State.
That leaves large dictionaries above the 32 MiB cache cutoff on the old per-row size_of_index_type dispatch for the rest of the query, which means this PR's last optimization does not apply to one of the main GROUP BY execution modes. Please route the adaptive frozen kernels through the same helper, or add an equivalent typed-index dispatch there, and cover it with a focused adaptive perf case.
|
This PR can be whittled down quite a bit if we land #115925 first. I'm marking it as draft for now. |


This is simply expanding what is done for narrower integers to wider ones.
Comparing
column_low_cardinality_key_holderto the previous commit:UInt8UInt8UInt16UInt16UInt32UInt32UInt64UInt64UInt128UInt128UInt256UInt256For end-to-end benchmark in
group_by_integer_key_width.xml:LowCardinality(UInt64)UInt64LowCardinality(UInt128)UInt128LowCardinality(UInt256)UInt256There's ~5% noise level if you look at the unaffected paths.
There's now also a test to ensure that the right aggregation is used.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Optimize aggregations of LowCardinality of 128 and 256 bit integers.
Workflow [PR]
Sync PR [sync-upstream/pr/114982]