Repository navigation
Description
Problem
ADDTIME() and SUBTIME() attach the current UTC date to a TIME-like string first argument in MatrixOne. MySQL keeps TIME-like string arithmetic in the time domain.
The MatrixOne value therefore changes with the calendar date on which the query runs, changes the result type to DATETIME(6), and converts legitimate negative or greater-than-24-hour time results into dates around today.
Tested on MatrixOne main commit f0c31cd4b830be32442cf329e0a3fb08aa9c16c3 and MySQL 8.3.0. Each MatrixOne reproduction was repeated three times.
Minimal reproduction
SELECT ADDTIME('12:00:00','01:00:00');
SELECT SUBTIME('00:00:00','00:00:00.000001');
SELECT ADDTIME('23:59:59.999999','00:00:00.000002');
SELECT ADDTIME('12:00:00','1 01:02:03.000004');MatrixOne on 2026-09-09 returns:
2026-09-09 13:00:00.000000
2026-09-08 23:59:59.999999
2026-09-10 00:00:00.000001
2026-09-10 13:02:03.000004
MySQL returns:
13:00:00
-00:00:00.000001
24:00:00.000001
37:02:03.000004
Row, prepared, and persistence coverage
The same behavior occurs when both inputs are VARCHAR columns and when they are bound through SQL PREPARE/EXECUTE.
For a view over VARCHAR inputs:
- MatrixOne exposes both ADDTIME and SUBTIME columns as
DATETIME(6); - MySQL exposes them as
VARCHAR(29)and preserves whether each row represents a time or datetime string.
CTAS persists MatrixOne's calendar-dependent values into DATETIME columns. MySQL persists the corresponding time strings into VARCHAR columns.
MatrixOne also accepts a datetime-shaped second string such as '2024-01-01 01:00:00' as if it were a one-hour TIME operand, while MySQL returns NULL for that invalid second operand.
Controls
ADDTIME(CAST('12:00:00' AS TIME(6)), '01:00:00')returns TIME13:00:00in both systems.- Datetime-like string first arguments such as
'2024-01-02 12:00:00'produce the same datetime value in both systems. - NULL propagation agrees.
- Invalid first strings produce NULL in both systems (MatrixOne currently omits MySQL's warning, but that is not the main issue here).
- MatrixOne remains healthy after the full vector and persistence matrix.
Code analysis
pkg/sql/plan/function/list_builtIn.go registers every string/string ADDTIME and SUBTIME overload with a fixed DATETIME(6) return type.
addTimeToString and subTimeFromString in pkg/sql/plan/function/func_binary.go first try types.ParseDatetime; when a TIME string is found instead, they call time1.ToDatetime(scale). types.Time.ToDatetime in pkg/container/types/time.go explicitly uses Today(time.UTC) as its date component.
This discards the original TIME-vs-DATETIME domain and makes a deterministic time calculation depend on the execution date.
Expected behavior
TIME-like string first arguments should remain in the time domain, including negative and greater-than-24-hour results. Datetime-like first arguments should remain datetime-like. The result metadata and CTAS/view persistence should preserve that distinction without introducing today's date.
Activity
fix: align date compatibility semantics (#28851)
XuPeng-SH commentedon Sep 27, 2026
QA handoff after merged PR #28851 (merge
a99db843c7b4630a86883addc9424433d93fc2d2). This issue was a non-closing related report; the merge and shared BVT counts are not an independent PASS for this reproducer.Latest MatrixOne contract: C03–C04, C08, C18 in the merged temporal design. A TIME-like string first operand in ADDTIME/SUBTIME remains duration-family; new string-first results are VARCHAR(29), with no current-date injection. Representable results keep duration values; out-of-domain arithmetic returns NULL plus warning 1441.
Please rerun the original reproducer on
mainat or after the merge and record the exact SHA, deployment, SQL mode/time zone, client path, observed rows/types/NULLs and active warnings or errors. Rerun the original SQL on two calendar dates, both signs, a >24-hour valid duration and endpoint overflow; check value, type and warnings.Keep the issue open until the issue-specific acceptance is demonstrated with happy and unhappy controls. If any part still fails, post the exact observed-versus-expected result and return it to development; if it passes, record evidence and close the issue. @Ariznawlll
Ariznawlll commentedon Oct 2, 2026
测试版本
maind50a2d475a406829f67127fef7b2ad4abc1c1d3dmo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE原问题验证
按 issue 原始语义在上述 commit 重新执行并重复 3 次。字符串 TIME 第一参数在 ADDTIME/SUBTIME 中保持 duration family,结果未附加当前日期。
Happy Path 覆盖
覆盖正负 TIME、跨小时和小数秒,结果类型/文本值稳定。
Unhappy Path 覆盖
覆盖越过 TIME endpoint、malformed 与 NULL;返回受控 NULL/warning,不产生今天日期。
白盒验证
关联修复 #28851 已进入当前
main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。回归测试
suites/14_issue_regression/t/issue_recent_temporal_contracts.test714/714条语句通过。测试证据
d50a2d475a406829f67127fef7b2ad4abc1c1d3d14_issue_regression中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。测试结论
测试通过。