Repository navigation
Description
Description
Saving a DATA BRANCH DIFF result for a changed TIMESTAMP(6) column silently loses fractional seconds and applies the process-local timezone instead of the session timezone. Reading the result through RESULT_SCAN returns wrong timestamps, and INSERT ... SELECT persists those wrong values.
Environment
- Branch:
main - Commit:
f847803802289b2b2d0df4f0a2f842c2804b823a - Deployment: isolated local standalone launch, one CN, session
time_zone='+00:00'
Steps to reproduce
CREATE DATABASE q_branch_ts;
USE q_branch_ts;
SET time_zone = '+00:00';
CREATE TABLE b(id INT PRIMARY KEY, v TIMESTAMP(6));
INSERT INTO b VALUES
(1,'2023-01-01 00:00:00.000000'),
(2,'2023-01-01 00:00:00.000000');
DATA BRANCH CREATE TABLE c FROM b;
UPDATE c SET v = CASE id
WHEN 1 THEN '2024-01-01 00:00:00.123456'
WHEN 2 THEN '2024-01-01 00:00:00.654321'
END;
SET save_query_result=ON;
DATA BRANCH DIFF c AGAINST b;
SET @qid=last_query_id();
SELECT id,v FROM result_scan(@qid) AS r ORDER BY id;
CREATE TABLE copied(id INT PRIMARY KEY, v TIMESTAMP(6));
INSERT INTO copied SELECT id,v FROM result_scan(@qid) AS r;
SELECT id,v FROM copied ORDER BY id;Actual behavior
With session timezone UTC, the direct DIFF returns the correct values:
1 2024-01-01 00:00:00.123456
2 2024-01-01 00:00:00.654321
The saved result instead returns rounded values shifted by eight hours:
1 2023-12-31 16:00:00.000000
2 2023-12-31 16:00:01.000000
INSERT ... SELECT FROM result_scan(@qid) persists the same wrong values in copied.
Expected behavior
The saved DIFF result must preserve the exact TIMESTAMP(6) value and use the session timezone consistently with the direct result. Copying the saved result must not change data.
Stability and controls
- Reproducer: 3/3 fresh databases (
qbranchtsprec_01/02/03). Five fractional boundaries were used in each run:.123456,.499999,.500000,.654321,.999999; every saved value was wrong. - Control:
save_query_result=OFFreturned every exact microsecond value. An ordinary savedSELECT id,v FROM cfollowed byRESULT_SCANalso preserved every value exactly under the same session timezone. - Failure atomicity/data check: source and branch tables remained correct; only the saved DIFF and a table populated from it contained wrong values. The session remained usable.
Evidence
- Reproducer:
/private/tmp/mo-explore-run-20261028/data_branch_timestamp_precision.py - The run prints the exact direct DIFF, saved result, and persisted destination rows for all five boundaries.
Code analysis
pkg/frontend/util.go:mysqlColDef2PlanResultColDef maps MYSQL_TYPE_TIMESTAMP to types.T_timestamp with scale 0, discarding the wire column's fractional precision. convertRowsIntoBatch then receives the DIFF timestamp as a string and calls types.ParseTimestamp(time.Local, v, typ.Scale). This parses a session-UTC value using the process-local timezone and scale zero, explaining both the eight-hour shift and microsecond loss. Ordinary query results carry types.Timestamp and bypass this string parse, matching the passing control.
Regression coverage
Add a Git4Data/result-save regression covering TIMESTAMP(0/3/6) under process and session timezones that differ, fractional boundaries around half a second, RESULT_SCAN, and downstream INSERT ... SELECT exact-value comparison.
Related
- [Bug]: saved DATA BRANCH DIFF corrupts text and binary values returned by RESULT_SCAN #31535 changes VARCHAR/VARBINARY/vector saved DIFF values through a different formatting path.
- [Bug]: saving DATA BRANCH DIFF with DATETIME crashes the service #31547 covers process termination for DATETIME/TIME values through strict type assertions; this issue returns and persists wrong TIMESTAMP data instead.
Activity
fix: reject invalid global time_zone, save DATA BRANCH DIFF temporal …
XuPeng-SH commentedon Nov 14, 2026
QA 交接:已合并修复,待验收
PR #32456 已合入 main,merge SHA
625865c470631f33da52793a2e2766d63e5a316e,最终 head86d6fbf32cfb96ed8e0155d6124cec3e568ae4cb。证据边界:最终 head 的评审 #32456 (review) 复用 shared build、Ubuntu/x86 UT、arm64 SCA、coverage、PROXY/PESSIMISTIC BVT 成功结论;合并记录 CI Required 成功,队列未重跑 CI。评审只新做 diff check,未新跑 Go/集群,原始 CI/作者日志未供其复核。作者报告定向 BVT 57/57、system_variable 636/636、branch/diff 1976/1976;snapshot 18389/18454,65 项资源准入失败,不能称全目录通过。上述为远端记录和作者报告,本轮没有本地构建或实测。
修复保存结果列 TIME/DATETIME/TIMESTAMP scale 保留,并将 TIMESTAMP 文本按会话时区而非进程时区解析;当前完整讨论未见新版本反例或未完开发 follow-up。#31535 的字符串/二进制/vector 格式问题不包含在本次范围。
QA 建议 TIMESTAMP(0/3/6)、进程与会话时区不同、正负时区和小数秒半秒两侧边界,逐值比较直接 DIFF、RESULT_SCAN、INSERT SELECT 目标表和原表;覆盖 NULL、失败后连接复用及多 CN。作者计数不能替代该边界验收。
交 Ariznawlll 验证,保持 open;转测不代表验收通过,本轮未运行测试。
Ariznawlll commentedon Nov 15, 2026
结论
测试通过。main 上保存 DATA BRANCH DIFF 后 TIMESTAMP 丢失小数秒或使用错误时区的问题未再复现。
关键证据
mainc71e0c6904f444f45c4f4095be0e9f088b0c3b50,包含修复 PR fix: reject invalid global time_zone, save DATA BRANCH DIFF temporal results, reject snapshot-qualified write targets #32456;独立 Linux 容器、1 TN/LogService、双 CN,两个 CN 的git_version()均核对为该完整 SHA。未将本结果外推到 4.2-dev。14_issue_regression931 项中 800 通过、12 失败、119 跳过;12 项失败与更早同版本基线名单一致,不能称整套 CI 全绿。最新一轮结果同为 800 通过、12 失败、119 跳过,失败名单一致。RESULT_SCAN和 INSERT 目标表,结果一致。.123456、.499999、.500000、.654321、.999999,以及 NULL;普通保存 SELECT 为对照。待解决点