Skip to content

perf: reduce general hash aggregation overhead - #31586

Merged
XuPeng-SH merged 14 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/systematic-hash-aggregation-20261028
Oct 28, 2026
Merged

XuPeng-SH merged 14 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/systematic-hash-aggregation-20261028

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • Improvement
  • BUG

Which issue(s) this PR fixes:

Related to #27665

What this PR does / why we need it:

Reduce CPU overhead in general hash aggregation paths:

  • Simplify integer hash insertion planning while preserving preview, admission, commit validation, and group IDs.
  • Copy eligible single eight-byte keys into iterator-owned scratch using a byte view, preserving the exact type-independent representation. Retain generic encoding for floats, nulls, constants, and composite keys. This fixes the CI race-build panic caused by treating datetime, time, and timestamp vectors as []uint64.
  • Reuse the selection count checked during preflight when publishing group keys, while preserving string provenance and batch-boundary behavior.

These changes apply to common hash operations, without query- or data-specific planner rules. A fixed-window adaptive local reduction prototype was excluded after a repeated-key control exposed a regression. See the design. The design and final change were independently reviewed with gpt-6.1-terra/max.

Validation

  • Rebased onto main 6d1f5d7f2d31.
  • Reproduced the original failure against the pre-fix PR head under -race; the repaired version passes normal and race tests for pkg/common/hashmap, pkg/container/hashtable, pkg/sql/colexec/group, and pkg/sql/compile.
  • Normal and race SQL integration tests pass for fractional temporal primary keys and the affected timestamp CTE/join. New fast-path tests cover all seven eligible nonfloating eight-byte types, offsets, borrowed windows, duplicate/extreme values, generic-path equivalence, and preview/commit ownership across input mutation and replan.
  • SCA: vet and molint over the 336-package affected reverse-dependency closure completed successfully. Molint emitted existing repository diagnostics, including the pre-existing unsafe import in the hashmap test; no new diagnostic was found in the modified files. Golangci-lint reported 0 issues across the same scope.
  • On Apple M4, an encoder-only 256-key sequential ABBA microbenchmark measured BIGINT flat at 287.2 ns/op with the pre-PR encoder vs 61.2 ns/op fixed, and 63.9 ns/op with the original PR encoder vs 61.3 ns/op fixed; DATETIME measured 286.7 → 61.4 ns/op and 64.6 → 61.1 ns/op, respectively. All nine flat, null-flag, and composite scenarios allocated 0 B/op. A longer ABBA follow-up for the initially noisy INT null-flag control measured 648.25 vs 646.3 ns/op. This isolates the encoder and is not a post-rebase end-to-end measurement.

Historical measurements on the original PR head against main 9e29011e73, before this rebase and repair, used sequential ABBA on a four-core single-CN setup with a 12 GiB query budget and 99,997,497 rows. COUNT(DISTINCT UserID) medians were 3.104 s → 2.553 s (−17.8%) and 5.395 s → 4.977 s (−7.8%) for a shuffled multiset. The 17.8% improvement was below the original 25% Q5 target. Historical checks included high-repeat, unique, low-cardinality, skewed, nullable, string, composite-key, grouped DISTINCT, and one-worker controls with exact result checks and no aggregate median regression; the plans showed no spill and the measured processes had zero swap. These shared-host timings are historical evidence, not post-rebase end-to-end measurements, and do not establish DuckDB parity or guarantee similar improvement elsewhere.

The updated head’s Linux/x86 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 →

@XuPeng-SH

XuPeng-SH commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: bb997af05b65f14d69a78bff690181af56a52060

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: bb997af05b65f14d69a78bff690181af56a52060

Assessment: approve

Reviewed the complete change, design, consumers and discussion. Key identity, publication, batch splitting and string provenance contracts remain intact. No actionable findings remain.

Model: gpt-6-astra / xhigh

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

Validation:

  • Isolation preflight and native build passed; native inputs and artifacts verified.

  • 330 tests passed across hashtable, hashmap and group with -vet=all -count=1; no failures or skips.

  • Sequential baseline/candidate benchmarks confirmed intended gains. Complete iterator preview/commit improved 9–26%; tested lookup controls showed no material regression.

  • Source remained unchanged. Discussion coverage, logs and 16 execution receipts reconciled in review-audit.json; final audit passed under checks/1793185294017252188-4.json.

Limitations:

  • Some isolated fallback encoding benchmarks slowed 11–17%; complete iterator measurements did not reproduce that regression. Shared-host timing precision remains limited.

  • Author-reported SQL-scale benchmarks, additional compile-package tests and lint results were not independently reproduced. Pending, cancelled and skipped CI jobs were not counted as passes.

@XuPeng-SH

XuPeng-SH commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: a694f17896100b1e0daecc5ced5196a525361a33

"interrupted"

@mergify mergify Bot added the kind/bug Something isn't working label Oct 28, 2026
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Oct 28, 2026
@XuPeng-SH

XuPeng-SH commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 3289ce9e958e43b7f7b0ab775f5c8db4d44c13f5

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: 3289ce9e958e43b7f7b0ab775f5c8db4d44c13f5

Assessment: approve

Reviewed the complete delta, design, consumers and discussion. Key identity, preview ownership, admission, batch splitting and string provenance remain intact. The temporal-type race regression is fixed. No actionable findings remain.

Model: gpt-6-astra / xhigh

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

Validation:

  • Isolation preflight and native build/provenance verification passed.

  • 333 top-level tests and 347 subtests passed across hashtable, hashmap and group with -vet=all -count=1; no failures or skips.

  • Focused -race regression passed all seven eligible eight-byte types.

  • Logs and receipts reconciled in review-audit.json. Formatting, unchanged source and all five discussion keys verified; final audit passed under checks/1793197817489892824-4.json.

Limitations:

  • Product CI remained pending in the frozen evidence; skipped jobs were not counted as passes.

  • Historical performance reports support the design but do not establish current end-to-end gains.

  • Author-reported broader SQL, compile, race and lint checks were not independently reproduced.

@XuPeng-SH
XuPeng-SH merged commit 9598300 into matrixorigin:main Oct 28, 2026
21 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/systematic-hash-aggregation-20261028 branch October 28, 2026 16:10

This branch was previously deployed

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

Labels

kind/bug Something isn't working kind/enhancement size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants