Skip to content

[Compatibility]: TIMESTAMP(expr) returns TIMESTAMP(0) instead of MySQL DATETIME #30196

Closed

Description

@Ariznawlll

Summary

For the one-argument TIMESTAMP(expr) function, MatrixOne exposes a TIMESTAMP result with scale 0. MySQL documents this form as returning the input date/datetime expression as a DATETIME value. The MatrixOne type difference also truncates fractional seconds and makes a CTAS result depend on the session time zone when it is later read.

This is distinct from #26775, which covers the return type of DATE_ADD / DATE_SUB for a TIMESTAMP input, and from #28896, which covered conditional-expression precision.

Reproduction: type and fractional value

CREATE DATABASE repro;
USE repro;
CREATE TABLE c AS
  SELECT TIMESTAMP(CAST('2024-02-29 12:34:56.123456' AS DATETIME(6))) AS v;

SELECT column_type, datetime_precision
FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'c';
SELECT CAST(v AS CHAR) FROM c;
  • MatrixOne: column timestamp (precision 0); value 2024-02-29 12:34:56
  • MySQL 8.0.46: column datetime(6); value 2024-02-29 12:34:56.123456

The same truncation occurs with a string argument. The two-argument TIMESTAMP(expr1, expr2) control returned DATETIME(6) on both engines in this comparison.

Reproduction: session-time-zone dependency after CTAS

SET time_zone = '+00:00';
CREATE TABLE tz_copy AS
  SELECT TIMESTAMP('2024-02-29 12:34:56') AS v;
SELECT v FROM tz_copy;
SET time_zone = '+08:00';
SELECT v FROM tz_copy;

MatrixOne changes the stored value from 12:34:56 to 20:34:56; MySQL continues to return 12:34:56. This follows from the MatrixOne CTAS column being TIMESTAMP, while MySQL creates DATETIME for the one-argument function.

MySQL documents that one-argument TIMESTAMP() returns the date/datetime expression as a DATETIME: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

Environment

  • MatrixOne: local main-derived commit 2ce4e58af6f03b943ee288ffad81012766cf830a, server reports 8.0.30-MatrixOne-v1.3.0
  • MySQL: 8.0.46
  • Direct one-argument function and CTAS tested; temporary databases removed after comparison.

Activity

  1. added this to the MO-202610 milestone on Oct 14, 2026
  2. added theissue type on Oct 14, 2026
  3. added
    ai-easy
    on Oct 19, 2026
  4. Ariznawlll commented on Oct 19, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main
    • commit:8e63625c4e9baeb1d28c1095c07732f056c04895
    • 修复:fix: preserve prepared temporal result types and values #30224 MERGED,merge commit d82e828b0a4df9ce635fe573c1e90c5cde978bf9 已进入该 main。
    • 部署方式:隔离本地原生构建,1 CN / 1 TN / 1 LogService、MySQL 6001;专用测试库,结束后删除。
    • 测试日期:2026-10-19 UTC。

    原问题验证

    原始 CREATE TABLE c AS SELECT TIMESTAMP(CAST('2024-02-29 12:34:56.123456' AS DATETIME(6))) 独立 3/3:information_schema.columns 为 datetime(6)、精度 6,实际值 2024-02-29 12:34:56.123456,不再是旧 timestamp(0) 截断值。+00:00 建表后切换 +08:00 读取,3/3 仍是完全相同的值。

    Happy Path 覆盖

    1. 字符串参数的一元 TIMESTAMP('2024-02-29 12:34:56') CTAS 3/3 为 datetime 和 2024-02-29 12:34:56,切换时区后不变。
    2. 双参数 TIMESTAMP('2024-02-29','12:34:56.123456') 对照 3/3 为 2024-02-29 12:34:56.123456。

    Unhappy Path 覆盖

    1. TIMESTAMP(NULL)、TIMESTAMP('invalid') 各 3/3 返回 NULL,未出现错误值;专用库清理后不存在。本场景无跨表写入失败原子性路径。

    白盒验证

    同 SHA 定向 TestPreparedTemporalResultContracts|TestPreparedTemporalMarkerReuse|TestTemporalCompatibilityExecutionMatrix|TestDynamicTimeResultTypedCalendarAndMask,pkg/sql/plan/... -count=3 PASS;覆盖类型/精度求值。已有 MatrixOne 分布式 SQL 文件 test/distributed/cases/prepare/prepared_temporal_results.sql 包含时区切换与类型断言,本轮未独立运行该 BVT。

    回归测试

    MOTR #247 新增成对 t/issue_30195_30196_30197_prepared_temporal.test / r/*.result,当前 head 623ac129a7d011ae0d441cd4275d0100e5d8d854,定向 3/3、135/135 语句成功、0 skip;PR 未合入。完整 659 case suite 尝试启动后中断,专用库已清理;完整 suite/集成 CI 未完成。

    测试证据

    • MOTR #247 测试脚本与独立核对的期望结果;定向摘要:total=3 success=3 failed=0 skipped=0 | stmts=135 ok=135 fail=0。
    • 原始 CTAS 的实际类型、值、时区切换与 NULL 对照均在上述完整 SHA 的本地隔离服务上核对;未声称历史发布线已修复。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easyarea/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions