Skip to content

fix: avoid double rounding in decimal scaling - #28785

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/decimal-scale-double-rounding-28772
Sep 12, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/decimal-scale-double-rounding-28772

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #28772

Summary

  • Truncate intermediate DECIMAL scale-down chunks and apply half-up rounding only once on the final chunk.
  • Preserve D256 signed-minimum magnitude during scale-down without a wrapping left shift.
  • Apply the same final-only rounding rule to D128/D256 multiplication scale-down helpers.
  • Add focused Go and SQL regression coverage, including persisted DML results.

Validation on 10.222.1.55

  • Full CGo-wrapper package tests passed for pkg/container/types and pkg/sql/plan/function.
  • decimal_scale_rounding BVT: 8/8 passed.
  • Multi-step helper microbenchmark: zero allocations, no material regression (D128 flat, D256 about 1.6% faster).

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

Reviewed the full six-file diff at head 577cd036ddaf4f741cf89f0d04340074f63b7bad. I found no blocking issue. Truncating intermediate base-10 chunks and applying half-up only to the final chunk preserves the single-round result; the signed-minimum D128/D256 cases and extreme negative-scale guards are handled without an intermediate overflow. The ordinary one-chunk path remains unchanged, and the multi-chunk helpers add no allocation or shared state. Exact-head UT, SCA, coverage, and relevant BVT jobs are green. Follow-up test hardening (non-blocking): a compact big.Int differential table around scale chunk boundaries and positive/negative exact ties would give broader arithmetic coverage.

@XuPeng-SH
XuPeng-SH merged commit 792a065 into matrixorigin:main Sep 12, 2026
16 of 20 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/decimal-scale-double-rounding-28772 branch September 12, 2026 14:57
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Fixes matrixorigin#28772

## Summary
- Truncate intermediate DECIMAL scale-down chunks and apply half-up
rounding only once on the final chunk.
- Preserve D256 signed-minimum magnitude during scale-down without a
wrapping left shift.
- Apply the same final-only rounding rule to D128/D256 multiplication
scale-down helpers.
- Add focused Go and SQL regression coverage, including persisted DML
results.

## Validation on 10.222.1.55
- Full CGo-wrapper package tests passed for pkg/container/types and
pkg/sql/plan/function.
- decimal_scale_rounding BVT: 8/8 passed.
- Multi-step helper microbenchmark: zero allocations, no material
regression (D128 flat, D256 about 1.6% faster).

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Fixes matrixorigin#28772

## Summary
- Truncate intermediate DECIMAL scale-down chunks and apply half-up
rounding only once on the final chunk.
- Preserve D256 signed-minimum magnitude during scale-down without a
wrapping left shift.
- Apply the same final-only rounding rule to D128/D256 multiplication
scale-down helpers.
- Add focused Go and SQL regression coverage, including persisted DML
results.

## Validation on 10.222.1.55
- Full CGo-wrapper package tests passed for pkg/container/types and
pkg/sql/plan/function.
- decimal_scale_rounding BVT: 8/8 passed.
- Multi-step helper microbenchmark: zero allocations, no material
regression (D128 flat, D256 about 1.6% faster).

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Fixes matrixorigin#28772

## Summary
- Truncate intermediate DECIMAL scale-down chunks and apply half-up
rounding only once on the final chunk.
- Preserve D256 signed-minimum magnitude during scale-down without a
wrapping left shift.
- Apply the same final-only rounding rule to D128/D256 multiplication
scale-down helpers.
- Add focused Go and SQL regression coverage, including persisted DML
results.

## Validation on 10.222.1.55
- Full CGo-wrapper package tests passed for pkg/container/types and
pkg/sql/plan/function.
- decimal_scale_rounding BVT: 8/8 passed.
- Multi-step helper microbenchmark: zero allocations, no material
regression (D128 flat, D256 about 1.6% faster).

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DECIMAL scale reduction double-rounds values below halfway in ROUND, CAST, and DML

2 participants