Skip to content

[Bug]: saved DATA BRANCH DIFF corrupts TIMESTAMP precision and timezone #31550

Closed

Description

@Ariznawlll

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=OFF returned every exact microsecond value. An ordinary saved SELECT id,v FROM c followed by RESULT_SCAN also 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

Activity

  1. added this to the MO-202610 milestone on Oct 28, 2026
  2. added
    kind/bug
    on Oct 28, 2026
  3. added theissue type on Oct 28, 2026
  4. added a commit that references this issue on Nov 14, 2026
    625865c
  5. XuPeng-SH commented on Nov 14, 2026

    @XuPeng-SH
    Contributor

    QA 交接:已合并修复,待验收

    PR #32456 已合入 main,merge SHA 625865c470631f33da52793a2e2766d63e5a316e,最终 head 86d6fbf32cfb96ed8e0155d6124cec3e568ae4cb。

    证据边界:最终 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;转测不代表验收通过,本轮未运行测试。

  6. Ariznawlll commented on Nov 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。main 上保存 DATA BRANCH DIFF 后 TIMESTAMP 丢失小数秒或使用错误时区的问题未再复现。

    关键证据

    • 测试版本:官方 main c71e0c6904f444f45c4f4095be0e9f088b0c3b50,包含修复 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。
    • 执行证据:双 CN 验证任务。对应 MOTR 定向步骤成功;前一轮同类定向记录两个 CN 各 15/15、无跳过;本次附加普通保存 SELECT 与失败原子性控制。
    • 回归:MOTR #345,main 专用;PR 已提交、待合入。
    • suite 边界:前一轮 14_issue_regression 931 项中 800 通过、12 失败、119 跳过;12 项失败与更早同版本基线名单一致,不能称整套 CI 全绿。最新一轮结果同为 800 通过、12 失败、119 跳过,失败名单一致。
    • 原始路径和 Happy case:进程时区为 +08:00;两个 CN 各重复 3 轮,每轮分别使用 UTC、+05:30、-07:00 会话时区。对 TIMESTAMP(0/3/6) 比较源表、保存开关 OFF/ON 的 DIFF、RESULT_SCAN 和 INSERT 目标表,结果一致。
    • 精度边界:覆盖 .123456、.499999、.500000、.654321、.999999,以及 NULL;普通保存 SELECT 为对照。
    • Unhappy case:重复主键插入被拒绝,已有目标数据不变,连接仍能执行后续查询。
    • 白盒:核对 fix: reject invalid global time_zone, save DATA BRANCH DIFF temporal results, reject snapshot-qualified write targets #32456 保留时间列 scale,并按会话时区解析 TIMESTAMP 文本,而非使用进程本地时区。

    待解决点

    • 本结论仅覆盖所列精度、时区和双 CN 测试范围;未覆盖其他数据类型或规模性能。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions