Skip to content

[Bug]: date/time functions error on zero or invalid date strings instead of MySQL NULL/0 semantics #25306

Closed

Description

@Ariznawlll

Bug Report

MatrixOne Version

Latest origin/main verified locally at 200bfa7e0efb.

Reproduce Steps

set session sql_mode = '';

select date_format('0000-00-00', '%Y-%m-%d') as zero_fmt,
       dayofmonth('0000-00-00') as zero_day,
       month('0000-00-00') as zero_month,
       year('0000-00-00') as zero_year,
       last_day('2024-02-31') as invalid_last_day;

select extract(month from '0000-00-00') as zero_extract_month,
       extract(day from 'not-a-date') as invalid_extract_day;

select convert_tz('2024-01-01 00:00:00', '+00:00', '+08:00') as offset_ok,
       convert_tz('invalid', '+00:00', '+08:00') as invalid_dt;

Expected Behavior

MySQL returns zero parts for extractor-style functions that accept incomplete dates, and returns NULL for invalid complete-date operations:

zero_fmt    zero_day  zero_month  zero_year  invalid_last_day
0000-00-00  0         0           0          NULL

zero_extract_month  invalid_extract_day
0                   NULL

offset_ok            invalid_dt
2024-01-01 08:00:00  NULL

Actual Behavior

MatrixOne errors before returning the rows:

ERROR 20301 (HY000): invalid input: invalid datetime value 0000-00-00
ERROR 20101 (HY000): internal error: invalid input
ERROR 20301 (HY000): invalid input: invalid datetime value invalid

Notes

This is separate from #25253, which covers CAST('0000-00-00 00:00:00' AS DATETIME). This issue is about date/time function behavior for zero/incomplete/invalid date strings.

MySQL documentation says some date functions work with zero or incomplete dates and return zero parts, while functions expecting complete dates return NULL for invalid/incomplete values.

Activity

  1. added
    kind/bug
    severity/s1
    on Jul 1, 2026
  2. added
    severity/s0
    and removed
    severity/s1
    on Jul 2, 2026
  3. added this to the MO-202607 milestone on Jul 2, 2026
  4. added theissue type on Jul 2, 2026
  5. added and removed
    severity/s0
    on Jul 2, 2026
  6. self-assigned this
    on Sep 1, 2026
  7. iamlinjunhong commented on Sep 1, 2026

    @iamlinjunhong
    Contributor

    最新 main 复测(2026-09-01)

    在 main@33af6ae3c0c23e4f277137460577ea64678f7ecf 上,date('0000-00-00') 的零日期分支仍返回 NULL/0 混合结果;date('2024-02-30') 及相关无效日期表达式稳定返回 data out of range 错误,而不是按 issue 中的 MySQL 兼容 NULL/零部件语义完成查询。该结果来自 ODBC 和原始 MySQL 文本协议交叉测试。

  8. 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: C05, C16–C17, C30–C31 in the merged temporal design. Accepted zero-calendar raw YEAR/MONTH/DAY/DAYOFMONTH and EXTRACT fields are zero in either SQL mode; explicit DATE conversion observes NO_ZERO_DATE. Malformed tolerant temporal input is NULL, while zero/partial-zero calendar policies remain distinct. The merged contract does not automatically settle LAST_DAY or CONVERT_TZ.

    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. Rerun all three original statements under both modes, including LAST_DAY and CONVERT_TZ controls; close only if every issue-specific function satisfies its declared contract, otherwise document the residual path.

    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

  9. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

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

    原问题验证

    按 issue 原始语义在上述 commit 重新执行并重复 3 次。零日期的 YEAR/MONTH/DAY/EXTRACT 按约定返回 0;非法日历输入返回 NULL,不再中断查询。

    Happy Path 覆盖

    覆盖零日期、partial-zero 与普通有效日期,结果与最新 temporal contract 一致。

    Unhappy Path 覆盖

    覆盖非法日期文本、NO_ZERO_DATE 模式及 NULL 输入;均返回受控 NULL/诊断,无内部错误。

    白盒验证

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

    回归测试

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 当前结果:零日期的 YEAR/MONTH/DAY/EXTRACT 按约定返回 0;非法日历输入返回 NULL,不再中断查询。
    • 回归代码与 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