Skip to content

fix(agg): preserve grouped MEDIAN results across chunks and spills on 4.2-dev - #32152

Merged
XuPeng-SH merged 4 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/32141-42-median-spill
Nov 4, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/32141-42-median-spill

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Test and CI

Which issue(s) this PR fixes:

Related to #32141 (the 4.2-dev portion). The issue also tracks main, so this PR does not close it.

What this PR does / why we need it:

On 4.2-dev, grouped MEDIAN can overwrite earlier result chunks once there are more than 8,192 groups. During group spill, omitted selection chunks can also be interpreted as selected results while aggregate group-state offsets remain misaligned.

  • Write numeric and decimal MEDIAN results to their corresponding chunks, and keep selected result, NULL, and group state in the same order during serialization.
  • Propagate allocation and intermediate-serialization errors without publishing a partial record; reset the MEDIAN DISTINCT hash when replacing decoded state. MEDIAN/window selection serialization now rejects an empty selection before writing because its historical short record is not decodable.
  • Avoid extending an already-full result chunk by zero rows, and advance the result cursor correctly when preallocated growth consumes multiple complete chunks. A failed aggregate growth requires freeing the executor rather than retrying it in place.
  • Avoid creating an empty trailing Group batch for duplicate-only input. Exercise the existing Vector checkpoint/rollback contract for failed appends.

Validation

  • Full aggexec and group package tests passed in normal and race modes on Go 1.26.4; the affected Vector package also passed race in UTC and America/New_York. Added boundary, partial Group → MergeGroup, NULL, malformed-selection, allocation-failure/cleanup, and fresh-executor regressions.
  • Real single-CN 4.2-dev service: 16,385 grouped numeric/decimal MEDIAN values matched in both resident and forced-spill modes; telemetry recorded 130 spill writes and 130 reloads. DISTINCT and empty-input controls passed. The checked-in mo-tester case and expected output passed twice, 16/16 each time, with teardown verified.
  • gofmt, go vet, and incremental golangci-lint 2.6.2 passed for the affected packages. Repository-pinned molint exited successfully; its two checkunsafe diagnostics in unchanged Vector tests are also present on the base.
  • A numeric MEDIAN frame with partial selection and NULL was encoded and decoded in both directions using the 4.2.0 codec source overlaid on 4.2-dev dependencies and the candidate; the frames matched. The affected codec, Vector, type, native, and module sources in the PR base also match v4.2.7. These checks do not establish full mixed-version execution.
  • Correct-result serializer microbenchmark against the PR base, three alternating samples per version: all selected 1.332 → 1.286 ms; one in 32 selected 58.61 → 56.64 µs; one in 256 selected 19.35 → 17.85 µs; one of 8,192 selected 13.56 → 12.36 µs. Allocation counts and bytes were unchanged. These are component measurements, not end-to-end SQL claims.

The nonempty frame layout is preserved. The runtime MEDIAN/window selected-zero API now returns invalid input; in-tree Group spill writes only nonempty buckets. Mixed-version remote partial/final execution, physical short-write injection, and SQL-level allocation-failure injection were not established.

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner November 4, 2026 07:33
@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 · superseded

Commit: 1f67ffd502ba5c6497325341a11795f0d317dc83

PR closed or head changed

@XuPeng-SH

XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 4c3cf4fb9745844193c8be7eb797875080e030ad

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: 4c3cf4fb9745844193c8be7eb797875080e030ad

Assessment: approve

The MEDIAN chunk, spill-selection and failure/reuse fixes preserve existing serialization and ownership boundaries. Shared validation adds bounded work without new stateful machinery. No actionable correctness or design issue remains in the frozen 4.2-dev scope.

Model: gpt-6.1-sol / max

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

Validation:

  • Full aggexec, group and vector suites passed normally and under race: 395 roots / 896 named results per mode, zero failures or skips, using Go 1.26.6 and freshly built native prerequisites.

  • All 12 focused roots and 12 adaptive race checks passed, totaling 1066 root repetitions. Merge-base controls and a targeted allocation/retry probe confirmed the repaired failures.

  • Build, vet, formatting and whitespace checks passed; timestamp tests passed with UTC and America/New_York.

  • Reused author-reported single-CN SQL/BVT results: 16/16 twice, with confirmed spill/reload.

  • Reviewed all 12 changed files and three discussion entries. Reconciled 30 validation receipts with retained logs and provenance in validation-audit.json; source remains clean.

Limitations:

  • Author SQL/BVT and microbenchmark raw logs were unavailable. No local full-service SQL, multi-CN, released-binary or performance run is claimed.

  • Relevant CI build, UT, SCA and coverage jobs remain pending in the supplied snapshot and were not counted as passes.

@XuPeng-SH

XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 348fbe281899e388fa4daa5da3ee714ff7cb10f1

Review discussion changed before publication; a fresh contextual review is queued.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed a3cfb7551431d7e9d87c33383fb13c44e3757873...348fbe281899e388fa4daa5da3ee714ff7cb10f1 against the current 4.2-dev base. Approve: no actionable blocking finding in this revision. This is a code-review approval, not a claim that every CI job has finished.

Design and correctness

  • Read all 13 changed files and traced the affected result-growth, serialization, Group/partial-to-MergeGroup, window and Vector consumers. This is a bounded bug fix within the existing aggregate/result owners; it does not need another state machine or serialization framework.
  • Numeric and decimal MEDIAN now advance the output chunk correctly. Selected result values, empty/NULL flags and aggregate state use the same selection and actual chunk offsets, including omitted leading/middle/trailing chunks. The nonempty frame layout remains unchanged.
  • Checked exact/full/partial chunk growth with preallocation, allocation errors, DISTINCT replacement decoding, and duplicate-only input after a full Group batch. Failed intermediate serialization does not publish ExtraBuf or advance the output cursor. The documented failed-growth contract is to free the executor, not retry the partially changed executor.
  • Rejecting a zero-selected runtime MEDIAN/window frame does not reject public empty-input SQL: in-tree spill callers serialize only nonempty buckets. Ordinary aggregate codecs retain their separate existing path.

Unhappy-path audit

Question Assessment
Q1 — ownership/cleanup Temporary serialization vectors have local cleanup; Group reset/free owns failed aggregate state; replacement decoding releases the old DISTINCT hash. No new competing cleanup owner found.
Q2 — termination No new blocking primitive, retry loop or background worker. Errors return through the existing operator cleanup path rather than publishing partial output.
Q3 — growth/performance Allocation failures are propagated and zero-row extension of a full chunk is avoided. Selection validation is bounded by the existing chunks/flags; no persistent cache or duplicate execution path is introduced.

Evidence and limits

  • Inspected regression oracles for 8,191/8,192/8,193/16,385 groups, numeric/decimal values, NULLs, sparse selections, invalid input, allocation/serialization failure, and partial/final aggregation; the SQL case compares resident and forced-spill results and includes DISTINCT/empty controls.
  • Independently verified the latest-head coverage UT job succeeded. Its log contains actual product go test execution, and the downloaded coverage artifact includes executed blocks in the changed aggregate, Group and Vector files. Shared build, SCA and the pessimistic multi-CN BVT check also report success; other UT/BVT jobs remain pending at review time.
  • The PR reports additional normal/race runs, repeated SQL/BVT, codec compatibility probes and serializer measurements. Those raw local receipts were not independently reproduced here; they are not represented as reviewer-run tests or proof of full mixed-version execution.
  • Both worktrees remain unchanged; git diff --check and Go 1.26.4 parsing/format checks passed. The overlapping Vector change with #32155 merges cleanly at source level; this is not a combined runtime test.
  • No inline review threads are present to leave unresolved. Earlier bot assessments concern an older head and were not treated as approval of this revision. The main-branch portion of #32141 remains outside this PR.

@XuPeng-SH

XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 348fbe281899e388fa4daa5da3ee714ff7cb10f1

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: 348fbe281899e388fa4daa5da3ee714ff7cb10f1

Assessment: approve

The fix keeps MEDIAN values, NULL flags and selected group state aligned across chunks and spills. It reuses existing serialization and cleanup owners; no actionable issue remains in the scoped 4.2-dev change.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed all 13 changed files, affected consumers, linked issue context and seven discussion items, including changes since the older approval.

  • Static scope/formatting audit and an independent numeric/Decimal oracle for all 16,385 SQL fixture groups passed. Receipt: checks/1793791184422054342-2.json; log: scope-audit.log.

  • Reused author-reported validation and exact-head review 5766933990, which reports executed product coverage. Older-head results were not relabelled as current checks.

  • Frozen CI snapshot: five successful, nine skipped, four in-progress and two neutral checks. Pending entries were not counted as passes.

Limitations:

  • No new local Go, SQL, race or performance execution; raw external validation artifacts were unavailable.

  • Reported codec-source probes do not establish full released-binary or multi-CN execution. The main-branch portion of issue 32141 remains outside this PR.

@aunjgr aunjgr 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.

Reviewed 348fbe2 against 4.2-dev. No blocking finding. MEDIAN advances the result-chunk index, selected result/NULL/group state keep identical chunk offsets, and omitted selection chunks no longer mean all rows. Group publication now propagates serialization errors before advancing its cursor or publishing ExtraBuf. The DISTINCT replacement hash and failed-growth cleanup contracts are explicit. Reviewed numeric/decimal chunk-boundary, partial Group-to-MergeGroup, selection, NULL, allocation-failure and resident/forced-spill SQL controls. Nonempty frame layout is retained; no mixed-version execution requirement is inferred. Ordinary bug-fix exemption applies. Reused exact-head green CI and author normal/race, codec and repeated SQL/BVT evidence; no local full-suite rerun.

@XuPeng-SH

XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 348fbe281899e388fa4daa5da3ee714ff7cb10f1

New discussion was assessed; the previous review remains unchanged.

This branch was previously deployed

1 inactive deployment
ci — 348fbe28 Deployed Nov 4, 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 kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants