Repository navigation
Radix partitioned uniqExact for all argument types - #127280
Conversation
The values of up to 16 and of 32 bytes that are unambiguously represented by their bytes are the keys themselves, zero-padded (e.g. `Decimal32`, `DateTime64`, `FixedString(12)`, `UInt256`). The 16-byte values, including `IPv6` and `FixedString(16)`, go through the `mixKey` bijection instead of `SipHash`. The other values are keyed by the 128-bit `SipHash` of `updateHashWithValue`, as in `uniqExact` (e.g. `Tuple`, `Array`, `Map`). The slot hash of the 128-bit keys now multiplies the high half: it keeps the zero padding of a `FixedString(12)` in its top bits, which put all the keys into the same slots. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each block routes only the distinct dictionary values that its rows use (see `getMinimalDictionaryEncodedColumn`), so a shared dictionary larger than the block costs nothing extra. For `LowCardinality(Nullable)` the values are `Nullable` and NULLs are skipped as before. All the argument types are supported now, so `isRadixUniqExactSupported` is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A string of up to 15 bytes is represented by its bytes and its size, a bijection (see `packShortString`), then by `mixKey`, instead of the 128-bit `SipHash`, which cost more than half of the routing of short strings. Their consecutive duplicates are compared inline instead of by `memcmp`. The local set takes the keys of a batch in chunks of its room: only the new keys take room, so with frequent keys, it had no room for the whole batch, and the keys were inserted one by one. `toString(number % 1000)` over 50M rows: 48 ms -> 29 ms (the `count_distinct_optimization` rewrite takes 22 ms). `toUInt32(number % 1000)`: 10 ms -> 8 ms. The ClickBench `COUNT(DISTINCT)` queries are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [ea4cfa3] Summary: ✅
AI ReviewSummaryThis PR extends radix partitioned Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings. |
… ones
The packed short strings and the `SipHash` of the longer strings shared the `UInt128` set without a
discriminator, and `mixKey` is easy to invert, so a long string could have the key of a 15-byte string
(e.g. `long-string-example-494` and `unhex('D7A0004D354CD8BEB38E8080053CB7')` were counted once).
The longer strings now set the top bit of their hash before `mixKey`, which the packed short strings
never have.
Also reduce the data of the tests 10x: `05447_radix_uniq_exact_low_cardinality` ran longer than
180 s in the flaky check with ASan.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes6 object files changed (+93.83 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 units9 translation units recompiled, 33 s compile time in total, 9 of them have a recent master baseline. |
The keys of the strings of 16 bytes or more went through `mixKey`, two more `intHash64` per row, to keep them apart from the keys of the short strings. The first round of `mixKey` now leaves the top bit alone, so the keys of the short strings keep it clear, and the `SipHash` of the longer strings only sets it. 20-byte strings are 1.15x faster in one thread; the long strings are marked unlikely, so that the loop of the short strings keeps its registers. The `MergeTree` queries of `05447_radix_uniq_exact_low_cardinality` computed two aggregates, which the radix partitioning does not handle, so they are split and their pipeline is checked. The performance test covers the long strings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… test, and parallel replicas in `05447` The performance test had only the types that the radix partitioning handled before, so the comparison showed nothing of the new ones. It now has `Tuple`, `Array`, `Decimal128`, short strings and `LowCardinality(String)` from a `MergeTree` table, with fewer queries on the old types (8 in total). With parallel replicas, the replicas aggregate the table of `05447_radix_uniq_exact_low_cardinality` and their states are merged, which does not use the radix partitioning, so its check of the pipeline failed. The test disables them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
0fce803
The radix partitioned
uniqExacthandled only some argument types. The others fell back to the ordinaryuniqExact, which was much slower and often lost to thecount_distinct_optimizationrewrite. Now every type is supported:Decimal*,DateTime64,Time64,Int256/UInt256,FixedString(N ≤ 16)). The 16-byte ones, includingIPv6andFixedString(16), go through a bijection instead ofSipHash.SipHash.Tuple,Array,Map,Variant,JSON, otherFixedStringwidths) use the 128-bitSipHashofupdateHashWithValue, asuniqExactdoes.LowCardinalityroutes only the distinct dictionary values each block uses.The local set also takes a batch of keys in chunks of its free room, instead of inserting them one by one when the whole batch might not fit. This speeds up low cardinality inputs of every type.
50M rows, median ms (radix /
count_distinct_optimizationrewrite / plainuniqExact):Tuple(UInt64, UInt8)Array(UInt64)Map(UInt64, UInt64)Decimal32(1M distinct)LowCardinality(String)on MergeTree (100k distinct in the first column)String(toString(number % 1000))Existing types are unchanged on ClickBench
COUNT(DISTINCT)(UserID,WatchID,SearchPhrase,URL,Title,Referer,ClientIP,EventTime).IPv6andFixedString(16)get 1.2x faster.At low cardinality on
String, the rewrite is still a bit faster (22 ms vs 29). ItsGROUP BYkeeps short strings inline with a 32-bit CRC32 hash, while radix needs an exact 128-bit key per row.Related: #123552
Related: #127252
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The radix partitioned
uniqExact(andcount(DISTINCT)) now supports arguments of every type, includingDecimal,DateTime64, big integers,FixedString,Tuple,Array,MapandLowCardinality. It is 2-20x faster than before for these types, and faster for short strings.Workflow [PR]
Sync PR [sync-upstream/pr/127280]
Version info
26.11.1.1243-master(included in26.11and later)