Repository navigation
fix(decimal): handle Decimal256 wide multiplication scale reduction - #28878
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? |
5579166 to
beb53b3
Compare
|
Rebased the base-defect fix (Decimal256 wide multiplication scale reduction, including the related high-scale guard) onto latest |
|
Follow-up after GPT-6 medium review:
Pushed as 8125376. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
GPT-6 medium deep review at exact head 8125376.
I reviewed the Decimal256 scale-reduction path and its logical-range guard; I found no verified correctness blocker on this head. The exact-head CI is green. The available artifact does not list individual timings for the new tests, so I cannot certify their per-test time against the 45-second limit.
…atrixorigin#28878) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28875 Fixes matrixorigin#28876 ## What this PR does / why we need it: `d256Mul` previously rejected a raw 256-bit product before applying the target-scale reduction. High-scale values can have a wider unscaled product while their rounded result is representable; this caused the deterministic Decimal256 failures exposed by matrixorigin#28825. The same dispatch also indexed the two-limb `scalePow10Factors` helper out of bounds for valid scale reductions greater than 38 (for example `DECIMAL(76,76)`), which could panic the process. This change keeps the existing int32/int64 and ordinary 256-bit paths for the supported scale range. Raw-overflow recovery and reductions above 38 use an allocation-free 8-limb (512-bit) product, complete discarded-remainder accumulation, one round-half-up, and a final signed Decimal256 range check. Failure returns the existing controlled Decimal256 overflow error and does not overwrite the destination. `Mul256`'s raw integer contract is unchanged. ## Test plan - `./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestD256Mul(ScaledRawOverflow|ScaledFallbackChunkBoundaries|HighScaleSmallValues|WideMatchesBigInt)' ./pkg/sql/plan/function` - Same focused matrix with `-race`. - Full `./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=220s ./pkg/sql/plan/function`. - Independent `math/big` oracle covers positive/negative values, below/exact/above-half and carry-to-overflow, 38/39/57/76 scale chunks, raw-overflow/final-fit and final-overflow, vector/vector and broadcast layouts, partial/all NULL rows, and 256 random 512-bit products. - `go vet ./pkg/sql/plan/function` with the repository CGo include/link flags, `golangci-lint run ./pkg/sql/plan/function`, `license-eye header check`, `git diff --check`. - Existing benchmark medians for the ≤38 fast/scaled paths remained within run-to-run noise on the same host; the new wide path is only selected for raw-overflow recovery or scale reductions above 38. Validation was run after rebasing onto `origin/main` `60248a0895`. CI was not awaited per the task instruction.
…atrixorigin#28878) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28875 Fixes matrixorigin#28876 ## What this PR does / why we need it: `d256Mul` previously rejected a raw 256-bit product before applying the target-scale reduction. High-scale values can have a wider unscaled product while their rounded result is representable; this caused the deterministic Decimal256 failures exposed by matrixorigin#28825. The same dispatch also indexed the two-limb `scalePow10Factors` helper out of bounds for valid scale reductions greater than 38 (for example `DECIMAL(76,76)`), which could panic the process. This change keeps the existing int32/int64 and ordinary 256-bit paths for the supported scale range. Raw-overflow recovery and reductions above 38 use an allocation-free 8-limb (512-bit) product, complete discarded-remainder accumulation, one round-half-up, and a final signed Decimal256 range check. Failure returns the existing controlled Decimal256 overflow error and does not overwrite the destination. `Mul256`'s raw integer contract is unchanged. ## Test plan - `./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestD256Mul(ScaledRawOverflow|ScaledFallbackChunkBoundaries|HighScaleSmallValues|WideMatchesBigInt)' ./pkg/sql/plan/function` - Same focused matrix with `-race`. - Full `./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=220s ./pkg/sql/plan/function`. - Independent `math/big` oracle covers positive/negative values, below/exact/above-half and carry-to-overflow, 38/39/57/76 scale chunks, raw-overflow/final-fit and final-overflow, vector/vector and broadcast layouts, partial/all NULL rows, and 256 random 512-bit products. - `go vet ./pkg/sql/plan/function` with the repository CGo include/link flags, `golangci-lint run ./pkg/sql/plan/function`, `license-eye header check`, `git diff --check`. - Existing benchmark medians for the ≤38 fast/scaled paths remained within run-to-run noise on the same host; the new wide path is only selected for raw-overflow recovery or scale reductions above 38. Validation was run after rebasing onto `origin/main` `60248a0895`. CI was not awaited per the task instruction.
…atrixorigin#28878) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28875 Fixes matrixorigin#28876 ## What this PR does / why we need it: `d256Mul` previously rejected a raw 256-bit product before applying the target-scale reduction. High-scale values can have a wider unscaled product while their rounded result is representable; this caused the deterministic Decimal256 failures exposed by matrixorigin#28825. The same dispatch also indexed the two-limb `scalePow10Factors` helper out of bounds for valid scale reductions greater than 38 (for example `DECIMAL(76,76)`), which could panic the process. This change keeps the existing int32/int64 and ordinary 256-bit paths for the supported scale range. Raw-overflow recovery and reductions above 38 use an allocation-free 8-limb (512-bit) product, complete discarded-remainder accumulation, one round-half-up, and a final signed Decimal256 range check. Failure returns the existing controlled Decimal256 overflow error and does not overwrite the destination. `Mul256`'s raw integer contract is unchanged. ## Test plan - `./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestD256Mul(ScaledRawOverflow|ScaledFallbackChunkBoundaries|HighScaleSmallValues|WideMatchesBigInt)' ./pkg/sql/plan/function` - Same focused matrix with `-race`. - Full `./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=220s ./pkg/sql/plan/function`. - Independent `math/big` oracle covers positive/negative values, below/exact/above-half and carry-to-overflow, 38/39/57/76 scale chunks, raw-overflow/final-fit and final-overflow, vector/vector and broadcast layouts, partial/all NULL rows, and 256 random 512-bit products. - `go vet ./pkg/sql/plan/function` with the repository CGo include/link flags, `golangci-lint run ./pkg/sql/plan/function`, `license-eye header check`, `git diff --check`. - Existing benchmark medians for the ≤38 fast/scaled paths remained within run-to-run noise on the same host; the new wide path is only selected for raw-overflow recovery or scale reductions above 38. Validation was run after rebasing onto `origin/main` `60248a0895`. CI was not awaited per the task instruction.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #28875
Fixes #28876
What this PR does / why we need it:
d256Mulpreviously rejected a raw 256-bit product before applying thetarget-scale reduction. High-scale values can have a wider unscaled product
while their rounded result is representable; this caused the deterministic
Decimal256 failures exposed by #28825. The same dispatch also indexed the
two-limb
scalePow10Factorshelper out of bounds for valid scale reductionsgreater than 38 (for example
DECIMAL(76,76)), which could panic the process.This change keeps the existing int32/int64 and ordinary 256-bit paths for the
supported scale range. Raw-overflow recovery and reductions above 38 use an
allocation-free 8-limb (512-bit) product, complete discarded-remainder
accumulation, one round-half-up, and a final signed Decimal256 range check.
Failure returns the existing controlled Decimal256 overflow error and does not
overwrite the destination.
Mul256's raw integer contract is unchanged.Test plan
./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestD256Mul(ScaledRawOverflow|ScaledFallbackChunkBoundaries|HighScaleSmallValues|WideMatchesBigInt)' ./pkg/sql/plan/function-race../.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=220s ./pkg/sql/plan/function.math/bigoracle covers positive/negative values, below/exact/above-half and carry-to-overflow, 38/39/57/76 scale chunks, raw-overflow/final-fit and final-overflow, vector/vector and broadcast layouts, partial/all NULL rows, and 256 random 512-bit products.go vet ./pkg/sql/plan/functionwith the repository CGo include/link flags,golangci-lint run ./pkg/sql/plan/function,license-eye header check,git diff --check.Validation was run after rebasing onto
origin/main60248a0895. CI was not awaited per the task instruction.