Repository navigation
Description
Summary
ADDTIME / SUBTIME do not handle dynamic parameters whose values are datetimes consistently with MySQL 8.0.46:
- With a string-bound datetime crossing midnight, MatrixOne returns an unwrapped TIME duration (or a negative duration), while MySQL returns the clock portion of the date-arithmetic result.
- With a DATETIME-typed user variable, MatrixOne returns
ERROR 20101due topanic wrong type for FunctionResultWrapper; MySQL executes the same prepared statements successfully.
The typed-parameter panic was reproducible twice for each function. It is distinct from #28151 (fixed panic on fractional composite TIME strings) and #28561 (result type for TIMESTAMP-column inputs).
Value mismatch reproduction
SET @d = '2024-02-29 23:30:00.123456';
PREPARE p FROM 'SELECT ADDTIME(?, ''02:00:00.000001'')';
EXECUTE p USING @d;- MatrixOne:
25:30:00.123457 - MySQL 8.0.46:
01:30:00.123457
A matching negative-boundary probe (@d='2024-02-29 00:30:00.123456' and ADDTIME(?, '-02:00:00.000001')) returns -01:29:59.876545 in MatrixOne and 22:30:00.123455 in MySQL. Away from the day boundary, the returned values matched.
Panic reproduction
SET @d = CAST('2024-02-29 23:30:00.123456' AS DATETIME(6));
PREPARE p FROM 'SELECT ADDTIME(?, ''02:00:00.000001'')';
EXECUTE p USING @d;
PREPARE p FROM 'SELECT SUBTIME(?, ''02:00:00.000001'')';
EXECUTE p USING @d;MatrixOne returns ERROR 20101 (HY000): internal error: panic wrong type for FunctionResultWrapper for both statements (stacks point to addTimeToDatetime / subTimeFromDatetime in func_binary.go). MySQL returns 01:30:00.123457 for ADDTIME and 21:30:00.123455 for SUBTIME.
Casting the marker explicitly inside the expression (ADDTIME(CAST(? AS DATETIME(6)), ...)) succeeds on both engines and returns the datetime result; this changes the resolved expression type and does not cover the uncast dynamic-parameter form.
MySQL documents that from 8.0.28, when the first argument is a dynamic parameter, ADDTIME / SUBTIME resolve to TIME: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html
Environment
- MatrixOne: local main-derived commit
2ce4e58af6f03b943ee288ffad81012766cf830a, server reports8.0.30-MatrixOne-v1.3.0 - MySQL: 8.0.46
- SQL-level server-side
PREPARE/EXECUTE; no test files changed.
Activity
Ariznawlll commentedon Oct 19, 2026
测试版本
main8e63625c4e9baeb1d28c1095c07732f056c04895d82e828b0a4df9ce635fe573c1e90c5cde978bf9已进入该 main。原问题验证
原始 prepared
ADDTIME(?, '02:00:00.000001'),字符串绑定2024-02-29 23:30:00.123456:3/3 实际01:30:00.123457,不再错误返回25:30:00.123457。同样输入改成CAST(... AS DATETIME(6))绑定:3/3 也返回01:30:00.123457,不再报panic wrong type for FunctionResultWrapper。preparedSUBTIMEtyped 参数 3/3 返回21:30:00.123455,没有 panic。Happy Path 覆盖
00:30:00.123456加正两小时 3/3 为02:30:00.123457;ADDTIME(?, '-02:00:00.000001')越过前一日 3/3 为22:30:00.123455;SUBTIME同边界 3/3 也是22:30:00.123455。23:30:00.123456+ 两小时的对照 3/3 为合法持续时间25:30:00.123457,未把持续时间误转成时钟。Unhappy Path 覆盖
ADDTIME使用 NULL、无效文本invalid参数,均 3/3 返回 NULL;切回有效参数后 3/3 仍正常执行。此 SELECT 路径无持久写入,未观测到会话损坏或 panic。白盒验证
同 SHA 的
TestPreparedTemporalResultContracts|TestPreparedTemporalMarkerReuse|TestTemporalCompatibilityExecutionMatrix|TestDynamicTimeResultTypedCalendarAndMask在pkg/sql/plan/... -count=3PASS,含 typed DATETIME 与动态参数的类型/值断言。回归测试
MOTR #247 新增成对
t/issue_30195_30196_30197_prepared_temporal.test/r/*.result,当前 head623ac129a7d011ae0d441cd4275d0100e5d8d854;定向 3/3,135/135 语句成功、0 skip,PR 未合入。MatrixOne 原有test/distributed/cases/prepare/prepared_temporal_results.sql也含动态参数与 NULL 断言,本轮未单独跑该 BVT。完整 659 case suite 尝试启动后中断,遗留专用库已清理;完整 suite/集成 CI 未完成。测试证据
total=3 success=3 failed=0 skipped=0 | stmts=135 ok=135 fail=0。测试结论
测试通过。