Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues. [Bug]: date/time functions error on zero or invalid date strings instead of MySQL NULL/0 semantics #25306 (closed) covered the same semantic family for temporal extractor functions but its fix did not cover scalar
DATE(); [Compatibility]: Temporal functions mis-handle incomplete dates permitted by MySQL #30234 / [Compatibility]: STR_TO_DATE rejects incomplete zero dates when SQL modes allow them #30233 (open) track zero/incomplete-date inputs (2024-00-00), a different input class than the impossible-calendar and junk strings demonstrated here.
Environment
- MatrixOne commit:
beffc64c486d369406a41cdb1447b120bc93cb41(main, 2026-10-18), standalonemo-servicestarted via./mo-service -launch <launch.toml>(single CN/TN/log config; all ports shifted, mysql protocol on 31201). - OS: macOS 15.7 arm64 (Apple Silicon).
- Reference: local temp instance of MySQL 8.0.46 (
/opt/homebrew/opt/[email protected]homebrew), compared with identical client and identical SQL.
Actual Behavior
Every unparseable date string passed to the scalar DATE() function raises a query-killing error instead of producing NULL:
$ mysql -h127.0.0.1 -P31201 -udump -p ... -N
mysql> SELECT DATE('2026-02-30');
ERROR 1690 (22003) at line 1: data out of range: data type date, '2026-02-30'
mysql> SELECT DATE('2026-13-01');
ERROR 1690 (22003) at line 1: data out of range: data type date, '2026-13-01'
mysql> SELECT DATE('not a date');
ERROR 1690 (22003) at line 1: data out of range: data type date, 'not a date'
CAST(expr AS DATETIME) fails the same way for unparseable strings:
mysql> SELECT CAST('2026-02-30' AS DATETIME);
ERROR 20301 (HY000) at line 1: invalid input: invalid datetime value 2026-02-30
mysql> SELECT CAST('not a date' AS DATETIME);
ERROR 20301 (HY000) at line 1: invalid input: invalid datetime value not a date
The behavior is identical with SET SESSION sql_mode='' (non-strict) and under the default STRICT_TRANS_TABLES,NO_ZERO_DATE,... mode, so this is not a mode-gating issue.
Expected Behavior
MySQL 8.0.46 returns NULL (with warning 1292 "Incorrect date value") for the exact same statements, in every sql_mode:
$ mysql -h127.0.0.1 -P23206 -uroot -N --force < repro.sql
NULL -- SELECT DATE('2026-02-30');
NULL -- SELECT DATE('2026-13-01');
NULL -- SELECT DATE('not a date');
NULL -- SELECT CAST('2026-02-30' AS DATE);
NULL -- SELECT CAST('2026-02-30' AS DATETIME);
NULL -- SELECT CAST('not a date' AS DATETIME);
NULL -- SELECT DATE_FORMAT('2026-02-30', '%Y-%m-%d');
MatrixOne's own CAST('2026-02-30' AS DATE) already returns NULL on the same build, so the NULL-return machinery exists in the cast layer; the scalar DATE() path and the DATETIME cast path just do not use it. This makes user queries such as SELECT ... WHERE DATE(dirty_json_or_text_col) = '2026-02-28' or SELECT CAST(ts_text AS DATETIME) fail wholesale on legacy/dirty data that MySQL handles row-wise with NULLs, and it also makes on-parity CLI/BVT suites diverge.
Steps to Reproduce
- Build standalone service from commit
beffc64c486d369406a41cdb1447b120bc93cb41:make buildthen start./mo-service -launch etc/launch/launch.toml(I shifted all ports to avoid collisions: mysql 31201, cn port-base 43200, tn port-base 44200, log 57200-57202, status 32201; no other config changes). - Connect with any MySQL client:
mysql -h127.0.0.1 -P31201 -udump -p111 --default-character-set=utf8mb4. - Run the statements from the
reprofield (they are pure SELECTs, no schema needed). Every line errors on MatrixOne; every line returns NULL on MySQL 8.0.46.
Additional information
Root cause: DateStringToDate in pkg/sql/plan/function/func_unary.go (ParseDatetime call at line 1170, hard error at line 1172):
parsed, err := types.ParseDatetime(functionUtil.QuickBytesToStr(value), 6)
if err != nil {
return moerr.NewOutOfRangeNoCtxf("date", "'%s'", value)
}Any parse failure becomes a statement-fatal out-of-range error. The invalid-input error text seen for CAST(... AS DATETIME) is raised from pkg/container/types/datetime.go line 223 (moerr.NewInvalidInputNoCtxf("invalid datetime value %s", s)), which the CAST-to-DATETIME path surfaces to the user instead of returning NULL. By contrast the CAST-to-DATE path in pkg/sql/plan/function/func_cast.go already returns NULL for CAST('2026-02-30' AS DATE) and CAST('not a date' AS DATE) — verified on this build.
Recommended fix, keeping existing data/behavior compatible: make the scalar DATE() function and the CAST-to-DATETIME conversion append NULL for rows whose input string cannot be parsed (mirroring the CAST-to-DATE behavior), which matches MySQL 8.0 row-wise semantics. DATE_FORMAT('2026-02-30', '%Y-%m-%d') currently also errors (ERROR 20301 invalid input: invalid datetime value 2026-02-30 vs MySQL 2026-02-30) — the same parse call underlies it and should behave like MySQL: format what is parseable structurally and return the rendered string; if that part is considered covered by the open #30234 umbrella (zero/incomplete dates) it can be handled there separately.
Related history: issue #25306 ("date/time functions error on zero or invalid date strings instead of MySQL NULL/0 semantics") was closed on 2026-10-02, but its verification data contained only zero/incomplete dates and CONVERT_TZ-style cases; the scalar DATE() regression shown here is still reproducible on today's main (beffc64c486d), so this report tracks the residual path. Searches performed for dedup: date/time functions error, DATE invalid date, DATE('2026-02-30') — no open issue covers scalar DATE() on malformed calendar dates.
Full reproduction, exactly as Loom ran it
-- Run against MatrixOne (commit beffc64c486d) and against MySQL 8.0.46 with any mysql client.
-- MatrixOne: every statement 1-3 and 5-7 errors; MySQL 8.0.46: every statement returns NULL.
SELECT DATE('2026-02-30');
SELECT DATE('2026-13-01');
SELECT DATE('not a date');
SELECT CAST('2026-02-30' AS DATE); -- NULL on BOTH engines (MatrixOne cast path is correct here)
SELECT CAST('2026-02-30' AS DATETIME); -- MySQL: NULL | MatrixOne: ERROR 20301 invalid datetime value
SELECT CAST('not a date' AS DATETIME); -- MySQL: NULL | MatrixOne: ERROR 20301 invalid datetime value
SELECT DATE_FORMAT('2026-02-30', '%Y-%m-%d'); -- MySQL: '2026-02-30' | MatrixOne: ERROR 20301Found by Loom bug hunt (module: column-data; tests: unit, black-box, fuzzing)
Activity
Ariznawlll commentedon Oct 20, 2026
测试版本
main7c146f4adbf068dd0c06b377157cfb7d7698b1eb8dd623e7d7338669f1ae2c63ef555f17ec93a5d8,已确认进入上述 main。原问题验证
三轮 SQL 实测:
DATE('2026-02-30')、DATE('2026-13-01')、DATE('not a date')、CAST('2026-02-30' AS DATETIME)都从原先的查询错误变为NULL;协议结果中 DATE/DATETIME 类型分别为 10/12,IS NULL=1。默认严格模式、sql_mode=''与显式STRICT_TRANS_TABLES的相应查询均返回 NULL。DATE_FORMAT('2026-02-30','%Y-%m-%d')当前也返回 NULL。但原 issue 的 Expected Behavior 段明确要求 MySQL warning 1292。本轮在严格与非严格模式下对非法输入执行
SHOW WARNINGS,均没有记录;PR #30547 也明确写明未实现 1292 warning parity。此外,原 issue 的 Expected Behavior 列表把 DATE_FORMAT 预期写成 NULL,而末尾的补充段却写成字符串'2026-02-30';两处期望相互矛盾,本轮不能把当前 NULL 行为宣称为该路径已完成 MySQL 一致性验收。Happy Path 覆盖
DATE('2026-02-28')三轮均为2026-02-28,协议类型 DATE;DATE(NULL)为 NULL。2026-02-28/NULL/NULL/NULL,正常行的等值过滤COUNT(*)=1,未因脏行整体中断。三轮测试库均清理。Unhappy Path 覆盖
白盒验证
TestDateStringToDate及相关函数定向 Go 测试-count=3通过;未运行-race。回归测试
issue_30537_invalid_date_null.test与配对结果,覆盖非法/正常/NULL、混合行及两种 sql_mode;定向 3/3 通过(每次 13 条语句)。该回归只断言已确认的返回值和 NULL,不把缺失 warning 冒充为已通过。测试证据
SHOW WARNINGS无 1292。原 issue 与修复 PR fix(sql): return NULL for invalid DATE and DATETIME expressions #30547 对尚未覆盖的 warning 和 DATE_FORMAT 范围有上述差异。测试结论
测试不通过。
Ariznawlll commentedon Oct 23, 2026
Still reproducible for the TIME target on today's main (
3a1e42b430, 2026-10-23): the DATE/DATETIME cast paths now correctly return NULL for unparseable strings, butCAST(... AS TIME)still raises instead of returning NULL. Same root cause, one more target type the fix missed.The
TIMEcolumn/type uses the same strict-parse path (the20301 invalid time valueerror text) thatDATE/DATETIMEused to, but those two were relaxed whileTIMEwas left strict. AddingTIMEto the same NULL-on-unparseable-string handling closes the family.fix(sql): preserve temporal conversion warnings (#31746)
XuPeng-SH commentedon Oct 29, 2026
QA handoff for merged #31746 (
1c80f16a2bc2fd59d5ca5cadd8b5fb418f8b8244): this isolated QA run inspected the source and issue history but did not run current-head functional tests or live SQL because the existing resource guard left insufficient headroom. Please verify temporal warnings and row results, prepared/folding and multi-CN diagnostics. Author-reported PR tests are separate evidence and are not results of this QA run.Ariznawlll commentedon Nov 2, 2026
测试版本
8.0.30-MatrixOne-v1.3.0,SQL127.0.0.1:6001。原问题验证
执行
DATE('2026-02-30')和DATE('not-a-date')均返回 SQLNULL,不会中止查询;合法日期DATE('2026-01-15')正常返回日期值。Happy Path 覆盖
DATE('2024-02-29')返回正确日期。DATE(NULL)返回 NULL。6/6statements 通过。Unhappy Path 覆盖
2026-02-30返回 NULL,不再抛出致命错误。not-a-date返回 NULL。2023-02-29返回 NULL。白盒验证
本轮通过 SQL 黑盒验证 DATE() 的错误输入边界,未修改产品源码。
回归测试
已加入 matrixorigin/motr#304:
issue_30537_date_invalid_returns_null。测试证据
MOTR
--repeat 3成功,累计6/6statements 通过。测试结论
测试通过。
Ariznawlll commentedon Nov 2, 2026
测试结论更正
之前“测试通过”的结论和关闭操作过早,已重新打开 Issue。本轮实际运行的二进制构建 SHA 尚未确认,不能等同于最新官方 main。
补测原报告中的输入:
DATE('2026-13-01')、DATE('not a date')、无效值的 DATE/DATETIME CAST 返回 NULL;DATE_FORMAT('2026-02-30','%Y-%m-%d')返回 NULL,而原报告的 MySQL 参考结果是2026-02-30。需在确认版本的官方 main 上复核全部路径、SQL mode、混合行和相关语义,再给出验收结论。现有 MOTR 仅覆盖部分 DATE() 场景,尚未完成全套验收。Ariznawlll commentedon Nov 3, 2026
结论
测试通过。非法日期和时间文本在已测路径按行返回 NULL 并产生 1292 warning,不再中止整个查询。
关键证据
main@d61a7206c16b30baa4efc525eb6067c4364035aa的独立 MO;与隔离 MySQL 8.0.45 在空 SQL mode 和STRICT_TRANS_TABLES对照三轮。SHOW WARNINGS均为 1292;六类非法日期/时间结果和 warning 代码与 MySQL 8.0.45 的对照三轮一致。DATE_FORMAT('2026-02-30',...)本轮两端均为 NULL;此前报告对该值的期望描述相互矛盾,本次不宣称验证了 MySQL 8.0.46。TestDateStringToDate、时间 warning 与 CAST warning 定向 Go 测试各运行三轮。相关 SQL、预编译和诊断回归已加入 MOTR #305;新增场景与其他目标场景联合三轮 18/18。待解决点
MOTR PR 尚待评审合入;本轮 MySQL 对照版本是 8.0.45。