Skip to content

Reduce SORT ROLLUP finalization and window allocations - #31584

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/0eece105ae76d5caf73d37a3319ad499c710154f16eaf824d3d27e26fae31e11
Oct 28, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/0eece105ae76d5caf73d37a3319ad499c710154f16eaf824d3d27e26fae31e11

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 28, 2026 •

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:

What this PR does / why we need it:

SORT ROLLUP repeatedly finalizes and rebuilds completed aggregate groups and allocates argument windows. At high group cardinality, these costs can dominate aggregation. This change reuses single-group state through append/reset and fills input ranges directly when the complete aggregate list supports the narrow COUNT/native SUM/AVG fast path. A list containing any unsupported aggregate keeps the existing path for the whole list. Results, NULL handling, output ownership, cancellation checks, planner admission, and COST thresholds are preserved.

This is a follow-up to merged #28987 (SORT ROLLUP feature) and #31505 (DISTINCT correctness and ordered-input admission). Those DISTINCT/admission fixes are already present; this PR addresses the remaining executor cost. The earlier static cost concern is separate from the pre-merge measurements below. This change does not optimize every SORT ROLLUP workload. After merge, the original reporter should verify the remaining workload against this change.

Validation at the merged PR head

At e9281125b65348d22cdfe7afafa28c5a69f2871d:

  • 623 aggexec and 236 group owning-package tests (859 total), plus 40 planner/compiler consumer and allocation-guard tests.
  • 20 exact manual SQL oracle assertions across 42 statements, plus FLOAT fail-closed execution through the HASH fallback.
  • KILL QUERY during actual SORT ROLLUP work, followed by correct ROLLUP results on the same connection and verified transaction, lock, and working-frame cleanup. The test service exited and test databases were removed.
  • Incremental vet/lint passed for seven related packages. The new binary records this exact revision with vcs.modified=false; gpt-6-astra medium final overall review passed at this head.

The earlier two complete ROLLUP BVT runs (51/51 each) and full cancellation/timeout matrix (10 result checks, 6 resource-closure checks, including client cancellation, KILL QUERY/CONNECTION, reuse, and cleanup) remain evidence from pre-merge revision 07701c4cd47779ca7017b4674c3552fed719b815, reviewed with the documentation update at 44aab779ca5b5430c12edd22fba8758577b434f6. These full matrices were not rerun at the merged head.

Performance and limitations

Pre-merge local physical-operator benchmarks on Apple M4, Go 1.27.1, GOMAXPROCS=4 (100 ms, three samples per shape) show 78–94% lower time and more than 96% lower B/op and allocs/op for four ordered high-NDV shapes against the pre-change SORT implementation. Derived-input shapes including sorting also improve. These are historical operator measurements of production candidate c123861e5500408a2f1798a0f8e4e80a05a35d22 with final benchmark fixtures at 07701c4cd47779ca7017b4674c3552fed719b815 (pre-merge reviewed head 44aab779ca5b5430c12edd22fba8758577b434f6). No performance timing was rerun after the main merge at e9281125b65348d22cdfe7afafa28c5a69f2871d; the final review confirms the optimization mechanism and the applicability of these historical results, without establishing merged-head percentages, exact timings, or absence of regression. There are no SQL end-to-end or multi-CN performance claims.

Forced SORT remains 1.08–6.80x slower than the retained shared-HASH baseline in the measured comparisons. DISTINCT, dedicated decimal implementations, MIN/MAX, and unsupported mixed lists are not accelerated. Earlier design-document performance numbers remain historical calibration, separate from the pre-merge candidate measurements above; neither set is a new measurement of the merged revision.

In those pre-merge measurements, for low-NDV protection, all three contemporaneous baseline/candidate pairs per shape fit the unchanged 20% engineering budget (nine pairs total, maximum ratio 1.128; median ratios 0.977/1.048/0.932). Pooling measurements across different periods instead gives COUNT/AVG ratios of 1.283/1.473, exceeding that budget; the initial comparison was also unfavorable. Using all contemporaneous pairs as the primary acceptance evidence is an explicitly reviewed, post-hoc applicability revision. The small sample and fixed baseline-first order limit the conclusion: this is not statistical proof of no regression.

CI remains pending and is separate from the local results above. No real multi-CN run was performed; distributed routing/state and compiler placement gates are unchanged.

@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

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

Commit: e9281125b65348d22cdfe7afafa28c5a69f2871d

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

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

Assessment: approve

Reviewed the complete change, affected consumers, ownership and failure paths. No actionable defects remain. Aggregate reuse preserves fallback behavior, arithmetic, output ownership and cleanup.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Reused frozen-head successful build, UT, static-analysis, coverage and multi-CN BVT statuses.

  • Inspected regression tests and existing SQL result oracles; reconciled all discussion entries.

  • Source and discussion integrity check passed: checks/1793192362985754652-3.json, with review-integrity.log.

Limitations:

  • Raw CI and author validation logs were not supplied; no local Go tests were rerun.

  • Benchmarks predate the merged head. Conflicting low-NDV sampling windows limit performance conclusions; no general non-regression claim is established.

@mergify mergify Bot added the queued label Oct 28, 2026
@mergify

mergify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

32 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Wed 28 Oct, 13:03 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 13:34 · cdb9c38

Reason

Pull request #31584 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Merge conditions: 2 of 3 met

This pull request

Condition Required by
✅ #review-threads-unresolved = 0 GitHub branch protection
✅ github-review-approved GitHub branch protection

The batch, tested in place

Condition Required by
❌ any of: check-neutral = CI Required, check-skipped = CI Required, check-success = CI Required GitHub branch protection

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@XuPeng-SH
XuPeng-SH merged commit 6d1f5d7 into matrixorigin:main Oct 28, 2026
25 of 27 checks passed
@mergify mergify Bot added dequeued and removed queued labels Oct 28, 2026

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

dequeued kind/documentation Improvements or additions to documentation kind/enhancement size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants