Skip to content

[Bug]: ADDTIME and SUBTIME misclassify long TIME strings as DATETIME #28147

Closed

Description

@Ariznawlll

现象

在 MatrixOne main 99ed717b769e261b842c2f17345bd65865fc1470,ADDTIME()/SUBTIME() 接收超大小时的时间字符串时错误推断为日期时间:

SELECT ADDTIME('838:59:59', '00:00:01');
-- 2026-10-08 23:00:00  (异常)
SELECT SUBTIME('-838:59:59', '00:00:01');
-- 2026-07-31 01:00:00  (异常)

同样的值先转为 TIME(6) 列或显式 CAST 后,结果为 839:00:00.000000 / -838:59:58.000000;TIMEDIFF() 对同一字符串边界也返回时间结果。因此问题限定在 ADDTIME/SUBTIME 的字符串输入类型推断,而非时间加法本身。

此外,CREATE TABLE ... AS SELECT ADDTIME('838:59:59','00:00:01') 将结果列物化为 DATETIME,进一步固化错误类型。

期望

ADDTIME(expr1,expr2) 的第一个参数为 TIME 形式字符串时,应按时间间隔解析并返回时间结果;不能因为小时数超过 24 就改按日期时间解释。表达式结果可以超过 TIME 列存储上限,但类型和数值语义应保持一致。

影响

持续时间计算、报表和 CTAS 会把合法的长时间间隔变成错误日期,导致后续比较、排序和落盘类型错误。

复现信息

  • MatrixOne main: 99ed717b769e261b842c2f17345bd65865fc1470
  • 重复执行 3 次,结果一致

Activity

  1. added this to the MO-202609 milestone on Sep 4, 2026
  2. added
    kind/bug
    on Sep 4, 2026
  3. added theissue type on Sep 4, 2026
  4. changed the title [-][Bug]: ADDTIME misclassifies long TIME strings as DATETIME[/-] [+][Bug]: ADDTIME and SUBTIME misclassify long TIME strings as DATETIME[/+] on Sep 4, 2026
  5. XuPeng-SH commented on Sep 27, 2026

    @XuPeng-SH
    Contributor

    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: C02–C04, C08, C18 in the merged temporal design. A long TIME-like string is a duration, never a DATETIME anchored to today; new string-first ADDTIME/SUBTIME returns VARCHAR(29). Arithmetic beyond ±838:59:59 returns NULL plus warning 1441 instead of a fabricated date or an out-of-domain TIME.

    Please rerun the original reproducer on main at 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. Retest both original endpoint queries plus a representable >24-hour control, and verify result metadata and warning code.

    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

  6. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • Commit:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 部署方式:本地全新单 CN mo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE
    • 测试日期:2026-10-02

    原问题验证

    按 issue 原始语义在上述 commit 重新执行并重复 3 次。长 TIME 字符串保持 duration 语义;越过 ±838:59:59 的算术结果按当前 contract 返回 NULL,不再被识别为当天 DATETIME。

    Happy Path 覆盖

    覆盖正负长 TIME、ADDTIME/SUBTIME 及合法端点。

    Unhappy Path 覆盖

    覆盖端点外 1 微秒、NULL 和 malformed 输入;返回 NULL/受控 warning,无日期注入。

    白盒验证

    关联修复 #28851 已进入当前 main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。

    回归测试

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 当前结果:长 TIME 字符串保持 duration 语义;越过 ±838:59:59 的算术结果按当前 contract 返回 NULL,不再被识别为当天 DATETIME。
    • 回归代码与 golden result 已提交到 MOTR #209;本地全量 14_issue_regression 中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions