Repository navigation
[4.2-dev] fix(window): reuse full and cumulative aggregate frames - #31546
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: a11250d9e5f408e6d970f7bfa67ee30a7a4390a3
Assessment: approve
Reviewed the complete five-file delta and its consumers. Aggregate reuse preserves frame semantics and result ownership while removing quadratic work on the targeted paths. No actionable findings remain.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1
Validation:
-
All 83 Window tests passed normally and under race detection; seven focused tests each passed 100 race repetitions. Build and vet passed.
-
60 decimal/wide-integer prefix controls passed across consecutive partitions.
-
All 20 SQL fixture statements and 11 result sets matched through an isolated MySQL endpoint, including metadata and prepared reuse.
-
At 4096 rows, median full-frame SUM improved from 1531 ms to 0.44 ms; cumulative RANGE improved from 770 ms to 0.56 ms. Warmed bounded-frame controls remained essentially unchanged.
-
Preflight, native provenance, unchanged source, discussion coverage and 21 command/log pairs reconciled in /home/xupeng/.local/state/mo-bot/jobs/62a55ccc1fc291d73222c84d/attempt-1/validation-audit.json; final audit receipt 1793170194383932379-5.json passed.
Limitations:
-
Validation used Linux/amd64 and an embedded MySQL fixture adapter; mo-tester, arm64 and multi-CN performance were not independently rerun. Frozen CI was pending.
-
Unsupported cumulative aggregates retain the existing evaluator; eager evaluation before LIMIT and singleton-partition setup costs remain outside this fix.
## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Addresses #31530 on `release/v4.2.1-hotfix-20261026`. ## What this PR does / why we need it: Backport #31546 to the active 4.2.1 hotfix branch. Aggregate windows currently rescan unbounded frames for every output row, causing quadratic aggregate work, including with a `LIMIT` above the Window operator. Compute a whole-partition aggregate once and broadcast its result. Reuse independent unfinalized states for supported cumulative COUNT/SUM/AVG and fixed-width MIN/MAX frames; RANGE includes the complete peer group. Preserve the existing evaluator for unsupported cumulative aggregates and frames, and keep the target branch's unrelated vector and lifecycle code unchanged. Validation on the target branch, macOS arm64 and Go 1.26.4: - Full Window package passed normally and with `-race`; tests cover aggregate values, NULLs, peers, partition isolation, varlen/DISTINCT full frames, work counts, cancellation and allocation failures. - Exact public SQL BVT passed twice on a two-CN cluster: 20/20 each, no skipped or failed statements, with database cleanup checked on both CNs. - Incremental 31-package `go vet`, `molint` and configured `golangci-lint` passed; lint reported zero issues. Molint printed six diagnostics in unchanged frontend/compile files; the same six were reproduced against the target baseline. - Same local SQL harness, target baseline versus backport, 8,000 rows: full SUM 10.708 s → 1.639 ms, cumulative SUM 5.323 s → 1.952 ms, full COUNT 332.37 ms → 0.285 ms; returned values checked. These are single observations on separate local cluster starts, not a statistical no-regression benchmark. The UT also checks aggregate work counts. - gpt-6.1-terra/max design and final overall review completed. Unsupported cumulative DISTINCT, variable-length MIN/MAX and other unsupported states, and frames ending at a non-current offset retain the generic evaluator. CI remains separate.
What type of PR is this?
Which issue(s) this PR fixes:
Addresses #31530 on
4.2-dev.What this PR does / why we need it:
Aggregate windows currently rescan the entire frame for every output row. Full-partition and unbounded-prefix frames therefore perform quadratic aggregate work, even when the query ends with
LIMIT 20.Compute full-partition aggregates once and broadcast the finalized value using the existing off-heap allocation contract. For cumulative
ROWSandRANGE, reuse independent, unfinalized COUNT/SUM/AVG/fixed-width MIN/MAX states and fill each input row once. RANGE snapshots include complete peer groups; finalization occurs only after all snapshots are complete. This preserves NULL handling, decimal scales, floating-point addition order, and result ownership.Tests cover peers, partition isolation, grouped pagination, prepared reuse, the 8192-group boundary, variable-length results, deterministic linear work, aggregate errors, cancellation, and allocation denial.
Validation
-race; seven focused tests also pass 100 repetitions each under-race.go build,go vet, configured golangci-lint, molint, and changed-file license checks pass, including the new Go tests.Same-harness measurements at 4,096 rows:
The final public SQL check at 50,000 rows takes 12.7 ms for whole-partition SUM. These are local measurements; CI is pending.
Unsupported cumulative aggregate states retain the existing evaluator. Many-singleton-partition setup costs and eager evaluation before LIMIT remain separate limitations.