Skip to content

[Compatibility]: JSON constructors omit zero fractional seconds for TIME and DATETIME values #28056

Closed

Description

@Ariznawlll

Description

When JSON constructors receive TIME(0) or DATETIME(0) values, MatrixOne serializes them without a fractional component. MySQL 8 serializes the same values in JSON with six zero fractional digits. This changes the JSON string value seen by JSON_EXTRACT/JSON_UNQUOTE, so equality, ordering, generated columns, and indexes built from that value can differ across the two systems.

Environment

  • Branch: main
  • Commit: 95d04586eb80864499d0fde27aeb912b463ae4cd
  • Deployment: local single-CN MatrixOne

Steps to reproduce

SELECT
  JSON_UNQUOTE(JSON_EXTRACT(
    JSON_OBJECT('tm', CAST('04:05:06.123456' AS TIME)), '$.tm')) AS tm,
  JSON_UNQUOTE(JSON_EXTRACT(
    JSON_OBJECT('dt', CAST('2024-02-03 04:05:06.123456' AS DATETIME)), '$.dt')) AS dt;

Actual behavior

MatrixOne returns:

04:05:06 | 2024-02-03 04:05:06

MySQL 8 returns:

04:05:06.000000 | 2024-02-03 04:05:06.000000

The same MatrixOne behavior occurs through JSON_OBJECT and JSON_ARRAY.

Expected behavior

For compatibility with MySQL JSON constructors, TIME(0) and DATETIME(0) values should be represented in JSON with .000000 rather than omitting the fractional component.

Stability and controls

Code analysis

pkg/sql/plan/function/func_builtin_json.go converts TIME, DATETIME, and TIMESTAMP through String2(fromType.Scale) before creating typed JSON values. With scale 0, that produces text without .000000.

Regression coverage

After a fix, add a deterministic SQL regression covering TIME(0), DATETIME(0), and explicit scale controls through JSON_OBJECT, JSON_ARRAY, and JSON_SET.

Related

Activity

  1. added this to the MO-202609 milestone on Sep 3, 2026
  2. added
    kind/bug
    on Sep 3, 2026
  3. added theissue type on Sep 3, 2026
  4. Ariznawlll commented on Sep 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充影响范围:

    JSON_ARRAYAGG 对 TIME(0) 和 DATETIME(0) 也出现同一 JSON 文本差异。

    CREATE TABLE t (tm TIME, dt DATETIME);
    INSERT INTO t VALUES ('04:05:06', '2024-02-03 04:05:06');\nSELECT JSON_ARRAYAGG(tm), JSON_ARRAYAGG(dt) FROM t;\n```\n\nmain @ `95d04586eb80864499d0fde27aeb912b463ae4cd` 连续三次输出:\n\n```text\n["04:05:06"] | ["2024-02-03 04:05:06"]\n```\n\nMySQL 8 连续三次输出:\n\n```text\n["04:05:06.000000"] | ["2024-02-03 04:05:06.000000"]\n```\n\n因此受影响的 JSON 入口不仅是 `JSON_OBJECT`、`JSON_ARRAY`、`JSON_SET`,还包括 `JSON_ARRAYAGG`。`DATE` 与 `ENUM` 聚合在两端一致;YEAR 聚合输入被拒绝的问题单列在 #28061。
  5. Ariznawlll commented on Sep 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    再补充 TIMESTAMP 与时区范围:

    在会话 +00:00 插入 TIMESTAMP '2024-02-03 04:05:06',切换到 +08:00 后,MO 和 MySQL 的普通 TIMESTAMP 读取都为 2024-02-03 12:05:06,说明时区换算正确。\n\n但 JSON_OBJECT('ts', ts) 经提取后,MO 连续三次为 2024-02-03 12:05:06,MySQL 8 为 2024-02-03 12:05:06.000000。\n\n因此 #28056 同时涉及 TIME、DATETIME、TIMESTAMP 的 scale-0 JSON 序列化;时间值的时区转换本身未见偏差。

  6. added
    severity/s1
    and removed on Sep 8, 2026
  7. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    【QA 交接|PR #28093 已合并】

    关联合并:PR #28093(merge commit 8836fb4);当前 main=1cfec4c80134adc5640a3bbf1aef7aaa87a45282。

    本次范围:JSON_OBJECT、JSON_ARRAY、JSON_SET 及相关聚合入口对 TIME/DATETIME/TIMESTAMP scale-0 值的 MySQL 兼容序列化,期望保留六位小数;TIMESTAMP 必须按 session timezone 转换但保留 DATETIME JSON atom 语义。请覆盖普通入口、JSON_ARRAYAGG、+00:00/+08:00 时区切换、NULL/预编译路径、单 CN 与多 CN、重启后读取。

    合并后证据:PR required checks 无失败;本地 exact-main CGo 自测因缺少 cgo/libmo.dylib 阻塞,mo-tester 未安装,未宣称本地 PASS。

    请在合并版本连续复验上述场景;PASS 标准是结果与 MySQL 8 完全一致,FAIL 时请保留 SQL、main SHA、重复轮次和实际/期望结果。

  8. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    补充 pin:远端 main 已推进到 9f87b62。请以该当前 main 复验;此前列出的合并提交、测试范围和 PASS/FAIL 标准保持不变。该更新不代表 QA PASS。

  9. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    再次补充 pin:远端 main 已推进到 9cedf6e。请以该当前 main 复验;此前列出的合并提交、测试范围和 PASS/FAIL 标准保持不变。该更新不代表 QA PASS。

  10. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    Automation checkpoint: merged PR #28093 is being validated against current upstream/main 6d44c50. This issue remains open in phase/testing; no terminal tester PASS has been recorded in the current handoff. Please report complete version, environment, scoped scenario results, and terminal PASS/FAIL evidence before any closure decision.

  11. Ariznawlll commented on Sep 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:a9d3b8b857c44f1249e682c91d4d62a914eb7d20
    • 环境:本地单机 MatrixOne,2026-09-09。

    原问题验证

    验证 temporal 值写入 JSON object、array 和 set 时的小数秒精度及类型语义。

    Happy Path 覆盖

    • scale 0 的 TIME/DATETIME 输出带 .000000;scale 6 的值保留原微秒;
    • JSON object、array、set 三种容器结果均正确,连续 3 轮通过。

    Unhappy Path 覆盖

    本 issue 的核心是合法 temporal 的精度编码;以 scale 0 与 scale 6 作为两端边界,确认不会丢失微秒或将零精度编码为非时间值。

    白盒验证

    不适用:通过 JSON 文本和容器查询结果验证外部契约。

    回归测试

    • 已加入 MOTR PR #152:suites/14_issue_regression/t/issue_28056_28057_28058_28060_json_constructor_types.test。
    • --record --repeat 3 和非 record --repeat 3 均通过;PR 共 21/21 用例、321/321 条语句成功。

    测试证据

    时间类型、两个精度端点和三种 JSON 容器均重复 3 次。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugphase/testingseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions