Repository navigation
fix: widen decimal arithmetic to Decimal256 - #28629
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? |
aptend
left a comment
There was a problem hiding this comment.
Deep review of exact head ac9cee1 (merge-base 9a07655). I read the linked issue, the only issue comment, and checked all review/inline/thread history (there are no prior reviews or threads), then traced the complete six-file diff through overload selection, binder-inserted casts, Decimal128/256 kernels, comparison narrowing, affine SUM rewriting, and downstream published result types. The same-type 39/40-digit cases are correctly widened and the comparison/affine adaptations are directionally sound, but three uncovered boundaries remain blocking: mixed numeric operands still stay on Decimal128, explicit casted string literals can generate an invalid width<scale implicit cast, and products beyond the public 65-digit precision can escape inside a value tagged DECIMAL(65). Native dependencies were built. Full exact-head ./pkg/sql/plan and ./pkg/sql/plan/function tests pass, as do the changed focused tests under -race. Three review-only counterexamples reproduced the findings and were removed; git diff --check is clean.
aptend
left a comment
There was a problem hiding this comment.
Re-reviewed the complete diff, all review history and resolved threads, plus the delta since my prior review at ac9cee1, against exact head 308db3c. The three previously reported Decimal/integer, explicit-cast/literal, and published-precision issues are closed. One exact numeric coercion domain is still omitted and reproduces the same overflow this PR is intended to eliminate. Exact-head CI is green, but it does not cover this direct BIT/DECIMAL pair.
…w-fix # Conflicts: # pkg/sql/plan/base_binder.go
|
Pushed 83222be, merging current upstream/main (bb358ea) and restarting CI. The reported TestIssue28313EmptyRemoteDispatch failure was a 180-second context timeout in the full Ubuntu UT run; the Decimal change does not touch dispatch/shuffle lifecycle code. On the updated head, the exact regression passes three consecutive runs, and the affected plan/function packages pass as well. |
aptend
left a comment
There was a problem hiding this comment.
Deep re-review completed on exact head ae7fd9949383d80de87092894865cfa619f80ab3 against exact merge-base 07fdd4ae0f80f287b93fc4b525fd296d5617abc7. I read the complete review and inline-comment history, author replies, issue discussion, and resolved/unresolved thread state; compared the delta after my prior reviewed head 308db3cc5d93480beba3182b6d984f873b58b66a; and rechecked the complete arithmetic resolver, binder casts, Decimal256 kernels/precision checks, comparison and affine-SUM consumers, Substrait boundary, tests, and BVT expectations. My remaining BIT/DECIMAL blocker is closed in code: BIT is now treated as a 20-digit exact unsigned domain for the widening decision, both operand orders produce Decimal256 casts, and +/* publish 39/58-digit Decimal256 results. I independently built the plan-level BIT(64)/DECIMAL(38,0) + and * shapes and confirmed their physical arguments/results are Decimal256. The earlier mixed integer/decimal, explicit-cast/weak-literal, and 65-digit runtime-boundary findings remain closed. Validation on this exact head: full pkg/sql/plan, pkg/sql/plan/function, and pkg/sql/plan/substrait suites pass with repository CGO/third-party artifacts; git diff --check passes; all required CI checks are green. No remaining blocking issue found.
…w-fix # Conflicts: # pkg/sql/plan/function/list_operator.go
|
Resolved the latest main conflict at 0a490af after preserving the remote branch updates and merging upstream/main through 2ea4ec2. The list_operator conflict now retains both dispatch layers: main mixed signed/unsigned integer domain handling runs first, then this PR applies widened Decimal256 operand selection for decimal arithmetic. This also integrates main Decimal256 high-scale multiplication coverage without dropping either behavior. Local validation passed for container/types, plan/function, plan, compile, and external, followed by the complete native-provenance-aware make build. |
Merge Queue Status
This pull request spent 39 minutes 36 seconds in the queue, with no time running CI. Waiting for any of
All conditions
ReasonPull request #28629 has been dequeued Queue conditions are not satisfied:
HintYou 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. Requeued — the merge queue status continues in this comment ↓. |
aunjgr
left a comment
There was a problem hiding this comment.
[P2] Correct the newly accepted wrapped decimal multiplication result.
At test/distributed/cases/dtype/decimal.result:1306-1310, this PR replaces an overflow with three successful values that are mathematically incorrect. The fixture declares col2 DECIMAL(19,0), and its first value is 1235467899687894561. For:
SELECT col2 * -2733892455124775.7851878942123454 FROM decimal19;
the first exact product is:
-3377636369505588272411432821735887.9920303797133694
but the new expected result is:
-12929400140562083461.4885988496007550
The exact coefficient has 50 digits and fits the advertised DECIMAL(51,16), so this is not an allowed overflow or rounding difference. The expected value exactly equals col2 multiplied by the signed low 64 bits of the literal's scaled coefficient: int64(-27338924551247757851878942123454) = -104651850070959550, divided by 10^16. The other two newly accepted rows follow the same truncated coefficient.
Please correct the oracle using independent arbitrary-precision arithmetic and verify the exact-head SQL execution. If execution produces the checked-in values, fix the constant conversion/widened execution path before accepting the result. Add a focused positive/negative wide-fractional-literal case and literal-versus-typed-column control; resolver/type-only and scale-zero multiplication tests cannot catch this.
Reviewed all 16 changed files and traced original-domain widening, explicit-cast/weak-literal handling, physical argument casts, Decimal256 precision checks, comparison/affine consumers and tests. Prior mixed integer/BIT-domain fixes are retained. This finding is independently proven against the checked-in fixture/oracle with exact integer arithmetic; I have not run a fresh SQL reproduction or established the precise runtime truncation site, and am not claiming that a generated expected file proves runtime behavior. Current-head UT and BVT were still running at submission preflight. No other confirmed blocker found.
|
Thanks — confirmed on exact head: the checked-in values were the low-64-bit wrapped products. Root cause was in the Decimal256 fast-path classifiers, not in literal parsing or Decimal128→Decimal256 casting. Fixed in c9bdffc:
Exact-head validation:
|
…w-fix # Conflicts: # pkg/sql/plan/substrait/tpch_test.go
|
Resolved the conflict with current Conflict decision in
New exact head: Validation passed:
|
aunjgr
left a comment
There was a problem hiding this comment.
No blocking finding at this revision.
Compared the patch series against my previous reviewed head: all nine non-merge patches are unchanged after the main merge. Rechecked the decimal widening/cast/precision boundaries, comparison non-narrowing, affine-result restoration and changed binder surroundings. The prior full source/test/BVT review remains applicable, and exact-head CI is green.
Existing review and CI evidence reused; no new local test execution or performance claim.
Merge Queue Status
This pull request spent 25 minutes 38 seconds in the queue, with no time running CI. Waiting for any of
All conditions
ReasonPull request #28629 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.
HintYou 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. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #28584
What this PR does / why we need it:
Testing
go test ./pkg/container/types ./pkg/sql/plan/function ./pkg/sql/plan ./pkg/sql/compile ./pkg/sql/colexec/external -count=1make build