Skip to content

fix(agg): return DOUBLE for decimal variance and stddev - #30228

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/decimal-statistics-double-30179
Oct 14, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/decimal-statistics-double-30179

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 14, 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:

DECIMAL variance and standard-deviation aggregates computed in float64 but returned DECIMAL128 with an input-dependent scale. For DECIMAL(38,18) values 1e-18, 2e-18 and 3e-18, both variances became zero and standard deviations were rounded to 1e-18. These functions now return DOUBLE, matching the MySQL numeric result domain and preserving approximately 6.666666666666667e-37, 1e-36, 8.16496580927726e-19 and 1e-18.

The shared return-type helper and DECIMAL64/128 executor factories now use float64 results. Native decimal arguments, exact-origin centering, stable recurrence, DISTINCT identity and legacy/current partial-state layouts retain their contracts. MORPC v113 gates the changed result ABI at worker placement, actual destination validation, aggregate decoding and persisted-expression admission; legacy DECIMAL-typed expressions require rebinding. Native Group/MergeGroup descriptors explicitly carry the DOUBLE result type, including partial and nested scopes. Receivers reject missing or incompatible result contracts before constructing operators, and actual sends recheck descriptor requirements together with expression requirements using one destination observation. Temporal numeric operands follow the same DOUBLE result domain. Explicit DECIMAL result casts use the existing DOUBLE cast semantics, covered with an independent literal-cast control.

Validation:

  • Executed the pre-fix reproduction through the current executor and MySQL protocol, including the explicit DOUBLE input control.
  • Focused regressions cover tiny values at DECIMAL64 scale 18, DECIMAL128 scales 18/38, DECIMAL256 scale 30, large exact offsets, finite wide variance, NULL/cardinality, DISTINCT, merge and serialized-state continuation.
  • All six affected Go packages passed their complete normal test suites; the added exact-origin QA cases passed. Incremental gofmt, go vet and golangci-lint passed. Native and service builds passed on Go 1.27.1, macOS arm64.
  • Before the receiver-only admission correction, nine SQL case groups passed normal comparison twice on the same fresh two-CN test instance: 1208/1208 per run, with no test schemas remaining between or after runs. Coverage includes metadata, CTAS aliases, grouped/window/SQL PREPARE execution and forced AP aggregation. The physical plan exposed two Remote scopes and the executed result fields were DOUBLE.
  • Updated DECIMAL statistical result snapshots only; finite overflow replacements were checked against independent high-precision decimal variance calculations.
  • After the receiver admission correction, its real decodeScope regressions and complete compile package passed; vet/lint and the service rebuild passed. The affected forced-AP case passed 26/26 twice on the rebuilt service with verified teardown.
  • Native descriptor regressions cover all four statistical functions, DECIMAL64/128, Group/MergeGroup, nested pipelines, DISTINCT receive, missing/wrong result types, unknown/old local floors, destination rollback after placement, actual encode/decode and one shared probe for combined expression/descriptor requirements. Complete compile and pipeline packages passed with the CGo wrapper (-count=1); incremental gofmt, vet and lint passed. Generated pipeline bindings reproduce exactly.
  • gpt-6-astra / medium completed the design and final overall review gates. The final candidate has no unresolved material findings.

Finalization removes float-to-decimal conversion work and uses 8-byte DOUBLE result cells. Consumers requesting DECIMAL results can explicitly cast them; ordinary float approximation and DOUBLE-to-DECIMAL cast rounding continue to apply. The previous head passed remote build, UT, SCA, coverage and both active multi-CN BVT lanes; remote CI for this descriptor repair is pending. Reporter verification of #30179 is expected after merge.

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

Copy link
Copy Markdown
Contributor

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

Commit: 8b92a0417a5a796ce9ea0dac972899d90e0c0b50

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: 8b92a0417a5a796ce9ea0dac972899d90e0c0b50

Assessment: request_changes

Reviewed the complete 22-file delta. Shared DOUBLE finalization appropriately fixes decimal rounding without changing accumulation or partial-state layout. Two reproduced native aggregate protocol gaps leave mixed-version execution unsafe.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

  • P1 pkg/sql/compile/remoterun.go:2101: A pre-113 coordinator sends a final decimal statistical Group descriptor to a protocol-113 receiver during rolling upgrade.
    Impact: The receiver silently changes the physical result ABI from DECIMAL128 to DOUBLE. Carry and validate the native descriptor's result contract, rejecting incompatible legacy descriptors or preserving their expected output.
    Evidence: The new guard checks only the receiver's runtime version. Native descriptors omit the aggregate result type, so expression-level legacy rejection does not apply. TestReviewLegacyFinalDecimalDescriptorExecution passed a legacy descriptor through decodeScope and real Group execution: its DECIMAL128 projection emitted DOUBLE 6.666666666666667e-37. Retained descriptor-execution-v2.log and receipt checks/1792010833029645810-3.json record the failed ABI assertion.

  • P1 pkg/sql/compile/expression_destination_protocol.go:51: A decimal statistical aggregate's destination reports protocol 113 during placement but protocol 112 when its native Group/MergeGroup scope is serialized.
    Impact: The send-time gate permits execution on an incompatible worker, which can return DECIMAL results to a coordinator expecting DOUBLE. Include native aggregate descriptors in the shared destination requirements.
    Evidence: constructGroup lowers the function expression into an aggregate ID and argument expressions. RequiredRemoteExpressionFeatures consequently misses its changed result contract; validateRemoteAggregateProtocol checks only the sender's local version. TestReviewDecimalDescriptorSendFloor reproduced successful encodeRemoteScope calls with zero destination probes for all four Group/MergeGroup × DECIMAL64/128 combinations. See descriptor-probes.log and checks/1792010627780419412-4.json.

Validation:

  • Isolation preflight passed. Independently reconciled 192 native source inputs, 62 artifact hashes, and the repository build-owner command/receipt/log.

  • All six full affected Go packages passed with -count=1 and the supplied test-exec: defines, pb/plan, colexec/aggexec, plan/function, plan, and compile. Receipt: checks/1792010639292012257-5.json; log: affected-packages.log.

  • Production encode/decode counterexamples and native Group execution reproduced both findings. Diagnostic overlays preserved the source checkout.

  • Independently verified 12 large-variance SQL snapshot values using 110-digit Decimal arithmetic; this was not SQL execution.

  • The exact-head CI snapshot reports successful build, Ubuntu UT, SCA, coverage, proxy BVT and pessimistic multi-CN BVT; upgrade jobs were skipped.

  • Commands, source fingerprints, exit receipts, log hashes and diagnostic-source hashes are reconciled in /home/xupeng/.local/state/mo-bot/jobs/1a5ed343a450b06045268db6/attempt-1/evidence-audit.json. Complete review record: review-record.json in the same directory.

Limitations:

  • No mixed-binary cluster or SQL/client reproduction was run; the findings use production protocol boundaries and native operator execution.

  • Performance assessment is structural: finalization removes decimal formatting/parsing and halves result payload width; receive validation adds a linear pipeline walk. No throughput benchmark was performed.

  • No retained worker validation gate, raw CI case logs, or full linked-issue body was supplied. Initial diagnostic fixture/selector failures were corrected and excluded from product findings.

@XuPeng-SH

XuPeng-SH commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: a7809b40685d401f10abb921fd0b45333cfb79a3

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

Assessment: approve

Reviewed the complete 24-file delta. Shared DOUBLE finalization fixes precision loss while preserving native accumulation and partial-state formats. Explicit aggregate result metadata and fresh destination checks close both prior protocol findings. The design reuses existing owners and removes decimal conversion overhead without adding row-level work. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

Validation:

  • Focused current-head tests passed: 6 top-level tests and 112 subtests across compile, protobuf-plan and SQL-plan packages, covering placement, descriptor encoding/decoding, version rollback and persisted contracts.

  • Reconciled commands, clean-head fingerprints, exit receipts and retained logs in attempt-1/evidence-audit.json. Isolation preflight passed; 192 native inputs and 62 artifacts matched build-owner provenance.

  • Verified generated protobuf changes, formatting and diff checks. Reconciled retained independent arithmetic checks for 12 SQL expectations against byte-identical inputs.

  • Frozen exact-head CI reports successful shared build, Ubuntu unit tests, arm64 static analysis, coverage and proxy/pessimistic multi-CN BVT.

Limitations:

  • No mixed-binary upgrade cluster or performance benchmark was run; upgrade CI was skipped. Compatibility validation used production encode/decode entry points with controlled protocol responses.

  • Raw author BVT counts and the linked issue's full body were unavailable; assessment uses the frozen PR contracts, comments and CI snapshot.

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

mergify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-14 23:08 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-14 23:26 UTC · at 8b9fc96ad5858932ad343d80ed70914963e28f4c

This pull request spent 18 minutes 25 seconds in the queue, with no time running CI.

Reason

Pull request #30228 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.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

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

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 8c8f829 into matrixorigin:main Oct 14, 2026
@mergify mergify Bot added dequeued and removed queued labels Oct 14, 2026
cpegeric added a commit to cpegeric/matrixone that referenced this pull request Oct 15, 2026
Main took MORPCVersion113 for DECIMAL variance/stddev DOUBLE results
(matrixorigin#30228). The IndexSearchScan search knobs move to MORPCVersion114 (latest);
vectorscan.SearchKnobsProtocolVersion points at it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was previously deployed

1 inactive deployment
ci — 8b9fc96a Deployed Oct 15, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working kind/test-ci 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