Skip to content

fix(median): correct unaccounted results across chunks - #32182

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/32141-main-median
Nov 5, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/32141-main-median

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 4, 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:

Fixes #32141

What this PR does / why we need it:

Unaccounted MEDIAN could overwrite the first result chunk and corrupt both values and NULL markers when results crossed a chunk boundary (8192 groups in Group). Advance the output chunk with the group offset for numeric and decimal results. Also correct the shared split-result cursor for multiple fully preallocated chunks and avoid unnecessary allocations on zero growth or when the current chunk is full.

Document the existing Vector append failure contract and exercise checkpoint rollback, reuse, and allocation-account cleanup after a real grouped varlen allocation failure.

Make the remote allocation statement-group expiry tests deterministic by triggering expiration after the first fragment finishes, and verify that only the still-active fragment is canceled. A separate test continues to exercise the real timer.

Validation:

  • Unbound aggregate and Group regressions across 8191/8192/8193/16385 groups, including decimal, NULL, DISTINCT, ordered percentile, ranking, capacity errors, and account-bound controls. The Group regression fails against the base and passes with this change.
  • vector, aggexec, group, and compile package tests in normal and -race modes; both changed expiry tests also passed 100 individual -race repetitions each. Incremental gofmt, go vet, molint, and golangci-lint.
  • Rebased-head single-CN SQL control: 8193 groups, BIGINT and both decimal representations, no spill and verified spill/reload; the BVT passes twice with teardown. This exercises the account-bound SQL path, not the unbound reproducer.
  • Before-rebase single-chunk unbound MEDIAN Flush microbenchmark: allocation counts unchanged, with integer and decimal median times within 1% of base in this run.

This change does not modify wire formats or the account-bound MEDIAN implementation. Multi-CN and released binaries were not tested.

@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 Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 220c4c8e4c2e00df8501eb0b4520e22794bf6d8d

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: 220c4c8e4c2e00df8501eb0b4520e22794bf6d8d

Assessment: approve

The fix advances unbound MEDIAN values and NULL markers to the correct output chunk and restores the shared cursor after fully filling preallocated chunks. It reuses existing result ownership, allocation checks and append rollback, with no new state or format. Independent value/error/cleanup oracles and all nine locally executed regression roots support the change. No actionable correctness, design or required-validation gap remains.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Read every hunk in all nine changed files, both indexed discussion entries and linked issue #32141 with its decimal follow-up; traced shared result consumers, baseline behavior, allocation failures, output transfer and cleanup.

  • Isolation preflight passed. Built native prerequisites using the repository's top-level make cgo in the diagnostic workspace; verified 198 frozen native/build input hashes and retained output hashes and build log.

  • Go 1.27.1 focused tests passed with the supplied test-exec: nine regression roots across pkg/container/vector, pkg/sql/colexec/aggexec and pkg/sql/colexec/group, covering chunk boundaries, account-bound controls, NULLs, preallocation, DISTINCT/percentile/ranking, capacity errors, rollback and cleanup. See focused-components-recovered.log and checks/1793801003177700529-2.json.

  • Frozen-source audit passed: exact clean HEAD, supplied patch match, complete change/discussion coverage, git diff --check, gofmt for all seven changed Go files, native-input provenance and reconciliation of the focused test receipt with actual passing roots. See frozen-audit.log and validation-audit.json.

Limitations:

  • The frozen CI snapshot has build, UT, SCA and coverage still in progress; none was counted as a completed product-test pass. Initial native/toolchain/proxy setup failures were recovered and are retained as environment diagnostics.

  • Local execution was limited to the nine focused roots. Full-package/race checks, two single-CN SQL BVT runs with observed spill/reload and the performance comparison are author-reported evidence without supplied raw logs. Multi-CN and released binaries were not validated.

@XuPeng-SH

XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 5606a71f6274b6a21abf22f5474ae69a9669d484

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: 5606a71f6274b6a21abf22f5474ae69a9669d484

Assessment: approve

The fix corrects MEDIAN output-chunk and preallocated-result cursors without adding state. It reuses existing allocation and rollback owners, while deterministic expiry tests retain separate real-timer coverage. No actionable defect remains.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed all 10 changed files, complete discussion and linked issue; traced result consumers, allocation failures, cleanup and expiry-test lifecycle.

  • Local frozen-audit.log matches checks/1793825069396684664-2.json, exit 0: frozen head, clean source, patch consistency, diff whitespace, gofmt, prior-core comparisons and independent SQL value/NULL oracles.

  • Reused the supplied prior review's nine focused regression passes after verifying unchanged relevant owners and tests; intervening Vector and expiry-test changes were reviewed separately.

  • Author reports four owning packages passing normal/race tests, both changed expiry tests passing 100 individual race repetitions each, and scoped static checks.

  • Author reports two rebased-head single-CN SQL runs with teardown and observed spill/reload. These cover the account-bound control; aggregate/Group regressions cover the unbound defect.

Limitations:

  • No fresh local Go, race or SQL execution; supplied prior-review and author results were reused without embedded raw logs.

  • Frozen build/UT/SCA/coverage CI remains pending and was not counted as passing. Multi-CN and released binaries were not validated.

@XuPeng-SH
XuPeng-SH merged commit 3d54f0c into matrixorigin:main Nov 5, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/32141-main-median branch November 5, 2026 01:18

This branch was previously deployed

1 inactive deployment
ci — 38f2a1a6 Deployed Nov 5, 2026 by XuPeng-SH
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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MEDIAN 跨块错值、spill 序列化及失败恢复:main / 4.2-dev 证据与修复

2 participants