Repository navigation
Description
Problem
FROM_DAYS() maps every day number below the first representable non-zero date (366) to SQL NULL in MatrixOne. MySQL 8.3 returns the DATE sentinel 0000-00-00 for this range.
MatrixOne already models MySQL zero dates explicitly (types.ZeroDate) and supports them through parsing, storage, and the wire protocol, so this is a function implementation gap rather than a general decision to reject zero dates.
Tested on MatrixOne main commit f0c31cd4b830be32442cf329e0a3fb08aa9c16c3 and MySQL 8.3.0. The MatrixOne result was reproduced three times under each SQL mode below.
Reproduction
SET SESSION sql_mode='';
SELECT FROM_DAYS(0), FROM_DAYS(1), FROM_DAYS(365), FROM_DAYS(366);MatrixOne:
NULL | NULL | NULL | 0001-01-01
MySQL:
0000-00-00 | 0000-00-00 | 0000-00-00 | 0001-01-01
Negative day numbers also return 0000-00-00 in MySQL, while MatrixOne returns NULL.
SQL-mode behavior
The scalar-expression difference is unchanged under:
- empty
sql_mode NO_ZERO_DATESTRICT_TRANS_TABLESSTRICT_TRANS_TABLES,NO_ZERO_DATE
MySQL's NO_ZERO_DATE checks apply when a generated zero date is written into a table, not to the scalar result of FROM_DAYS() itself. MatrixOne currently returns NULL before that distinction can be made.
Row and persistence coverage
CREATE TABLE src(n BIGINT);
INSERT INTO src VALUES (-1), (0), (1), (365), (366), (730485), (3652424), (3652425);
SELECT n, FROM_DAYS(n), TO_DAYS(FROM_DAYS(n)) FROM src ORDER BY n;
CREATE TABLE copied AS SELECT n, FROM_DAYS(n) AS d FROM src;The row-wise MatrixOne result stores NULL for n <= 365 in CTAS. With non-strict mode MySQL stores 0000-00-00. The behavior is also reproduced with a bound/prepared parameter.
Controls
FROM_DAYS(366)returns0001-01-01in both systems.FROM_DAYS(730485)returns2000-01-01in both systems.FROM_DAYS(3652424)returns9999-12-31in both systems.- Values above the supported upper date range return
NULLin both systems. TO_DAYS(FROM_DAYS(n)) = nfor representable dates in both systems.- MatrixOne remains healthy after all boundary queries.
Code analysis
pkg/sql/plan/function/func_builtin.go, builtInFromDays, computes an interval relative to types.DatetimeEpoch (0001-01-01). For day numbers below 366, Datetime.AddInterval rejects the underflow and the function appends types.Date(0) with the null flag set.
The underflow branch does not distinguish the MySQL zero-date range from a true upper overflow, and it does not return the existing types.ZeroDate sentinel.
Expected behavior
FROM_DAYS(n) should return the DATE sentinel 0000-00-00 for day numbers that MySQL maps to the pre-year-1 range, reserving SQL NULL for actual out-of-range overflow. Subsequent assignment/CTAS should then apply the active SQL-mode rules independently.
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: C26, C30 in the merged temporal design. FROM_DAYS of every signed value below 366 yields the typed zero-date sentinel; 366 is 0001-01-01, 3652424 is 9999-12-31, and larger values are NULL. Under NO_ZERO_DATE, DATE(FROM_DAYS(0)) is NULL while raw YEAR(FROM_DAYS(0)) remains 0.
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. Verify original negative/zero/boundary inputs, TO_DAYS round-trips on ordinary dates, and SELECT/CTAS metadata under both SQL modes.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 次。FROM_DAYS(0/1/365) 返回 typed zero-date,366 返回 0001-01-01;不再把 pre-year-1 一律变成 NULL。
Happy Path 覆盖
覆盖 0、1、365、366 和普通现代日期。
Unhappy Path 覆盖
覆盖负数、上界外值及 NO_ZERO_DATE 下的显式 DATE 消费;返回 zero-date 或 NULL 与 contract 一致。
白盒验证
关联修复 #28851 已进入当前
main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。回归测试
suites/14_issue_regression/t/issue_recent_temporal_contracts.test714/714条语句通过。测试证据
d50a2d475a406829f67127fef7b2ad4abc1c1d3d14_issue_regression中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。测试结论
测试通过。