Skip to content

[Compatibility]: session timestamp override is unavailable for current-time expressions and automatic TIMESTAMP columns #28599

Closed

Description

@Ariznawlll

Environment

  • MatrixOne: main at fc621e3616d229c7a29d0c80e73ed8eb1997459c
  • MySQL reference: 8.0.46
  • Session time zone: +00:00

Problem

MatrixOne does not define MySQL's session timestamp system variable. Reading or setting @@session.timestamp returns internal error: the system variable does not exist.

MySQL uses this variable to override the session's current time for deterministic execution. A nonzero value controls NOW, CURRENT_TIMESTAMP, LOCALTIME, LOCALTIMESTAMP, UTC_TIMESTAMP, UNIX_TIMESTAMP(), and automatic DEFAULT/ON UPDATE CURRENT_TIMESTAMP evaluation. Setting it to zero restores the real clock. SYSDATE() intentionally remains tied to the real clock.

This behavior is documented by MySQL under the timestamp system variable.

Reproduction

SET SESSION time_zone = '+00:00';
SET SESSION timestamp = 1704067200.123456;
SELECT @@session.timestamp;

SELECT NOW(6), CURRENT_TIMESTAMP(6), LOCALTIME(6),
       LOCALTIMESTAMP(6), UTC_TIMESTAMP(6), UNIX_TIMESTAMP(), SYSDATE(6);

PREPARE p FROM 'SELECT NOW(6), CURRENT_TIMESTAMP(6), UTC_TIMESTAMP(6), UNIX_TIMESTAMP()';
EXECUTE p;

CREATE TABLE t (
  id INT PRIMARY KEY,
  created_at TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6),
  updated_at TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6)
    ON UPDATE CURRENT_TIMESTAMP(6)
);
INSERT INTO t(id) VALUES (1);

SET SESSION timestamp = 1704067260.5;
UPDATE t SET id = 2 WHERE id = 1;
SELECT id, created_at, updated_at FROM t;
EXECUTE p;

SET SESSION timestamp = 0;
EXECUTE p;

MatrixOne behavior

SET SESSION timestamp = 1704067200.123456
ERROR 20101: internal error: the system variable does not exist

SELECT @@session.timestamp
ERROR 20101: internal error: the system variable does not exist

All affected functions and automatic timestamp columns continue to use wall-clock time.

MySQL 8.0.46 behavior

  • @@session.timestamp returns 1704067200.123456.
  • The affected functions return 2024-01-01 00:00:00.123456; repeated executions of the prepared statement return the same frozen value.
  • The inserted row receives 2024-01-01 00:00:00.123456 for both automatic columns.
  • After changing the variable to 1704067260.5, updated_at becomes 2024-01-01 00:01:00.500000, while created_at remains unchanged.
  • SYSDATE(6) continues to return wall-clock time.
  • Setting the variable to zero restores real-time evaluation.

Impact

Applications and test tools that rely on MySQL's session clock override cannot obtain deterministic current-time expressions or deterministic automatic timestamp values in MatrixOne. The same SQL either errors while configuring the session or silently uses wall-clock time if the configuration step is omitted.

Code analysis

pkg/frontend/variables.go registers several MySQL-compatible temporal variables, including default_week_format, explicit_defaults_for_timestamp, and lc_time_names, but has no timestamp system-variable definition. Current-time expressions therefore only receive the statement execution time and have no session override to consume.

The behavior above was reproduced three times with fresh databases and connections. Direct execution, prepared-statement reuse, automatic column defaults, automatic ON UPDATE, and the zero-reset control were covered.

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-T7 — TIMESTAMP defaults/current-time behavior (#28598 + #28599): align explicit_defaults_for_timestamp, automatic TIMESTAMP columns, and session timestamp override. They share TIMESTAMP default-value generation and need DDL plus INSERT/UPDATE coverage.
    • Keep #28570 separate because DST gap mapping is a time-zone conversion contract, not default generation.

    Suggested priority: P2; confirm exact MySQL mode/version compatibility before changing DDL behavior.

  4. jiangxinmeng1 commented on Oct 22, 2026

    @jiangxinmeng1
    Contributor

    已在远程机器 [email protected] 的 clean main(dcb0f52ff758)运行 SQL 复现:SET SESSION timestamp=1704067200.123456 后 NOW(6) 返回 2024-01-01 00:00:00.123456;无参数 UNIX_TIMESTAMP() 返回对应整秒 1704067200;TIMESTAMP(6) 的 DEFAULT CURRENT_TIMESTAMP(6) 使用覆盖时间。重新设置 timestamp=1704067260.5 后,ON UPDATE CURRENT_TIMESTAMP(6) 将该列更新为 2024-01-01 00:01:00.500000;SET timestamp=0 也成功。对应修复 PR #28932 已合入 main。此项在 main 上验证通过,转给 Ariznawlll 跟进。

  5. Ariznawlll commented on Oct 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main;测试日期:2026-10-22。
    • 实际测试 commit:75ae9a79d626622e6ccec0bcb28412f5fcf84c7f,是该轮执行时核对的官方 main;发布评论时 main 已前进,本评论不声称测试过后续提交。
    • 修复 PR #28932 已 MERGED;merge commit 0c3f7e035d90fbcf205b3164c560eda2df38335e 已核实位于上述测试 SHA 的祖先链。
    • 隔离 macOS arm64 部署:2 CN / 1 TN / 1 LogService,DISK-V2;本场景经公共 TCP 连接一个 CN,不宣称跨 CN 故障恢复验证。
    • 实际 mo-service 构建信息 vcs.revision 与上述 SHA 一致,运行时 git_version 为 75ae9a7。工作树受跟踪源码无差异,但含其他未跟踪 QA 文件,build info 为 vcs.modified=true;不是官方发布二进制。

    原问题验证

    UTC 会话执行 SET SESSION timestamp=1704067200.123456,连续 3/3 轮验证。NOW(6)、CURRENT_TIMESTAMP(6)、LOCALTIME(6)、LOCALTIMESTAMP(6)、UTC_TIMESTAMP(6) 均为 2024-01-01 00:00:00.123456;变量读回误差不超过 1 微秒。无参 UNIX_TIMESTAMP() 按研发澄清返回整数 1704067200,不把它误判为应带小数。

    Happy Path 覆盖

    1. SYSDATE 仍跟随真实时钟,未被会话覆盖值冻结。
    2. 真实二进制预处理语句连续执行两次返回上述冻结时间;修改 timestamp 为 1704067260.5 后,同一句已准备语句返回 2024-01-01 00:01:00.500000。
    3. TIMESTAMP(6) DEFAULT 插入值为首个冻结时间;真实 UPDATE 后 updated_at 为新的冻结时间,created_at 保持原值。
    4. timestamp=0 后 UNIX_TIMESTAMP 恢复真实时钟范围,已准备语句不再停留于旧冻结值。

    Unhappy Path 覆盖

    本项没有执行非法 timestamp 数值域测试,不声称覆盖了所有变量输入校验。已验证显式恢复 timestamp=0;清理路径还会 ROLLBACK、重置 timestamp、删除并核对测试数据库、关闭连接,避免会话状态泄漏。

    白盒验证

    本次新增回归不导入 MatrixOne 内部源码,不用内部 mock 替代产品路径;通过实际服务的 SQL/客户端协议接口断言。本次 MOTR 迁移验证未新增或重跑内部 Go/race 测试。

    回归测试

    已提交独立 MOTR PR #258,head e8a012246457624f7091c44f6d3445a4ebab1f48;从官方 MOTR main 建立,不追加 #247,也没有新建 MO 仓库 PR。该回归 PR 目前 OPEN,未声称已合入。

    • 固定版本场景代码。
    • 正常 MOTR runner 定向执行两套场景,各重复 3 次:total=6 / success=6 / failed=0 / skipped=0。本 issue 对应场景为 3/3,不把同组其他场景累计成它的次数。
    • 离线框架测试 431 项通过;这是测试框架/oracle 验证,不是 431 项产品验收。
    • 未执行完整 MOTR 产品 suite、完整 14_issue_regression suite、Linux/TKE 验证或修复前二进制对照。
    • CI run 39767106305 的四个 job 在任何步骤开始前被 Actions budget 阻止,steps 为空。CI 未执行,不记为通过,也不记为产品失败。

    测试证据

    本地原始日志:/tmp/mo-seven-qa-jc6Q4H/motr-migration-final.log,最终汇总 total=6 success=6 failed=0 skipped=0、耗时 13.00s,任务自有服务退出码 0。离线日志:motr-migration-offline.log。本地文件不是已上传的 GitHub artifact;可公开检查的测试实现见上述固定版本链接及 PR。

    本结论限定为上述 main SHA 的本 issue 原问题及所列边界;不代表 4.2 发布线、完整集成 CI 或所有分布式场景已通过。

    测试结论

    测试通过。

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