Repository navigation
Description
Environment
- MatrixOne: latest
main, commitf0c31cd4b830be32442cf329e0a3fb08aa9c16c3 - MySQL comparison: 8.3.0
Problem
PERIOD_ADD and PERIOD_DIFF truncate exact DECIMAL arguments instead of applying MySQL's exact numeric-to-integer rounding. Values at or above a .5 boundary therefore select a different period or month count. SQL prepared statements take a third path and reject the same DECIMAL values outright.
Reproduction
SELECT PERIOD_ADD(CAST(200801.5 AS DECIMAL(7,1)), 1);
SELECT PERIOD_ADD(200801, CAST(1.5 AS DECIMAL(3,1)));
SELECT PERIOD_ADD(200801, CAST(-1.5 AS DECIMAL(3,1)));
SELECT PERIOD_DIFF(CAST(200802.5 AS DECIMAL(7,1)), 200801);
SELECT PERIOD_DIFF(200802, CAST(200801.5 AS DECIMAL(7,1)));MatrixOne returns:
200802
200802
200712
1
1
MySQL 8.3 returns:
200803
200803
200711
2
0
The difference comes from converting 200801.5 to period 200801 instead of 200802, and month counts 1.5/-1.5 to 1/-1 instead of 2/-2.
Prepared-statement path
PREPARE p FROM 'SELECT PERIOD_ADD(?, ?)';
SET @period = CAST(200801.5 AS DECIMAL(7,1));
SET @months = CAST(1.5 AS DECIMAL(3,1));
EXECUTE p USING @period, @months;MatrixOne rejects this with invalid argument cast to int, bad value 200801.5; MySQL returns 200804 after rounding both exact arguments. PERIOD_DIFF has the same prepared-parameter rejection.
Coverage
All relevant paths were repeated three times:
- DECIMAL constants below, at, and above the
.5boundary; - positive and negative DECIMAL month counts;
- DECIMAL columns with valid YYMM/YYYYMM periods;
- SQL prepared statements;
- CTAS, which persists the incorrect
PERIOD_ADDandPERIOD_DIFFresults.
Integer and NULL controls behave normally, and .4 controls match MySQL because truncation and rounding happen to choose the same integer. The server remains healthy after all runs.
Code analysis
The function registrations in pkg/sql/plan/function/list_builtIn.go provide only signed integer, unsigned integer, and FLOAT64 overload combinations—there is no DECIMAL overload.
Both PeriodAdd and PeriodDiff in pkg/sql/plan/function/func_binary.go convert the floating execution path with direct truncation:
return int64(val), null // Truncate decimal partPrepared parameter resolution instead selects an integer cast and rejects the fractional DECIMAL text. A dedicated exact DECIMAL conversion path is needed to keep constant, column, and prepared behavior aligned.
Activity
slyunnn commentedon Sep 28, 2026
Regression and extended verification for #28496 (2026-09-28)
Verification Environment
origin/mainat9b7c2c23dba737232d975d66bd04628199e1a436—fix(tae): reconcile replay promotion merge state before write (#29421).arm64mo-servicebuilt from that exact source; its embedded build information reports branchmainand commit9b7c2c23db.1 Log service / 1 TN / 2 CN / 1 Proxy.6001, CN116001, and CN216002were all connected successfully. Original and SQLPREPAREregressions used the MySQL text protocol through each endpoint; binary prepared coverage used Go's MySQL driver andCOM_STMT_PREPARE/COM_STMT_EXECUTEon all three endpoints.8.3.0using the MySQL text protocol.61461c12a9e7088b5176fb477a7d40823e75cbef(refactor: migrate numeric integer parameters). It migrates bothPERIOD_ADDandPERIOD_DIFFparameters to the shared signedINT64integer-argument contract introduced by PR #28989,d9609d742b9000b54279f44e34295630b7238282.What Was Covered
PERIOD_ADDwith fractionalDECIMALperiod/month arguments andPERIOD_DIFFwith fractionalDECIMALperiods returned200803,200803,200711,2, and0, matching MySQL8.3.0on Proxy, CN1, and CN2..4and.5exactDECIMALvalues produced the same results as MySQL8.3.0on all three endpoints.-1.5rounded through the shared integer contract and returned200711.NULLcontrols for both functions returnedNULLon all three endpoints.DECIMALtable-column inputs, including positive, negative,.4,.5, andNULLrows, matched MySQL8.3.0on Proxy, CN1, and CN2.CTASpersisted the correctedPERIOD_ADDandPERIOD_DIFFvalues on all three endpoints.PREPARE/EXECUTEwithDECIMALvariables returned200804forPERIOD_ADDand1forPERIOD_DIFFon all three endpoints.COM_STMT_PREPARE/COM_STMT_EXECUTEwith parameters cast toDECIMALreturned the expected results andNULLpropagation on Proxy, CN1, and CN2.FLOAT/DOUBLEconversion behavior is outside this exact-DECIMALissue and was not used to judge the fix.Findings
Both arguments of
PERIOD_ADDandPERIOD_DIFFnow use the shared exact integer-argument coercion before selecting the canonicalINT64executor. The previous fractionalDECIMALtruncation and SQL prepared-statement rejection are not reproducible on the latest main runtime. All endpoints remained healthy after verification.MOTR / BVT Coverage
No new MOTR case or commit was needed. Existing distributed BVT coverage in
test/distributed/cases/function/integer_parameter_coercion.sqlexercises numeric integer consumers, includingPERIOD_ADD,DECIMALcolumns, SQL prepared execution,NULL, and overflow controls. Latest-main targeted planner/function testsTestIntegerArgumentAdditionalSignaturesandTestIntegerArgumentPreparedRuntimeCandidatespassed.Large-data regression is not required: this behavior is determined by scalar exact
DECIMALconversion and overload binding, independent of row count, block/batch boundaries, memory/spill, concurrency, data skew, network transfer, or resource scale. Increasing data volume would not cover an additional relevant execution boundary.Final Conclusion
Fixed. The original and extended exact-
DECIMALPERIOD_ADD/PERIOD_DIFFscenarios match MySQL8.3.0through Proxy, CN1, and CN2, including SQL and binary prepared execution.