Skip to content

[Compatibility]: MAKEDATE truncates exact DECIMAL arguments instead of rounding #28495

Closed

Description

@Ariznawlll

Environment

  • MatrixOne: latest main, commit f0c31cd4b830be32442cf329e0a3fb08aa9c16c3
  • MySQL comparison: 8.3.0

Problem

MAKEDATE truncates exact DECIMAL year/day-of-year arguments to integers. MySQL rounds exact numeric arguments during integer conversion, so values with a fractional part of .5 or greater select a different year or day.

This issue is separate from #28493, which covers the function's incorrect VARCHAR return domain.

Reproduction

SELECT MAKEDATE(2024, CAST(1.4 AS DECIMAL(3,1)));
SELECT MAKEDATE(2024, CAST(1.5 AS DECIMAL(3,1)));
SELECT MAKEDATE(2024, CAST(1.9 AS DECIMAL(3,1)));
SELECT MAKEDATE(CAST(2024.5 AS DECIMAL(5,1)), 1);

MatrixOne returns:

2024-01-01
2024-01-01
2024-01-01
2024-01-01

MySQL 8.3 returns:

2024-01-01
2024-01-02
2024-01-02
2025-01-01

A year-end boundary also shows the one-day error:

SELECT MAKEDATE(2024, CAST(365.5 AS DECIMAL(4,1)));
-- MatrixOne: 2024-12-30
-- MySQL:    2024-12-31

Coverage

The DECIMAL behavior was reproduced three times through:

  • exact DECIMAL constants around .4, .5, and .9 boundaries;
  • DECIMAL year and day-of-year columns;
  • SQL prepared statement parameters;
  • CTAS, which persists the earlier date.

Integer and NULL controls behave normally. FLOAT/DOUBLE and character inputs are intentionally excluded from the compatibility claim because MySQL itself has path-dependent conversion behavior for those domains; this issue is limited to the stable exact-DECIMAL contract.

Code analysis

MAKEDATE registers both parameters as VARCHAR, so DECIMAL inputs are converted to text. MakeDateString in pkg/sql/plan/function/func_binary.go then falls back from ParseInt to ParseFloat and converts with int64(...):

yearFloat, err := strconv.ParseFloat(yearStrStr, 64)
...
year = int64(yearFloat)

The same logic is used for the day argument. The direct float-to-int conversion truncates toward zero and also unnecessarily loses the exact DECIMAL domain before conversion.

Activity

  1. added this to the MO-202609 milestone on Sep 9, 2026
  2. added theissue type on Sep 9, 2026
  3. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    Current service recheck (2026-10-15)

    The issue's exact DECIMAL cases were rerun against the local MatrixOne service source commit 2ce4e58af6f03b943ee288ffad81012766cf830a and live MySQL 8.0.45. The previously reported differences did not reproduce:

    • DECIMAL day arguments 1.4, 1.5, 1.9 and year-end 365.5 return the same dates in both engines.
    • DECIMAL year 2024.4, 2024.5, and 2024.9 return the same dates.
    • The same values from DECIMAL table columns and SQL PREPARE/EXECUTE parameters also match.
    • All listed cases matched in 3/3 runs; valid integer controls matched.

    This is runtime evidence only; I have not changed the issue state.

  4. jiangxinmeng1 commented on Oct 22, 2026

    @jiangxinmeng1
    Contributor

    已在远程机器 [email protected] 对 clean main(a949c88af0ed)运行 MAKEDATE 精确 DECIMAL 参数的 SQL 复现,舍入行为通过;该 issue 已修复。转给 Ariznawlll 跟进。

  5. Ariznawlll commented on Oct 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main
    • commit:cca94b810ce87a38d1af16d7b418ea727eeda81c(包含已合入修复 fix remaining date/time compatibility issues #28932 的 merge commit)
    • 部署方式:本地隔离工作树,1 LOG / 1 TN / 2 CN;通过 CN0 的真实 MySQL TCP 黑盒测试
    • 测试日期:2026-10-22

    原问题验证

    精确 DECIMAL 输入 1.4/1.5/1.9 分别得到 2024-01-01/02/02,MAKEDATE(2024.5,1)=2025-01-01;表列 (2024.5,1.5) 得到 2025-01-02。 独立启动环境重复 3/3 轮通过,未用开发者自测代替 QA。

    Happy Path 覆盖

    1. 临界舍入及年末 365.5 -> 2024-12-31 均与预期一致。
    2. 新增成对 SQL 回归定向重复 3/3 通过,结果与独立 Go 黑盒断言核对。

    Unhappy Path 覆盖

    1. 未观察到截断回归;本项为有效数值边界,未执行异常参数/溢出的大范围矩阵。
    2. 每轮在独立临时数据库执行并 DROP 清理;失败场景无残留表数据或错误 golden。

    白盒验证

    本轮未单独跑 Go UT / race;本问题为确定性 SQL 值或类型路径,以真实协议黑盒及 SQL 回归验收。完整 MatrixOne suite 未执行。

    回归测试

    • MOTR 汇总 PR #247,本项所在 t 用例 及同名 r 预期结果;定向 --repeat 3 通过。PR 当前仍 Open,尚未声称已合并或 CI 全绿。
    • 未运行完整 MOTR suite、TKE/集成 CI;不据此声称其他发布线通过。

    测试证据

    上述 PR 的成对 t/r、实际 main SHA,以及本地 go test ./pkg/tests/issues -run '^TestQATemporalScreenshot20261022$' -count=3 与 MOTR 定向 --repeat 3 均通过;黑盒临时测试仅用于本次独立验收,未作为持久产品代码提交。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions