Skip to content

[Compatibility]: temporal formatting functions reject row-dependent format expressions #28566

Closed

Description

@Ariznawlll

现象

MatrixOne main(ac660ae56ecd37bab3dd8c61193617a323377029)要求 DATE_FORMAT()、TIME_FORMAT() 和双参数 FROM_UNIXTIME() 的格式参数必须是常量,因此不能按行使用格式列或依赖当前行的表达式。MySQL 8.0.46 支持这些用法。

CREATE TABLE src(
  id INT PRIMARY KEY,
  dt DATETIME(6),
  tm TIME(6),
  epoch DECIMAL(20,6),
  fmt VARCHAR(64)
);

INSERT INTO src VALUES
  (1,'2024-01-02 03:04:05.123456','12:34:56.123456',
     1704164645.123456,'%Y-%m-%d %H:%i:%s.%f'),
  (2,'2025-06-07 08:09:10.654321','23:45:01.654321',
     1749283750.654321,'%H:%i:%s.%f');

SELECT id, DATE_FORMAT(dt, fmt) FROM src ORDER BY id;
SELECT id, TIME_FORMAT(tm, fmt) FROM src ORDER BY id;
SELECT id, FROM_UNIXTIME(epoch, fmt) FROM src ORDER BY id;
SELECT id, DATE_FORMAT(dt, CASE WHEN id=1 THEN '%Y' ELSE '%m' END)
FROM src ORDER BY id;

MatrixOne 对以上语句分别返回同类错误:

invalid argument date format format, bad value not constant
invalid argument time format format, bad value not constant
invalid argument from_unixtime format, bad value not constant

MySQL 根据每行的 fmt 返回对应字符串;例如第一条返回:

1  2024-01-02 03:04:05.123456
2  08:09:10.654321

常量格式和 PreparedStatement 中单个格式参数在两端均可执行,问题限定在格式值随行变化的场景。

期望

上述三个函数应逐行读取格式参数,使格式列、CASE、IF、CONCAT 等行相关表达式具有与 MySQL 一致的语义。

代码定位

pkg/sql/plan/function/func_binary.go 的 DateFormat、TimeFormat 及四个 FromUnixTime*Format 实现均在入口处拒绝 !ivecs[1].IsConst(),并只读取格式向量的第 0 个值。

复现信息

  • MatrixOne main:ac660ae56ecd37bab3dd8c61193617a323377029
  • MySQL:8.0.46
  • 完整场景重复执行 3 次,结果一致

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added theissue type on Sep 10, 2026
  3. XuPeng-SH commented on Sep 10, 2026

    @XuPeng-SH
    Contributor

    Triage routing: assigned to @jiangxinmeng1. Labels normalized to kind/bug + needs-triage (existing compatibility labels, when present, are retained).

    Recommended PR decomposition:

    • PR-T1 — temporal format expressions (#28566 only): support row-dependent format expressions in DATE_FORMAT, TIME_FORMAT, and FROM_UNIXTIME. This changes the constant-expression/planner contract and vectorized execution, so it should stay isolated.
    • Keep it separate from #28567/#28597 (format output and locale semantics), #28572/#28573 (EXTRACT), and #28569/#28570 (temporal arithmetic/time-zone conversion).

    Suggested priority: P2 compatibility issue with a clear repro; confirm supported format-expression scope before implementation.

  4. 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: C24, C27, C36–C38 in the merged temporal design. DATE_FORMAT, TIME_FORMAT and formatted FROM_UNIXTIME read each row’s format expression; NULL value/format propagates, and repeated or alternating formats do not reuse an earlier row’s state.

    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 the original format-column query, empty/all-NULL batches and a real prepared format marker; compare values and result metadata.

    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

  5. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

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

    原问题验证

    按 issue 原始语义在上述 commit 重新执行并重复 3 次。STR_TO_DATE 的 format 可逐行变化,每行均按自己的格式解析,不再复用首行格式。

    Happy Path 覆盖

    覆盖同批次多种 DATE/DATETIME format 和重复值。

    Unhappy Path 覆盖

    覆盖某行格式不匹配、NULL format/value;只影响对应行,不污染其他行。

    白盒验证

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

    回归测试

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 当前结果:STR_TO_DATE 的 format 可逐行变化,每行均按自己的格式解析,不再复用首行格式。
    • 回归代码与 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

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions