Repository navigation
Description
Environment
- MatrixOne:
mainatfc621e3616d229c7a29d0c80e73ed8eb1997459c - MySQL reference: 8.0.46
- Session time zone:
+00:00
Problem
MatrixOne accepts TIME_TRUNCATE_FRACTIONAL in sql_mode, but temporal values are still rounded when converted to a lower fractional-seconds precision. The mode therefore has no effect on TIME, DATETIME, or TIMESTAMP values.
MySQL documents this mode as selecting truncation instead of rounding when temporal values are converted to lower precision: TIME_TRUNCATE_FRACTIONAL.
Minimal reproduction
SET SESSION time_zone = '+00:00';
SET SESSION sql_mode = 'STRICT_TRANS_TABLES,TIME_TRUNCATE_FRACTIONAL';
CREATE TABLE t(
id INT PRIMARY KEY,
dt DATETIME(3),
ts TIMESTAMP(3),
tm TIME(3)
);
INSERT INTO t VALUES(
1,
'2024-01-02 03:04:05.123556',
'2024-01-02 03:04:05.123556',
'12:34:56.123556'
);
SELECT CAST(dt AS CHAR), CAST(ts AS CHAR), CAST(tm AS CHAR) FROM t;MatrixOne returns rounded values:
2024-01-02 03:04:05.124
2024-01-02 03:04:05.124
12:34:56.124
MySQL 8.0.46 returns truncated values:
2024-01-02 03:04:05.123
2024-01-02 03:04:05.123
12:34:56.123
Without TIME_TRUNCATE_FRACTIONAL, both systems round the same input to .124.
Boundary behavior
With the mode enabled, MatrixOne also rounds 23:59:59.999500 across the day boundary and rounds 12:59:59.999500 across the hour boundary:
DATETIME/TIMESTAMP: 2024-01-03 00:00:00.000
TIME: 13:00:00.000
MySQL truncates them to 2024-01-02 23:59:59.999 and 12:59:59.999. Negative TIME values show the same difference: MatrixOne converts -12:34:56.123556 to -12:34:56.124, while MySQL converts it to -12:34:56.123.
Affected execution paths
The same mode-insensitive rounding occurs in MatrixOne for:
- direct
INSERTandUPDATE; - non-key assignments in
INSERT ... ON DUPLICATE KEY UPDATE; INSERT ... SELECTfrom FSP 6 columns into FSP 3 columns;- SQL
PREPARE ... EXECUTE ... USINGparameters; - explicit
CAST(... AS DATETIME(3))andCAST(... AS TIME(3)); - CTAS over those casts;
ALTER TABLE ... MODIFYfrom FSP 6 columns to FSP 3 columns.
A prepared statement created once and executed first with ordinary rounding mode and then with TIME_TRUNCATE_FRACTIONAL returns .124 both times in MatrixOne. MySQL returns .124 for the first execution and .123 for the second, so the mode is evaluated for the active execution rather than being permanently captured by preparation.
Code analysis
pkg/frontend/variables.go lists TIME_TRUNCATE_FRACTIONAL as a valid sql_mode token, but there is no other reference to this token in the repository. pkg/container/types/timestamp.go:getMsec unconditionally examines the first discarded digit and increments the retained fractional part when it is 5-9. TIME, DATETIME, TIMESTAMP, and relevant casts use this helper without a session-mode input, so truncation cannot currently be selected.
The behavior above was reproduced three times with fresh databases and connections. All listed paths include an ordinary rounding-mode control, where MatrixOne and MySQL agree.
Activity
XuPeng-SH commentedon Sep 10, 2026
Triage routing: assigned to @jiangxinmeng1. Labels normalized to
kind/bug+needs-triage(existing compatibility labels, when present, are retained).Recommended PR decomposition:
#28600only): implementTIME_TRUNCATE_FRACTIONALat the conversion/rounding owner. Keep it separate from invalid-date validation and DST handling because the rounding and validation contracts differ.Suggested priority: P2; cover exact precision boundaries and all affected temporal conversions.
jiangxinmeng1 commentedon Oct 21, 2026
fixed by #28932
slyunnn commentedon Oct 23, 2026
Regression and extended verification for #28600 (2026-10-23)
Verification Environment
origin/main:2b388dd1690f83e2e807d6809180336dae2a68eb—fix(sql): honor cancellation inside LoopJoin and LIKE evaluation (#30862). The running MatrixOne binary was built from this commit with Go1.27.1.2 CN / 1 TN / 1 LogService / Proxy.6831, CN116131, and CN216132were each reachable and tested directly.PREPARE/EXECUTE. Reference: MySQL8.0.46; session time zone was+00:00.What Was Covered
DATETIME(3),TIMESTAMP(3), andTIME(3)insert underSTRICT_TRANS_TABLES,TIME_TRUNCATE_FRACTIONAL: input fraction.123556is truncated to.123on all three MatrixOne endpoints, matching MySQL.TIME_TRUNCATE_FRACTIONALrounds the same.123556input to.124, matching MySQL.23:59:59.999500truncates without carrying into the next day;12:59:59.999500stays within the hour; negativeTIME-12:34:56.123556truncates to-12:34:56.123. All match MySQL..124,.123,.124on each system, confirming the active execution mode is observed.INSERT ... SELECTfrom FSP6into FSP3,UPDATE, non-key assignments inINSERT ... ON DUPLICATE KEY UPDATE, explicitCAST, CTAS over casts, andALTER TABLE ... MODIFYall truncate to FSP3and match MySQL on Proxy, CN1, and CN2.INSERT IGNOREwith malformedTIMEinput retains12:34:56and warning code1265on all endpoints and MySQL.Findings
The fix is merged in PR #28932, merge commit
0c3f7e035d90fbcf205b3164c560eda2df38335e, titledfix remaining date/time compatibility issues. It appliesTIME_TRUNCATE_FRACTIONALat temporal conversion/rounding paths while preserving ordinary-mode rounding and evaluating session mode for the active prepared execution.The malformed-input control has different warning message wording (MatrixOne:
Data truncated for TIME value; MySQL:Data truncated for column 'v' at row 1), while the warning code and stored value match. This diagnostic-text difference does not change the verified truncation behavior and is not treated as an unresolved runtime failure for this issue.MOTR / BVT Coverage
The existing product distributed regression is
test/distributed/cases/function/temporal_assignment_regression.sql; it covers truncation mode, casts, and prepared-statement mode changes. No additional MOTR case or commit was needed. The full BVT harness was not run locally, so no latest-main full-suite pass is claimed.Large-data regression is not needed: fractional temporal conversion is independent of row count and resource scale.
Final Conclusion
Fixed — the reported mode-insensitive rounding is fixed on latest main and the original and extended SQL paths tested here match MySQL
8.0.46through Proxy, CN1, and CN2. The issue remains open for maintainer/reporter workflow; no issue state change was made.