Skip to content

implement:implements full support for DECIMAL(M, D) with M up to 65 - #23916

Merged
mergify[bot] merged 13 commits into
matrixorigin:mainfrom
robll-v1:issue/23910
Mar 26, 2026
Merged

mergify[bot] merged 13 commits into
matrixorigin:mainfrom
robll-v1:issue/23910

Conversation

@robll-v1

@robll-v1 robll-v1 commented Mar 20, 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:

issue #23910

What this PR does / why we need it:

This PR extends DECIMAL(M, D) support up to M = 65 by wiring the decimal256 type through parser, planner, execution, output, and test coverage, and then closes the remaining correctness and performance gaps found during review.

What was added across the branch

Commit 1 — d9a6e16: Basic query path

  • Parser accepts DECIMAL(M) up to M = 65 and routes M > 38 to T_decimal256
  • Decimal256 parse/format, float/string/int cast, encode/decode, compare, and vector infrastructure wired up
  • DDL, INSERT, SELECT, CAST('...' AS DECIMAL(65,30)), and frontend output working
  • BVT case added: test/distributed/cases/dtype/decimal_256.test

Commit 2 — fa7995f: Core operator and function support

  • Arithmetic: +, -, *, /, %, div
  • Aggregation: SUM, AVG, MIN, MAX
  • Math functions: ABS, SIGN, CEIL, FLOOR, ROUND, TRUNCATE
  • Predicates: =, !=, <, >, <=, >=, <=>, BETWEEN, IN, NOT IN
  • Conditional expressions: CASE WHEN, COALESCE, IFF
  • Sorting: ORDER BY
  • Type coercion and return-type deduction updated for decimal256

Commit 3 — 8f5453d: Reviewer follow-up fixes

  • Fixed decimal256 arithmetic null propagation under selectList
  • Reworked decimal256 FROM_UNIXTIME paths to avoid float64 precision loss
  • Added focused regression tests for both paths

Commit 4 — 1195159: Edge-case correctness fixes

  • Added missing decimal256 source casts for bit/int/uint
  • Changed decimal256 comparison to return scale-overflow errors explicitly instead of silently ignoring Scale() failures
  • Added focused tests for cast and compare overflow handling

Commit 5 — 18e35cf: Decimal256 format hot-path optimization

  • Replaced Decimal256.Format() big.Int-based formatting with a fixed-buffer decimal path built on Div256/Mod256
  • This removes the avoidable big.Int allocations from result output/export paths while preserving existing formatting semantics
  • Added format edge-case tests and a micro-benchmark

Validation

  • GOCACHE=/tmp/go-build-23910 go test ./pkg/container/types -count=1
  • GOCACHE=/tmp/go-build-23910 go test ./pkg/container/types -run '^$' -bench '^BenchmarkDecimal256Format$' -benchmem -count=1
  • GOCACHE=/tmp/go-build-23910 go test ./pkg/frontend -run '^$' -count=1
  • GOCACHE=/tmp/go-build-23910 go test ./pkg/sql/compile ./pkg/cdc ./pkg/iscp ./pkg/vm/engine/tae/common -run '^$' -count=1
  • GOCACHE=/tmp/go-build-23910 SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include CPLUS_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 make build CMAKE_POLICY_VERSION_MINIMUM=3.5
  • Runtime verification via MySQL on standalone launch:
    • created a DECIMAL(65,30) table
    • inserted large positive / negative / zero decimal256 values
    • verified formatted query output
  • mo-tester gate:
    • cd /Users/moukeyu/mo-tester
    • ./run.sh -p /Users/moukeyu/matrixone-23910/test/distributed/cases/dtype/decimal_256.test -g
    • [SUMMARY] COST : 0s, TOTAL :10, SUCCESS : 10, FAILED :0, IGNORED :0, ABNORAML :0, SUCCESS RATE : 100%

Known Risks and Limitations

  1. ZoneMap pruning is still disabled for decimal256 columns
  • In pkg/vm/engine/tae/index/zm.go, UpdateZM and BatchUpdateZM skip T_decimal256
  • Correctness is not affected
  • Large-table filtering on decimal256 cannot use min/max block pruning yet
  • A proper fix needs a zonemap layout/storage change rather than a small function-level patch
  1. Some low-frequency decimal256 surfaces are still not extended
  • Window functions are not wired for decimal256
  • Bitwise family / BIT_AND / BIT_OR / BIT_XOR / OCT are not implemented for decimal256
  • LEAST / GREATEST / SERIAL / SERIAL_EXTRACT are still unsupported for decimal256
  1. FROM_UNIXTIME behavior for very large numeric literals changed after decimal256 widened the literal typing path
  • The decimal256 execution path itself is now precise
  • The remaining change is compatibility behavior for previously-overflowing large numeric literals

robll-v1 and others added 2 commits March 20, 2026 14:27
Extend the DECIMAL(65,30)/decimal256 type to cover all core numeric
operators and functions:

- Arithmetic: +, -, *, /, %, div with scale-aware Decimal256.Add/Sub/Mul/Div/Mod methods
- Aggregation: SUM, AVG, MIN, MAX with dedicated decimal256 exec paths
- Math functions: ABS, SIGN, CEIL, FLOOR, ROUND, TRUNCATE
- Predicates: =, !=, <, >, <=, >=, <=>, BETWEEN, IN, NOT IN
- Conditional: CASE WHEN, COALESCE, IFF
- Sorting: ORDER BY via pkg/sort
- Implicit type coercion rules updated in type_check.go
- Return type inference for all arithmetic operators updated in list_operator.go

All affected unit tests pass. BVT cases updated and verified with mo-tester (10/10).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@robll-v1
robll-v1 requested a review from a user March 20, 2026 08:29
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@robll-v1

Copy link
Copy Markdown
Contributor Author

I fixed the clear issue-level gaps in this round:

  1. decimal256 cast support
    I added the missing decimal256 source casts for bit/int/uint, so decimal256 is no longer missing the basic
    integral cast paths that other decimal types already expose.

  2. silent scale-overflow handling in decimal256 comparison
    I changed the decimal256 compare path to return the scale overflow error explicitly instead of ignoring the
    Scale() error and continuing with a potentially wrong comparison result.

I also added focused tests for both changes.

ZoneMap bypass for decimal256 is a real performance limitation, but I did not address it in this patch. The
current zonemap raw layout cannot safely store 32-byte decimal256 values, so fixing it cleanly needs a
storage/index layout change rather than a small function-level patch.

The cast-gap report is only partially applicable now. I fixed the missing decimal256 integral cast paths
(bit/int/uint). I did not extend decimal256 to date/datetime/time/timestamp/year in this patch, because
that would widen the temporal cast surface beyond the scoped fix and is better handled as a follow-up
behavior discussion.

Decimal256 Format() using big.Int is a valid performance concern. I agree it is worth optimizing, but I
treated it as a follow-up perf improvement rather than a correctness blocker for issue 23910.

I do not see evidence that Decimal128.Mod128 behavior changed in this branch. The branch adds decimal256-
specific helpers, but Decimal128.Mod128 itself was not changed here.

FROM_UNIXTIME behavior did change for very large numeric literals after decimal256 widened the literal
typing path. I left that behavior as-is for now because it is a compatibility discussion, not a clear
correctness bug in the decimal256 execution path itself.

There is still duplicated decimal256 code across the decimal64/128/256 paths. That is real technical debt,
but I kept this patch scoped to correctness/compatibility fixes instead of refactoring the whole decimal
family.

Some result-file churn in this branch is broader than the core decimal256 behavior change. I agree that is
test hygiene noise, but it does not affect runtime correctness.

robll-v1 and others added 4 commits March 25, 2026 13:03
The resultType-based early return handles cross-type promotions
(e.g. decimal128 + int64 → decimal256), while the paramType switch
case handles inputs already typed as decimal256. Both are reachable.

Co-authored-by: Copilot <[email protected]>
@mergify

mergify Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-03-26 08:36 UTC · Rule: main
  • 🚫 Left the queue — 2026-03-26 08:36 UTC · at 0c408d2ffe43a9ff33e8aed55e570a75321fa312

This pull request spent 6 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

expected head sha didn’t match current head ref.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

@mergify

mergify Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-03-26 09:33 UTC · Rule: main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-03-26 09:33 UTC · at c2bfa696018d853c0563722f37697e383193493e

This pull request spent 10 seconds in the queue, with no time running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage

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

kind/feature size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants