Skip to content

perf: reduce aggregate key retention and preflighted string copies - #31061

Merged
XuPeng-SH merged 6 commits into
mainfrom
codex/clickbench-systematic-20261025
Oct 25, 2026
Merged

XuPeng-SH merged 6 commits into
mainfrom
codex/clickbench-systematic-20261025

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #27665. This is a bounded aggregation improvement; it does not close the ClickBench umbrella issue.

What this PR does / why we need it:

Mixed PAD SPACE grouping currently retains a second copy of every key when only some keys require a distinct equality representation. Q40 therefore retains ten columns for five logical keys. A shared aggregate-retention helper reuses only structurally identical same-ordinal keys, preserves the visible prefix, appends transformed keys, and produces the executor's existing sorted physical-key subset. It is used by GROUP BY, DISTINCT rewriting, and dependent UNION DISTINCT. Complete set-operation equality tuples stay intact.

Preflighted all-selected string publication now reuses the existing contiguous-copy path. It copies only the exact admitted live-byte span within reserved capacity and preserves selection flags for row metadata; sparse, reordered and gapped inputs use the existing fallback. Admission, growth and spill policies are preserved.

Design and measured validation.

Local results on Apple M4 / 16 GiB / macOS arm64, Go 1.27.1, four threads, source-built DuckDB cc9648d736fd:

Measurement main dae02bbaaaa1 candidate
Q40, original full-width 1M fixture, paired ABBA median 184.65 ms 151.49 ms (-18.0%)
Q40, retained columns / EXPLAIN aggregate memory (not RSS) 10 / 324.18 MiB 6 / 250.81 MiB
Q40, 1 MiB forced spill, DOP4 4.199 s 3.229 s
Q34, dispersed 10M, explicit 4 GiB aggregate budget 863.52 ms 863.77 ms
Preflight+publish, all-selected 256 × 128-byte vector 2252 ns 907.4 ns

DuckDB remains faster: Q40 1M is 18.50 ms; Q34 10M is 160.36 ms. Q34's automatic-spill paired difference is only ~4%, not claimed as a robust SQL latency gain. MO and DuckDB memory limits have different scopes. The 10M fixture projects 18 columns and has no CounterID=62, so positive Q40 evidence uses the full-width 1M fixture. These samples are not a full 100M benchmark.

Validation:

  • Full normal UT: vector, planner, explain, compile and group owning packages.
  • Race once: vector/planner/explain/group owning packages plus affected dependent/native/group compile consumers.
  • Incremental gofmt, vet, repository molint and configured golangci-lint: passed; golangci reports zero issues.
  • Existing SQL BVT file: mo-tester normal comparison twice, 35/35 each; ISCP readiness and database teardown verified.
  • Public controls: DOP1/2/4, NDV1/64/65536, width8/128, NULL/PAD SPACE, scalar/tuple DISTINCT, ROLLUP, prepared reuse and forced spill. Q40 plans confirm actual spill at all three DOPs.
  • All 43 candidate queries executed; Q29 uses equivalent dialect syntax. Deterministic Q12/Q19/Q31/Q33/Q40 results agree with main and local-source DuckDB (AVG precision normalized). Paired follow-ups resolve initial Q38 and corrected-Q29 timing flags.
  • gpt-6.1-sol / xhigh design gate passed and final overall review approved with zero unresolved material blockers. Reviewed source/test fingerprint: e68a4bf508f9a28c493268e63e5a998254fd384377a70f12f05f88acb943c897; delivered commit: 4cc97247f5c9.

Normal set-operation merge factories and sparse-span coalescing remain outside this measured change. CI is pending.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Oct 24, 2026
@XuPeng-SH

XuPeng-SH commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 148af35c5446186a074c56536f301851b12e31a3

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 148af35c5446186a074c56536f301851b12e31a3

Assessment: approve

Reviewed the complete 14-file delta and affected consumers. The design reuses existing aggregate-retention and vector-copy owners, preserves sorted equality keys and preflight admission limits, and demonstrates measurable benefit. No actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Passed 53 focused tests, 6,399 normal tests across five affected packages, and 10 focused race tests. Incremental gofmt, go vet and diff checks passed.

  • Exact SQL BVT passed normal mo-tester comparison twice: 35/35 statements each, with ISCP readiness and database teardown verified.

  • Public SQL probes passed mixed-key grouping, DISTINCT, prepared reuse and ROLLUP; actual spill was verified at DOP 1/2/4.

  • Independent ABBA SQL comparison: mixed-key median 92.29→77.92 ms; EXPLAIN aggregate memory 142.91→110.29 MiB, not RSS. Plain-key control showed no measured regression.

  • Vector comparison: all-selected publication 2544.5→956.4 ns; sparse control 1351.5→1363 ns, with zero allocations.

  • Verified native provenance and reconciled 24 completed command/source/exit receipts with retained logs. Evidence: /home/xupeng/.local/state/mo-bot/jobs/ebcfee29ce904a5528267747/attempt-1/validation-audit.json and review-notes.json. Source remains unchanged.

Limitations:

  • Author ClickBench/DuckDB raw artifacts were unavailable. Independent Linux synthetic measurements do not verify those specific numbers or full-scale ClickBench performance.

  • Repository-wide CI and golangci-lint/molint were not independently verified; local functional, race, BVT and vet results establish the reviewed scope.

@XuPeng-SH
XuPeng-SH merged commit 289d58b into main Oct 25, 2026
25 of 26 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/clickbench-systematic-20261025 branch October 25, 2026 04:01

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants