Repository navigation
Conversation
|
Workflow [PR], commit [bf15783] Summary: ❌
AI ReviewSummaryThis PR rewrites PR Metadata
Findings
Tests
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 718/756 (94.97%) · Uncovered code |
42ca1ed to
a9b9e7b
Compare
|
📊 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 is a targeted optimization of LowCardinality column merging (cross-dictionary index translation plus a shared-dictionary fast path in insertRangeFrom) and an ARRAY JOIN hash-map reserve cache, and it ships its own dedicated perf test for exactly that path. Neither ClickBench (integer/string aggregation, no ARRAY JOIN) nor the adapted TPC-H set (joins on native types) exercises the changed code, so none of the flagged deltas are plausibly caused by this change. The apparent wins trace to thin base samples (only 2 base builds): several base medians sit above master's current variance band while the source medians sit inside it, and the TPC-H ×20.1/×6.9 'improvements' come with master bands that span the entire measured range (42-1044 ms and 67-554 ms). All flagged regressions and improvements are downgraded to not_sure; ClickBench Q13 was correctly left as no_change. clickbenchFlagged queries (9 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 (5 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
|
a9b9e7b to
bcae8c4
Compare
|
WARNING: STALE, see #114870 (comment). I amended the commits with the fair suggestion from #114870 (comment) (measured as 402x regression locally). New results are below (empty destination is measuring hashing now, not just cheap aliasing).
Re-measuring the SQL tests as they were affected (it's slightly worse, but still better than the baseline):
I also rebased to pick up #114872 to unblock builds. |
bcae8c4 to
93af56b
Compare
|
This build timed out, but it was still marked successful: That doesn't feel right. Not sure if it's intentional. |
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/Columns/ColumnUnique.cpp.o |
2.93 MiB | 4.68 MiB | +1.75 MiB (+59.77%) |
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
1191 translation units recompiled, 9297 s compile time in total, 1191 of them have a recent master baseline.
Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +507.9 s (+6%) in total before that adjustment.
| Translation unit | Master | PR | Δ vs median |
|---|---|---|---|
src/Columns/ColumnUnique.cpp |
8.4 s | 15.4 s | +6.5 s (+73%) |
c2d9aac to
c127da4
Compare
|
Comparing baseline vs this + #114982 + #114993 shows modest improvements. This is the query, two runs each: SELECT *
FROM r0.profiles_v4_replica
WHERE (timestamp >= '2026-08-18 00:00:00') AND (timestamp < '2026-08-19 00:00:00')
ORDER BY
serviceName ASC,
profileType ASC,
label_app_name ASC,
label_instance ASC,
timestamp ASC
FORMAT `Null`
SETTINGS max_threads = 64, read_in_order_use_buffering = 1, max_memory_usage_for_user = 160000000000Baseline:
Patched:
Diff (zoomed in a bit more, red = added, green = removed):
That's about 6% improvement in the runtime. |
c127da4 to
a4de03e
Compare
|
WARNING: STALE, see #114870 (comment). I combed through the profile (better screenshots in #114993 (comment)), and I found some more optimizations. I'm calling it v3. Two key improvements:
C++:
SQL:
|
c92d73e to
4650350
Compare
4650350 to
a74e796
Compare
|
I updated with a v4 with C++:
SQL:
|
a74e796 to
cdabfbb
Compare
This adds a benchmark query to exercise the problematic path. It also adds a bunch of C++ benchmarks: * Sparse indices * Empty destination with a non-minimal source dictionary * Empty destination with a minimal source dictionary * Tiny range from an oversized dictionary followed by hashing * Disjoint dictionaries * Partially overlapping dictionaries * Fully overlapping dictionaries * Same dictionary fastpath * Dense dictionary control Plus some correctness C++ tests that will be expanded in following commits.
Each source index now performs exactly one `HashMap::emplace`. A newly seen source index is assigned its compact index immediately and is appended to the compact-to-source mapping in the first-seen order. The input index array is also rewritten in the same pass. Additionally, the old sparse mapper always: * Copied the entire input index array * Rewrote all the indexes * Scanned everything to verify Tha latter is an expensive correctness check that doesn't need to exist in a normal release build, so it is now guarded for debug/sanitizers.
Add coverage for dictionary sharing, CoW behavior, nullable dictionaries, and zero-length range insertions. Update the benchmark to exercise the existing shared-dictionary fast path.
cdabfbb to
847c6c0
Compare
|
I rebased and took advantage of #115961 here. It gave us faster
That's a whopping 800x improvement for Otherwise it's within the noise at ±3% (including the SQL bench). |
* Dense source-index ranges retain the previous gather-based implementation. * Sparse ranges compact the referenced source positions in first-seen order, then translate only those distinct positions directly into the destination dictionary. Source key columns are no longer gathered into a temporary column on this path. * If every position in the range is distinct, the translated indexes are returned directly and the final expansion gather is skipped. * Source index columns are dispatched as `UInt8`, `UInt16`, `UInt32`, or `UInt64` without converting their storage. `IColumnUnique` now exposes `uniqueInsertRangeFromDictionary`, with the typed implementation in `ColumnUnique`. It reads keys at supplied source-dictionary positions, inserts or finds them through the destination reverse index, and returns destination indexes in a width selected from a checked upper bound on the resulting dictionary size. The implementation handles nullable values, nested defaults, and canonical NaN insertion consistently with the existing dictionary insertion behavior, updates the null mask on exit, and checks that each produced index fits the selected destination type.
Benchmarks appear to be within the noise.
…x checks | Benchmark group | Improvement | |-----------------------------------------|------------:| | Empty destination, different dictionary | 3.5–6.3% | | Non-empty, disjoint dictionaries | 4.4–9.9% | | Non-empty, fully overlapping | 6.4–6.9% | | Non-empty, partially overlapping | 6.6–7.8% |
Instead of growing the hashmap for each block, remember how big it was before. * MapSparseOnly: 42.6% faster /1, 21.5% faster /2, 2.3% slower /4. * End-to-end /1: 4.5–11.7% faster. * End-to-end /2: 7.7–12.4% faster. * End-to-end /4: effectively flat (−1.1% to +0.2%).
Same as the previous commit: * Empty destination /1: 58.3% faster * /2: 14.4% faster * /4: 16.4% faster
`uniqueInsertRangeFromDictionary` receives distinct source dictionary positions. For empty non-floating numeric destinations, append these values directly and translate null/default positions structurally instead of building and probing a `ReverseIndex`. Keep the reverse index lazy so later insertions build it from the populated dictionary. Retain the existing path for non-empty destinations, floating- point dictionaries, and already-built indexes. Results: * Empty destination: 25–43% faster * Ordered merge with disjoint IDs: 6.8% faster * Ordered merge with overlapping IDs: 7.4% faster
847c6c0 to
bf15783
Compare
|
This will need another rebase after #116637. |
|
In #117123 I added parallelism instead, which cuts latency much deeper. There's some synergy, but parallelism alone is a much bigger bang for the buck for a pure ordered select. |





I'm using ClickHouse to store continuous profiling data. ClickHouse itself is subject to said continuous profiling.
There are some bits that I found to be slower than I would've expected, for example this part:
The optimizations here are very much AI assisted, based on continuous profiling data. The added benchmarks were used as a guiding star. Each optimization step is a separate commit that can be measured with benchmarks from the first one.
Here are the benchmarks measuring CPU time in ms (WARNING: STALE, see #114870 (comment)):
MapSparseOnly/1MapSparseOnly/2MapSparseOnly/4EmptyDestinationDifferentDictionary/1EmptyDestinationDifferentDictionary/2EmptyDestinationDifferentDictionary/4NonEmptyDisjointDictionaries/1NonEmptyDisjointDictionaries/2NonEmptyDisjointDictionaries/4NonEmptyFullyOverlappingDictionaries/1NonEmptyFullyOverlappingDictionaries/2NonEmptyFullyOverlappingDictionaries/4NonEmptyPartiallyOverlapping/1NonEmptyPartiallyOverlapping/2NonEmptyPartiallyOverlapping/4SameDictionary/1SameDictionary/2SameDictionary/4SmallDenseDictionaryFor the last step we went through a few iterations to land on something that does not regress partial overlaps:
Disjoint/1Disjoint/2Disjoint/4Fully overlapping/1Fully overlapping/2Fully overlapping/4Partially overlapping/1Partially overlapping/2Partially overlapping/4You can see that the wins here are not amazing compared to the rest (just 8%), and there's a fair bit of code. I would understand if you would like to drop it or split in a separate PR.
For the query benchmark added in the first commit, comparing the first commit against the las tone:
This change removes the long standing TODO from @KochetovNicolai:
cc @nickitat, @Avogar, @nihalzp, @alexey-milovidov
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
LowCardinality merge optimizations.
Workflow [PR]
Sync PR [sync-upstream/pr/114870]