Repository navigation
Speed up groupUniqArray for numeric types - #110917
Conversation
Use HashCRC32 instead of DefaultHash (intHash64) for integer keys, matching uniqExact, and devirtualize/inline `add` in the batch loop by marking it ALWAYS_INLINE final. Single-threaded aggregate-only benchmarks (interleaved A/B, n = 12, significant under permutation tests at p < 0.001): - 100M rows, 64 distinct UInt64: 303 ms -> 140 ms (2.2x), now on par with uniqExact (143 ms) - 30M rows, 4096 distinct: 130 ms -> 43 ms (3.0x) - 30M rows, 262144 distinct: 219 ms -> 81 ms (2.7x) - Float64 (inlining only; hash unchanged): 400 ms -> 257 ms (1.6x) Result order of the unsorted output array changes for integer keys; three order-dependent test references are updated accordingly. The serialized aggregate state format is unchanged (a plain list of elements), verified compatible in both directions against 26.6.1.
Sort the result arrays with arraySort (and mapApply for the map column) instead of relying on hash-dependent set iteration order, so the tests no longer need reference updates when the hash function changes.
|
Workflow [PR], commit [99fc0b0] Summary: ✅
AI ReviewSummaryThis PR switches numeric Findings❌ Blockers
Final VerdictStatus: ❌ Block Minimum required actions:
|
|
📊 Cloud Performance Report ✅ AI verdict: This PR narrowly optimizes the groupUniqArray aggregate function (CRC32 hashing for integer keys plus an inlined, devirtualized per-row add). Neither flagged ClickBench query executes groupUniqArray, and their CPU time is essentially flat (Q4 ~2665 vs ~2685 ms, Q15 ~2601 vs ~2604 ms) despite -17.5% and -21.3% wall-clock deltas, so both flagged improvements are run-to-run variance rather than real effects and have been downgraded. The actual impact of this change should be judged from the new groupUniqArray perf test, not from ClickBench Q4/Q15. clickbenchFlagged queries (2 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
|
|
@groeneai, investigate the failure in the Upgrade check (amd_release): report — |
|
@alexey-milovidov Confirmed unrelated to this PR, and it is a known chronic upgrade-check flake. The captured failure ( On the restart Separate fix already open: #107126 adds a targeted |
|
Thanks for the analysis. I re-triggered CI on #107126 (the |
|
Status update: CI on #107126 has finished and is fully green (mergeable, no failing checks). It only needs an approval and merge; once it lands on |
|
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110917&sha=84a9c80aa85307d4b14902c4da7d8c0a7f14cfff&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The failed test is The other reds at 84a9c80 are all known issues ( |
|
Acknowledged. No fix in progress and no tracking issue for From the arm_darwin run the test ran 411.95s against the 60s fast-test limit before the per-test timeout killed the client; the |
|
Update after reproducing and reading the CI server log: this arm_darwin failure is Evidence from the run's
This is the chronic "Hung check failed, possible deadlock found" family (tracked in #107941). At the freeze onset the concurrently running tests were Given that, I do not think a separate fix PR on |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 3/3 (100.00%) · Uncovered code |
|
Regarding the AI Review blocker (serialized
The only user-visible effect is the element order of the (unsorted) result array, which is declared in the PR description and was part of the approved change; the three order-dependent tests were switched to Separately, the single CI red on 99fc0b0 is @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110917&sha=99fc0b0d7264b8abda888bb35b61b9223c4c8850&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%202%2F6%29 (the Keeper sanitizer assert in |
|
@alexey-milovidov Confirmed: this is the known systemic Keeper TSan false positive, unrelated to the Root cause. TSan reports a data race in Fix already in progress: #107083 (al13n321, open, approved by antonio2368, Keeper maintainer) adds Spread (CIDB, last 30d). The Log-collection gap. Confirmed: the Keeper TSan report never reaches the archived |
|
Follow-up on the log-collection gap: opened #111523 — integration tests now capture Keeper sanitizer stderr in the collected logs. Root cause: Fix redirects Keeper stderr/stdout to the already-bind-mounted |
f72697e
A Keeper sanitizer report (e.g. a TSan data race in clickhouse-keeper) is written to raw process stderr (fd 2). clickhouse-keeper, a BaseDaemon, only redirects fd 2 to a file when logger.stderr is set; the integration keeper configs set only <log>/<errorlog>, so the report reaches only the container stderr stream. The zoo* containers are not in ClickHouseCluster.instances, so the per-instance stderr.log scan in shutdown() never covers Keeper, and detection falls back to the 'docker compose logs --follow' capture, which is torn down at shutdown and is not archived into logs.tar.gz. That is why the Keeper sanitizer report could not be found in the collected logs on ClickHouse#110917. - docker_compose_keeper.yml: redirect Keeper stderr/stdout to /var/log/clickhouse-keeper/ (already bind-mounted and archived) via '-- --logger.stderr=... --logger.stdout=...', mirroring server nodes. - helpers/cluster.py shutdown(): also scan each Keeper instance's stderr.log for the sanitizer sign, so the report is detected deterministically once Keeper fd 2 no longer reaches the docker.log capture. The TSan race itself is unrelated to this change and is tracked in ClickHouse#107083. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…crc32-hash Speed up groupUniqArray for numeric types
A Keeper sanitizer report (e.g. a TSan data race in clickhouse-keeper) is written to raw process stderr (fd 2). clickhouse-keeper, a BaseDaemon, only redirects fd 2 to a file when logger.stderr is set; the integration keeper configs set only <log>/<errorlog>, so the report reaches only the container stderr stream. The zoo* containers are not in ClickHouseCluster.instances, so the per-instance stderr.log scan in shutdown() never covers Keeper, and detection falls back to the 'docker compose logs --follow' capture, which is torn down at shutdown and is not archived into logs.tar.gz. That is why the Keeper sanitizer report could not be found in the collected logs on ClickHouse#110917. - docker_compose_keeper.yml: redirect Keeper stderr/stdout to /var/log/clickhouse-keeper/ (already bind-mounted and archived) via '-- --logger.stderr=... --logger.stdout=...', mirroring server nodes. - helpers/cluster.py shutdown(): also scan each Keeper instance's stderr.log for the sanitizer sign, so the report is detected deterministically once Keeper fd 2 no longer reaches the docker.log capture. The TSan race itself is unrelated to this change and is tracked in ClickHouse#107083. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Use
HashCRC32(as inuniqExact) instead ofDefaultHashfor integer keys ingroupUniqArray, and markaddasALWAYS_INLINE finalso the batch loop devirtualizes and inlines it. Single-threaded aggregate-only benchmark, 100M rows / 64 distinctUInt64: 303 ms → 140 ms, on par withuniqExact(143 ms); up to 3× at higher cardinalities. The element order of the (unsorted) result array changes for integer keys; three tests that depended on it are switched to sorted output viaarraySort.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up
groupUniqArrayfor numeric types by up to 3x by using CRC32 hashing (as inuniqExact) and inlining the per-row insertion.Version info
26.7.1.1365(included in26.7and later)