Skip to content

[Compatibility]: MOD derives MySQL-incompatible DECIMAL result precision with integer operands #30157

Closed

Description

@Ariznawlll

Environment

  • MatrixOne: 8.0.30-MatrixOne-v1.3.0, built from 2ce4e58af6f03b943ee288ffad81012766cf830a
  • MySQL: 8.0.46
  • Topology: local single CN / TN / LogService
  • Verification date: 2026-10-14

The official main commit checked during this run is a53390c57de48ac280249ff0e88831e502e20fb0; its MOD return-type callback in pkg/sql/plan/function/list_operator.go is unchanged from the tested source. The test server itself remains pinned to the commit above.

Problem

For supported MOD / % expressions combining a DECIMAL operand with an integer operand, MatrixOne can expose a DECIMAL result precision different from MySQL. The mismatch is persisted by CTAS and views and propagates through CASE and COALESCE. The remainder values are the same in the tested rows; this report concerns result-schema / expression metadata compatibility, not an incorrect remainder value.

Minimal reproduction:

CREATE TABLE src(d DECIMAL(10,3), i INT);
INSERT INTO src VALUES (1.234, 2), (-1.234, -2), (NULL, NULL);

CREATE TABLE dst AS
SELECT MOD(d, i) AS by_column,
       MOD(d, 2) AS by_literal,
       MOD(d, CAST(i AS DECIMAL(10,0))) AS decimal_control
FROM src;

SELECT column_name, column_type
FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'dst'
ORDER BY ordinal_position;

Observed CTAS column types:

Expression MatrixOne MySQL 8.0.46
MOD(d, i) DECIMAL(38,3) DECIMAL(10,3)
MOD(d, 2) DECIMAL(38,3) DECIMAL(10,3)
MOD(d, CAST(i AS DECIMAL(10,0))) DECIMAL(10,3) DECIMAL(10,3)

The same types are exposed by a view. d % i follows the same mismatch. CASE and COALESCE expressions containing MOD(d,i) inherit the widened precision.

The operand-width boundary also differs in the other direction: for DECIMAL(18,3) MOD BIGINT, MatrixOne exposes DECIMAL(18,3) while MySQL exposes DECIMAL(19,3); for BIGINT UNSIGNED, MySQL exposes DECIMAL(20,3) while MatrixOne still exposes DECIMAL(18,3). DECIMAL(38,3) and DECIMAL(50,3) controls matched in the tested CTAS matrix.

Cross-path verification

  • CTAS and view metadata: the differences above reproduced 3/3.
  • Negative, positive, and NULL input rows: remainder values matched.
  • MOD and %: same behavior.
  • GROUP BY on the result and equality joins over the result: returned rows matched.
  • Direct MOD(decimal, 0) / % 0: both engines returned NULL; this is not part of the reported difference.
  • Explicitly casting the integer divisor to DECIMAL removed the DECIMAL(10,3) widening discrepancy.

Compatibility contract and related tracking

The mysql-compatibility-contract README has no DECIMAL MOD result-metadata exception. Existing #29610 concerns incorrect Decimal256 remainder values/panics at magnitude boundaries, not this result-type mismatch. #28595 tracks rounding-family result metadata and states that its tested MOD case matched; this mixed DECIMAL/integer operand shape is distinct. Related broad CTAS schema tracking: #24436.

Expected behavior

Derive and expose the DECIMAL result precision/scale for MOD and % consistently with MySQL across integer signedness and operand widths, including CTAS, views, and composed expressions, while preserving the already-matching remainder values.

Activity

  1. added this to the MO-202610 milestone on Oct 14, 2026
  2. added
    kind/bug
    kind/compatibility
    on Oct 14, 2026
  3. added theissue type on Oct 14, 2026
  4. added
    ai-easy
    on Oct 15, 2026
  5. slyunnn commented on Oct 16, 2026

    @slyunnn

    Regression and extended verification for #30157 (2026-10-16)

    Verification Environment

    • MatrixOne latest fetched origin/main: ac55588b8d4bf19c803a31bbd8248b7f63ad8122 — fix(lockservice): balance row waiter and range ownership lifetimes (#30321). The clean source HEAD and the running CN's mo-service -version both reported this commit; the binary was built with Go 1.27.1.
    • Isolated local topology: 2 CN / 1 TN / 1 Log service / 1 Proxy. Proxy 127.0.0.1:6781, CN1 127.0.0.1:16781, and CN2 127.0.0.1:16782 each accepted real SQL. The original regression and extended SQL and native prepared queries were executed through each endpoint, not merely health-checked.
    • MySQL 8.0.46 on 127.0.0.1:33857 was the compatibility control. Direct SQL used PyMySQL's MySQL text protocol (COM_QUERY), including SQL PREPARE/EXECUTE. Native prepared-result metadata used Go's MySQL driver with parameter interpolation disabled, exercising COM_STMT_PREPARE/COM_STMT_EXECUTE. MOTR connected via the Proxy and ran serially with -j 1.

    What Was Covered

    • OK — The original DECIMAL(10,3) MOD(d,i) and MOD(d,2) CTAS columns both exposed DECIMAL(10,3) on Proxy, CN1, and CN2, matching MySQL 8.0.46; the former incorrect DECIMAL(38,3) was absent.
    • OK — %, an explicitly cast DECIMAL divisor, CASE, and COALESCE exposed DECIMAL(10,3) in CTAS and view metadata. DECIMAL(18,3) with signed/unsigned BIGINT exposed DECIMAL(19,3)/DECIMAL(20,3); DECIMAL(38,3) and DECIMAL(50,3) controls retained precisions 38 and 50. All matched MySQL.
    • OK — Positive, negative, and NULL results matched MySQL. A zero divisor returned NULL; repeated SQL-prepared execution with row IDs 1, 2, 1 preserved values and connection health.
    • OK — Real binary-protocol prepared-result metadata reported DECIMAL with exact precision/scale (10,3), (19,3), (20,3), (38,3), and (50,3), with positive/negative/NULL values and reuse, on MySQL and all three MatrixOne endpoints.
    • OK — Independently reran the fix's three focused function tests, two focused planner tests, and TestDecimalModMetadata single-CN SQL integration test on this exact main; all passed.
    • Not covered — Full owning-package test suites, full BVT/TKE, JDBC application end-to-end, and an engine-internal parallel-worker path were not rerun. These are not required to establish this binding-time metadata contract; the native MySQL binary boundary and both direct SQL and embedded single-CN integration are covered.

    Findings

    • Fixed on the tested main: result precision/scale, rather than the remainder arithmetic, was the reported defect. Materialized CTAS columns, view metadata, direct result metadata and values, and native prepared-result metadata matched MySQL 8.0.46 through Proxy, CN1, and CN2.
    • Associated fix: MatrixOne PR #30170, merged as 94cd6938006cad15cad0d18e7643fc3fe26e694c — fix(plan): derive MOD decimal precision from original operands (#30170). It derives exact result metadata from the original operands without changing the remainder execution kernel. Existing materialized table schemas are not migrated by this fix.
    • Large-data regression: not needed. The defect occurs while binding DECIMAL precision and scale, not at a row-count, block/batch, memory/spill, concurrency, skew, or network-size boundary. The 3-row positive/negative/NULL fixture and precision 38/50 and signedness controls cover the relevant boundaries.

    MOTR / BVT Coverage

    • MOTR base origin/main: 4fd475a39876cdbd8aec5a025b9826a74a1cc48b. Independent branch test/issue-30157-mod-decimal-metadata contains the single commit 32f684a23b571b019a82b710fc085dfd22c59682 (test: add MOTR regression for #30157), remotely verified. It includes one SQL .test/.result pair and one Go native-protocol case; no MatrixOne service source changed.
    • Both cases were recorded and replayed on the source branch. The daily MOTR PR #246 contains cherry-pick commit aa3e9cae3daa31f41e038f77d6ffaaa2689b7851; its exact files were replayed twice: 4/4 cases and 46/46 checks passed, with no fixture database left behind. -j 1 means serial MOTR scheduling, not proof of engine parallel execution.
    • The independent focused Go tests and single-CN SQL integration test passed on MatrixOne ac55588. A fresh full BVT/TKE run was not performed because the direct multi-endpoint and embedded integration evidence closes the issue's metadata paths.

    Final Conclusion

    Fixed on MatrixOne main ac55588b8d4bf19c803a31bbd8248b7f63ad8122 for the reported MySQL-compatible MOD/% DECIMAL result metadata. The original reproduction, high-precision controls, native prepared-result metadata, focused Go tests, single-CN integration, and MOTR record/replay passed. Large-data regression is not required for this binding-time metadata issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easyarea/compatibilitykind/bugkind/compatibility

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions