Repository navigation
Description
Environment
- MatrixOne:
mainatfc621e3616d229c7a29d0c80e73ed8eb1997459c - 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.timestampreturns1704067200.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.123456for both automatic columns. - After changing the variable to
1704067260.5,updated_atbecomes2024-01-01 00:01:00.500000, whilecreated_atremains 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
XuPeng-SH commentedon Sep 10, 2026
Triage routing: assigned to @jiangxinmeng1. Labels normalized to
kind/bug+needs-triage(existing compatibility labels, when present, are retained).Recommended PR decomposition:
#28598 + #28599): alignexplicit_defaults_for_timestamp, automatic TIMESTAMP columns, and session timestamp override. They share TIMESTAMP default-value generation and need DDL plus INSERT/UPDATE coverage.#28570separate 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.
jiangxinmeng1 commentedon Oct 22, 2026
已在远程机器 [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 跟进。
Ariznawlll commentedon Oct 22, 2026
测试版本
75ae9a79d626622e6ccec0bcb28412f5fcf84c7f,是该轮执行时核对的官方 main;发布评论时 main 已前进,本评论不声称测试过后续提交。0c3f7e035d90fbcf205b3164c560eda2df38335e已核实位于上述测试 SHA 的祖先链。原问题验证
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 覆盖
2024-01-01 00:01:00.500000。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,未声称已合入。测试证据
本地原始日志:
/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 或所有分布式场景已通过。
测试结论
测试通过。
test: cover temporal SQL compatibility fixes (#28232 #28154 #28599) (#…