Repository navigation
Description
Environment
- MatrixOne:
8.0.30-MatrixOne-v1.3.0, built from2ce4e58af6f03b943ee288ffad81012766cf830a - 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.
MODand%: same behavior.GROUP BYon 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
fix(plan): derive MOD decimal precision from original operands (#30170)
slyunnn commentedon Oct 16, 2026
Regression and extended verification for #30157 (2026-10-16)
Verification Environment
origin/main:ac55588b8d4bf19c803a31bbd8248b7f63ad8122—fix(lockservice): balance row waiter and range ownership lifetimes (#30321). The clean sourceHEADand the running CN'smo-service -versionboth reported this commit; the binary was built with Go1.27.1.2CN /1TN /1Log service /1Proxy. Proxy127.0.0.1:6781, CN1127.0.0.1:16781, and CN2127.0.0.1:16782each accepted real SQL. The original regression and extended SQL and native prepared queries were executed through each endpoint, not merely health-checked.8.0.46on127.0.0.1:33857was the compatibility control. Direct SQL used PyMySQL's MySQL text protocol (COM_QUERY), including SQLPREPARE/EXECUTE. Native prepared-result metadata used Go's MySQL driver with parameter interpolation disabled, exercisingCOM_STMT_PREPARE/COM_STMT_EXECUTE. MOTR connected via the Proxy and ran serially with-j 1.What Was Covered
DECIMAL(10,3)MOD(d,i)andMOD(d,2)CTAScolumns both exposedDECIMAL(10,3)on Proxy, CN1, and CN2, matching MySQL8.0.46; the former incorrectDECIMAL(38,3)was absent.%, an explicitly castDECIMALdivisor,CASE, andCOALESCEexposedDECIMAL(10,3)inCTASand view metadata.DECIMAL(18,3)with signed/unsignedBIGINTexposedDECIMAL(19,3)/DECIMAL(20,3);DECIMAL(38,3)andDECIMAL(50,3)controls retained precisions38and50. All matched MySQL.NULLresults matched MySQL. A zero divisor returnedNULL; repeated SQL-prepared execution with row IDs1,2,1preserved values and connection health.DECIMALwith exact precision/scale(10,3),(19,3),(20,3),(38,3), and(50,3), with positive/negative/NULLvalues and reuse, on MySQL and all three MatrixOne endpoints.TestDecimalModMetadatasingle-CN SQL integration test on this exactmain; all passed.Findings
main: result precision/scale, rather than the remainder arithmetic, was the reported defect. MaterializedCTAScolumns, view metadata, direct result metadata and values, and native prepared-result metadata matched MySQL8.0.46through Proxy, CN1, and CN2.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.DECIMALprecision and scale, not at a row-count, block/batch, memory/spill, concurrency, skew, or network-size boundary. The3-row positive/negative/NULLfixture and precision38/50and signedness controls cover the relevant boundaries.MOTR / BVT Coverage
origin/main:4fd475a39876cdbd8aec5a025b9826a74a1cc48b. Independent branchtest/issue-30157-mod-decimal-metadatacontains the single commit32f684a23b571b019a82b710fc085dfd22c59682(test: add MOTR regression for #30157), remotely verified. It includes one SQL.test/.resultpair and one Go native-protocol case; no MatrixOne service source changed.aa3e9cae3daa31f41e038f77d6ffaaa2689b7851; its exact files were replayed twice:4/4cases and46/46checks passed, with no fixture database left behind.-j 1means serial MOTR scheduling, not proof of engine parallel execution.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
mainac55588b8d4bf19c803a31bbd8248b7f63ad8122for the reported MySQL-compatibleMOD/%DECIMALresult 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.