Skip to content

Run the group_by_dynamic_keys performance queries on 400k rows - #131871

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/perf-group-by-dynamic-keys-400k
Nov 16, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/perf-group-by-dynamic-keys-400k

Conversation

@groeneai

@groeneai groeneai commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #129258

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Queries 0 and 2 of group_by_dynamic_keys.xml take 2.79 and 1.56 s on MasterCI amd (3.51 and 1.90 s on arm); the String control takes 0.13 s. Every row is its own group, and seven Dynamic keys select the serialized aggregation method: 65-86% of CI's CPU samples are in ColumnDynamic::serializeValueIntoArena, the cost the file measures.

No existing query number or text changes: 2 queries are disabled and 2 copies appended as 3 and 4. The copies run the same queries on 400k rows instead of 2M and 1M, still one group per row. The JSON fill, read only by the disabled query, is renamed and resized in place to its first 400k rows. The String control keeps its 2M rows. Per row, a copy's local user time is 0.95x and 1.01-1.02x its original's.

On the MasterCI builds before and after #112316, which stopped the look-ahead prefetch from serializing every key twice (CI: 1.26-1.32x on amd, 1.52x on arm), the copies keep 84-92% of the originals' speedup locally, in both seat orders and two repetitions on different NUMA nodes. On open #131331's build, the copies take their originals' aggregation path.

Below 500k groups a repeated run gets no hash table size hint, so the copies start their table single-level and unallocated where the originals start it two-level and preallocated; that table is about 1% of CI's samples.

The copies should take 0.53-0.63 s on amd and 0.67-0.78 s on arm: about 32 s of query time per master perf job on amd and 40 s on arm, and the setup fills 400k JSON rows, not 1M. The copies restart the history of 2 queries.

Validation: perf.py on the final file runs only queries 1, 3 and 4, also with CI's --max-queries 10, with no run trend.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131871]

Version info

  • Merged into: 26.11.1.2412-master (included in 26.11 and later)

Queries 0 and 2 of tests/performance/group_by_dynamic_keys.xml take
2.79 / 1.56 s on MasterCI amd (3.51 / 1.90 s on arm); the String
control takes 0.13 s. Every row is its own group (the key moduli are
pairwise coprime), and 65-86% of CI's CPU samples are in the per-row
key serialization of the serialized method
(ColumnDynamic::serializeValueIntoArena), which the file measures.

No existing query number or text changes: 2 queries are disabled and
2 copies appended as 3 and 4. The copies run the same queries on 400k
rows (still one group per row). The JSON fill is read only by the
disabled query, so it is renamed and resized in place to
t_json_group_by_400k, the first 400k of the same rows. The String
control keeps its 2M rows.

Local A/B on official builds, two repetitions on different NUMA nodes,
L3 capped to one way (decide.py: every gate passes in both):
- user time per row of a copy 0.948 (Dynamic casts) and 1.009-1.016
  (JSON subcolumns) of its original;
- local time ratio copy/original 0.191 and 0.403-0.408 -> projected
  CI medians 0.53 / 0.63 s amd, 0.67 / 0.78 s arm;
- on the MasterCI builds before and after ClickHouse#112316 (7a9ada8 -> 6e89ba5,
  CI measured 1.26-1.32x on amd, 1.52x on arm), the copies keep
  0.836-0.919 of the original's speedup, both seat orders;
- on the build of ClickHouse#131331 each copy takes its original's adaptive
  aggregation path.
Below 500k groups a repeated run gets no hash table size hint
(HashTablesStatistics getSizeHint at max_threads = 1), so the copies
start their table single-level and unallocated where the originals
start it two-level and preallocated; that table is about 1% of CI's
samples.
Saving: about 32 s of query time per master perf job on amd and 40 s
on arm; the setup fills 400k JSON rows instead of 1M.

Related: ClickHouse#129258

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding), plus my own review (0 blocking findings).

# Sev Finding Verdict Evidence / action
1 ⚠️ No reviewable evidence that the 400k-row copies still detect the serialized-key prefetch regression, given they start their hash table without a size hint (group_by_dynamic_keys.xml:58-70) DISAGREE amd, recorded: perf.py runs of each original and its copy on the MasterCI builds before and after #112316, both seat orders, two repetitions on different NUMA nodes, L3 capped to one way: originals 1.26-1.38x, copies 1.20-1.35x (0.84-0.92 of the effect), A/A deltas of the copies at most 0.017. A copy's user time per row is 0.95x / 1.01-1.02x its original's. arm: projected only, as the PR body says; the copies change only the input size, and the size-hint cutoff is not architecture-specific.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261115-214201

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. MasterCI medians 2.79 / 1.56 s amd, 3.51 / 1.90 s arm for queries 0 / 2 (74 commits); in every local pass on the official master build the copies take 0.19x / 0.40x of their originals.
b Root cause explained? Input size: every row is its own group (2M / 1M rows), and the per-row key serialization of the serialized method (65-86% of CI's CPU samples) is what the file measures.
c Fix matches root cause? Yes. The copies change only the input size, to 400k rows, still one group per row; user time per row 0.95x / 1.01-1.02x of the originals'.
d Test intent preserved / new tests added? Yes. Same query texts, keys, JSON paths and fill expression; the String control unchanged. No functional test (perf-test-only change).
e Both directions demonstrated? Yes. On the builds before/after #112316 the originals speed up 1.31-1.38x and the copies 1.26-1.35x (retention 0.84-0.92), both seat orders, two repetitions on different NUMA nodes.
f Fix is general across code paths? N/A (test-only, no source change). Both queries above 1 s are handled.
g Fix generalizes across inputs (params/datatypes/wrappers)? Both key sources (casts to Dynamic, JSON subcolumns of a MergeTree read) are checked separately; both pass every gate.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; queries 0-2 keep their text and numbers, the copies take fresh numbers 3 and 4.
i Invariants and contracts preserved? Yes. Existing query texts and order unchanged, copies appended after the last query, every fill has an enabled reader, all 3 enabled queries run under --max-queries 10, no run trend.

Session id: cron:clickhouse-impl-slot-4:20261115-212700

@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [be9219a]

Summary: ✅


AI Review

Summary

PR #131871, reviewed at be9219ac81dc7559667577e097b0f191d426ed8b, replaces two expensive Dynamic/JSON aggregation benchmarks with 400,000-row copies, preserving existing query numbers and the String control. The reported before/after measurements support retaining regression sensitivity. No actionable findings.

Missing context / blind spots
  • ⚠️ No local ClickHouse binary or build was available to repeat SQL execution or timings. Performance conclusions rely on the author's reported amd A/B measurements; arm savings are projections. Independent confirmation would require running the original and replacement benchmarks on the corresponding CI hosts.
Final Verdict

✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Nov 15, 2026
@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). labels Nov 15, 2026
@alexey-milovidov alexey-milovidov self-assigned this Nov 16, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 16, 2026
Merged via the queue into ClickHouse:master with commit 1e0344d Nov 16, 2026
384 of 385 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
@clickhouse-gh clickhouse-gh Bot added comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants