Repository navigation
Conversation
278e7a8 to
ebefc4a
Compare
|
Workflow [PR], commit [82164e0] Summary: ❌
AI ReviewSummaryThe PR aggregates verified single-dictionary Output consumers traced:
Findings❌ Blockers
Tests
Missing context / blind spots
Final VerdictStatus: ❌ Block Preserve expression semantics for shared aggregation dictionaries and add the focused regression before merging. |
a94b432 to
ae41fea
Compare
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Interpreters/Aggregator.cpp.o |
33.73 MiB | 36.15 MiB | +2.43 MiB (+7.19%) |
src/CMakeFiles/dbms.dir/Interpreters/AdaptiveAggregation/Merge.cpp.o |
12.95 MiB | 13.25 MiB | +308.28 KiB (+2.33%) |
src/CMakeFiles/dbms.dir/Processors/Transforms/AggregatingTransform.cpp.o |
690.10 KiB | 830.76 KiB | +140.66 KiB (+20.38%) |
src/CMakeFiles/dbms.dir/Interpreters/AggregatorThresholdTopK.cpp.o |
2.09 MiB | 2.16 MiB | +80.41 KiB (+3.77%) |
src/CMakeFiles/dbms.dir/Interpreters/AdaptiveAggregation/Producer.cpp.o |
2.68 MiB | 2.73 MiB | +49.13 KiB (+1.79%) |
src/CMakeFiles/dbms.dir/Processors/Transforms/LimitByTransform.cpp.o |
1.56 MiB | 1.59 MiB | +27.30 KiB (+1.71%) |
716 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
301 translation units recompiled, 2158 s compile time in total, 301 of them have a recent master baseline.
|
📊 Cloud Performance Report ✅ AI verdict: This PR adds a specialized aggregation path that hashes LowCardinality dictionary indexes directly when a MergeTree part is verified to use a single dictionary, touching the aggregation hot path (ColumnsHashing, AggregationMethod, Aggregator). The only flagged query is ClickBench Q28, a LowCardinality GROUP BY that legitimately exercises this new code, so the flag is on-path and not downgraded. The +5.5% (median 1066ms to 1125ms) is marginal: the two tests disagree, CPU time is essentially flat (15571ms vs 15644ms), and the query has a noisy history, so this is inconclusive rather than a confirmed regression. Worth a re-run to confirm before drawing any conclusion. clickbenchFlagged queries (1 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_official🟢 No significant changes Debug info
|
ae41fea to
6840f0f
Compare
|
Rebased to resolve the trivial include conflicts with #116267. |
|
While the conflicts were minimal, #96630 did change the code to cause compilation errors after the rebase. I adjusted the code to work with the new topk optimization. cc @thevar1able |
6840f0f to
57b4f16
Compare
57b4f16 to
bd2d868
Compare
bd2d868 to
bc96b1c
Compare
bc96b1c to
9b21c3b
Compare
c3c4cfb to
bd53f1a
Compare
|
Single thread north star: That's -62% from the baseline. I'm trying to figure out how to not mess up parallel queries while doing this. |
|
I added a commit to preserve indexing across dictionary switches without compromising CPU or memory costs.
No impact to numbers in the description as those exercise one part to begin with. |
c1418c4 to
2fc1f49
Compare
…s after an ineligible block An eligible dictionary A, then an ineligible block (e.g. from a `Compact` part), then dictionary C enabled dictionary shards through the ineligible-block branch of `AggregatingTransform::consume`, bypassing the `spilling_under_memory_pressure` check applied on a dictionary switch. Apply the same restriction there. Extend `05565_low_cardinality_dictionary_spill_scheduler` with the A -> `Compact` -> C sequence under `enable_adaptive_memory_spill_scheduler = 1` with both external aggregation thresholds zero, and pin `use_columns_cache = 0` and `enable_parallel_replicas = 0` in its aggregation queries. ClickHouse#115925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Columns served from the columns cache do not carry the shared dictionary of the part, so with randomized `use_columns_cache = 1` the queries never reach the dictionary index path these tests exercise. `05093_low_cardinality_dictionary_memory_backpressure` then timed out waiting for the owner pause failpoint (TSan and MSan flaky checks), and `05060_low_cardinality_dictionary_eligibility_transitions` lost its index aggregation lines. The same fix was applied to `05087` earlier. Also pin `enable_parallel_replicas = 0` in `05060`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115925&sha=60033cee76c2c72bc4670bb1b2c7e12468e233b8 ClickHouse#115925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master now counts the rows of each dictionary position of a block for `GROUP BY lc_key` with `count()` alone, and does one lookup per distinct position. That beats the index-keyed table: the performance test `group_by_multi_low_cardinality` query 2 (`SELECT metric, count() ... GROUP BY metric`) was 48% slower with this PR (confirmed on rerun). `canUseSingleLowCardinalityDictionary` now returns false when `is_simple_count`; `can_reorder_dictionary_aggregation` is computed after the top-K adjustment of `is_simple_count`. `05045` gets a second aggregate to keep exercising the index path, and the `inline_count` case of `05080` now expects no dictionary switches. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115925&sha=60033cee76c2c72bc4670bb1b2c7e12468e233b8 ClickHouse#115925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged master and pushed three fixes:
Still open, needs a human decision: MSan |
…statistics Aggregation by dictionary index emits key columns that share the source dictionary, and `ColumnLowCardinality::byteSize` does not count a shared dictionary. `RuntimeDataflowStatisticsCacheUpdater::recordAggregationKeySizes` and `MaterializedKeyBytesMeter` priced the keys by `byteSize`, so the output bytes of the automatic parallel replicas cost model dropped to the indexes alone (about 4 KB instead of about 540 KB for 1000 keys of 1 KiB). Count the referenced dictionary values explicitly in both paths, and add a regression test that compares an eligible single-part aggregation with a value-keyed control. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A query whose only aggregate is `count` takes the inline-count path and bypasses aggregation by dictionary index, so the typed cases of the test no longer covered it. `sum(1)` does not help: the analyzer rewrites it to `count`. Add a checked `uniqExact(id)` to each subquery, and assert via `AggregationSingleLowCardinalityDictionarySwitches` that the two-part typed queries take the dictionary-index path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/115925/a78939781a0ef2f49707457c03a9ce8051151aac/pr/stress_test_amd_tsan/hung_check.log ( Other failures at a789397:
This push merges master and addresses both review threads (shared-dictionary bytes in the output statistics, and keeping the |
|
This hang is not caused by this PR. The query is stuck in The failing run at a789397, including the merge with master that CI built, does not contain the fix (286 commits behind its merge commit ebf03a4), while the new head 31a6b14 does, so no separate PR is needed. |
# Conflicts: # src/Interpreters/Aggregator.cpp
`05024`: the CI profile (`tests/config/users.d/limits.yaml`) sets `max_rows_to_group_by`, which disables aggregation by dictionary index, so the two-part typed queries never switched dictionaries and the `AggregationSingleLowCardinalityDictionarySwitches` checks returned 0. Pin `max_rows_to_group_by = 0` (and `use_columns_cache = 0`, as in the other dictionary aggregation tests). `05620`: `SHA256` is not available in the Fast test build. Use `sipHash128` to generate the poorly compressible keys, and check only the ratio of the output bytes instead of their exact build-dependent values. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115925&sha=31a6b14761d99ff13b566bb786f9415b14f049fd&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged master (one trivial include conflict in
All 25 tests of this PR pass locally against a server that uses the CI @groeneai, thanks for tracing the Still needs a human decision: the MSan |
…ndex Resolve conflicts with the adaptive aggregation merge rework on master: - `mergeSingleLevelPartitionsAndConvertToChunk` takes `destination_size_hint`; keep the dictionary copy for the destination. - `prepareVariantsToMerge` accepts indexed single-level sources of the bucket-merge destination. - `prepareAdaptiveTopKPruning` was renamed to `prepareAdaptiveTopK`. - Dictionary indexes are normalized whenever the adaptive merge goes by buckets (`mergesByBuckets`), not only when engaged, since the destination is value-keyed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged master (
Every changed TU compiles. I could not link the binary locally because of memory limits on the shared machine, so CI has to confirm the link. |
# Conflicts: # src/Interpreters/Aggregator.cpp # src/Interpreters/Aggregator.h
…lues in Arrow Both Arrow writers (`ArrowIPCBlockOutputFormat::encodeDictionaryColumn` and `fillArrowArrayWithLowCardinalityColumnDataImpl`) serialized the whole dictionary of a `LowCardinality` column. A `MergeTree` part dictionary that the reader shares with the column, or a dictionary that `filter` left unchanged, holds values of rows that were filtered out, e.g. by a row policy, so they were disclosed in the output. This already happened for a plain `SELECT` and the aggregation by dictionary index extends it to `GROUP BY` results. Compact the dictionary to the values that the rows reference (`cutAndCompact`) before encoding it. Add a test with a restricted user over HTTP. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115925&sha=026654f0258385a6dff41787a0fd63e4f4d58850&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%203%2F6%29 ( |
|
That looks like a property of this binary rather than of the code on that path, but I have not proven it. I'm comparing that path's machine code in the two CI binaries and will follow up here with a PR or my findings. |
AI review of a later commit does not approve the PR, see the AI Review comment.
|
Follow-up on
The current head ff325de is a new build, so its perf run gets a new placement. If this class should stop blocking PRs, the fix is in the perf gate: do not block on a confirmed slowdown when the functions the query spends its time in have the same machine code in both binaries (option (a) in #131211 (comment)). |
…ndex Conflicts: - `ColumnLowCardinality.cpp`: keep `tryAdoptSharedDictionary` (it covers the adoption of a shared dictionary by an empty column added on master) and read the current dictionary through the const overload, as on master. - `ColumnLowCardinality.h`: take the `const_cast` + `getPtr` form of `create` from master and pass `has_single_dictionary_for_part`. - `Aggregator.cpp`: use `AggregatedDataVariants::SizeHint` in `mergeSingleLevelPartitionsAndConvertToChunk` and the `state_cache` argument of `mergeStreamsImpl` in the dictionary index dispatch. Co-Authored-By: Claude Fable 5.2 <[email protected]>
- `AggregatedDataVariants::init` now takes a `SizeHint` instead of a number of keys; pass it for the normalized variant. - `master` added `chassert(use_count() == 1)` to `assumeMutableRef`, which the non-const accessors of the `LowCardinality` dictionary go through. `ColumnLowCardinality::insertDictionaryIndex` and `AggregationMethodSingleLowCardinalityDictionaryIndex::insertKeyIntoColumns` only read a dictionary that is shared by design, so they now use the const overloads. Co-Authored-By: Claude Fable 5.2 <[email protected]>
- `modernize-use-nodiscard` for `getIndexAt`, `getHashAtIndex`, `hasOnlyOneValueSinceLastReset` and `getCacheMissesSinceLastReset` of `HashMethodSingleLowCardinalityDictionaryIndex`. - `clang-analyzer-deadcode.DeadStores` for the unused second half of the structured binding of `std::ranges::unique` in `RuntimeDataflowStatistics.cpp`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115925&sha=ff325ded3669c3bac28d492ff7043966b0ef1cb0&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29 ClickHouse#115925 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged master ( Conflicts and the reconciliation with master (
All 26 stateless tests of this PR pass locally on the merged release build with the CI @groeneai, thanks for the analysis of Still needs a human decision: the MSan |
The style check forbids `std::vector` under `src/Processors/QueryPlan`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115925&sha=9aaaa6b8c474abb2208b8584bb5024575c152e34&name_0=PR&name_1=Style%20check ClickHouse#115925 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
|
||
| auto & column = assert_cast<ColumnLowCardinality &>(*key_columns_low_cardinality[0]); | ||
| if (column.empty()) | ||
| column.setSharedDictionary(dictionary); |
There was a problem hiding this comment.
[Blocker] Keep unused dictionary values out of post-aggregation expression evaluation
Attaching the entire part dictionary here changes which values downstream expressions evaluate. For example, create one Wide part with a numeric LowCardinality key:
SET allow_suspicious_low_cardinality_types = 1;
CREATE TABLE t (id UInt64, k LowCardinality(UInt64), v UInt64)
ENGINE = MergeTree ORDER BY id
SETTINGS min_rows_for_wide_part = 0, min_bytes_for_wide_part = 0;
INSERT INTO t SETTINGS low_cardinality_use_single_dictionary_for_part = 1
VALUES (1, 3, 1), (2, 1000001, 2);
SELECT space(k), sum(v)
FROM t WHERE id = 1 GROUP BY k
SETTINGS max_threads = 1, max_rows_to_group_by = 0,
optimize_aggregation_in_order = 0, use_columns_cache = 0;The old aggregation builds an output dictionary containing only default 0 and surviving key 3. This path retains 1000001 too. space inherits canBeExecutedOnDefaultArguments = true, so IExecutableFunction::executeWithoutSparseColumns and replaceLowCardinalityColumnByNestedAndGetDictionaryIndexes evaluate the entire dictionary (src/Functions/IFunction.cpp:135-140,591-621). FunctionSpace::checkRepeatTime then throws TOO_LARGE_STRING_SIZE for the filtered-out key, although the only result should be three spaces and 1.
Please make the shared aggregation output safe for expression consumers, or restrict generic dictionary evaluation to referenced entries, and add a focused stateless regression. The Arrow-writer fixes do not cover this consumer.



This is perhaps a simpler/better alternative to #114993. I'm reusing the first benchmark commit from there. Notice that it does not depend on #114982 to speed up aggregations of wide integers.
When a
MergeTreepart has one verifiedLowCardinalitydictionary, its indexes uniquely identify values throughout the part. Use these indexes directly as aggregation keys and retain the dictionary for result finalization.Merge parallel aggregation states directly when they share the same dictionary. Normalize back to value-based aggregation when the dictionary changes.
This gives a very nice speedup to the benchmark in the previous commit:
UInt8UInt16UInt32UInt64UInt128UInt256String(6 B)String(26 B)String(56 B)Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up single dictionary
LowCardinalityaggregations by aggregating keys by dictionary index.Workflow [PR]
Sync PR [sync-upstream/pr/115925]