Skip to content

[Bug]: CLONE and DATA BRANCH cannot use a table created earlier in the same transaction #26113

Closed

Description

@Ariznawlll

Summary

CREATE TABLE ... CLONE and DATA BRANCH CREATE TABLE cannot use a table
created earlier in the same explicit transaction as their source, even though
ordinary queries in that transaction can read the new table.

Tested version

main at 2eb7f523e5a10f352d3e258183ed8440510388de

Reproduction

DROP DATABASE IF EXISTS g4d_tx_repro;
CREATE DATABASE g4d_tx_repro;
USE g4d_tx_repro;

CREATE TABLE src(id INT PRIMARY KEY, v VARCHAR(20));
INSERT INTO src VALUES (1, 'a');

BEGIN;
DATA BRANCH CREATE TABLE c1 FROM src;

-- This succeeds and returns 1, so c1 is visible in the transaction.
SELECT COUNT(*) FROM c1;

-- This fails although c1 is visible above.
DATA BRANCH CREATE TABLE c2 FROM g4d_tx_repro.c1;
ROLLBACK;

The same problem is visible in the underlying clone path:

BEGIN;
CREATE TABLE c1 CLONE src;
SELECT COUNT(*) FROM c1;
CREATE TABLE c2 CLONE g4d_tx_repro.c1;
ROLLBACK;

Both variants were repeated three times with fresh databases.

Actual result

The first table is readable, but the second create fails:

c1_visible
1
ERROR 1064 (HY000): SQL parser error: table g4d_tx_repro-c1 does not exist

The rollback removes the first table and leaves no branch metadata from the
transaction.

Expected result

The second clone/branch create should resolve the table created earlier in the
same transaction, consistently with ordinary query visibility. Both tables
should commit or roll back together.

Code analysis

dataBranchCreateTable delegates to handleCloneTable. Without an explicit
snapshot, handleCloneTable creates an MO_TS hint using
tryToIncreaseTxnPhysicalTS and calls BackgroundExec.ExecRestore.

The restore source lookup reads the catalog at that timestamp and does not
include the transaction's newly created source table, while an ordinary query
through the shared transaction can already read it. The source-resolution path
therefore has different read-your-own-DDL semantics from the surrounding
transaction.

Additional checks

  • Two independent DATA BRANCH CREATE TABLE statements in one transaction
    succeed and create two metadata/snapshot records.
  • The failure also occurs with a fully qualified source table name.
  • After ROLLBACK, neither c1 nor c2 remains.

Activity

  1. added this to the MO-202607 milestone on Jul 23, 2026
  2. added
    kind/bug
    on Jul 23, 2026
  3. added theissue type on Jul 23, 2026
  4. VioletQwQ-0 commented on Jul 31, 2026

    @VioletQwQ-0
    Collaborator

    Post-merge QA handoff for PR #26293.

    QA Decision

    • required: yes
    • reason: this changes explicit-transaction visibility plus persisted Data Branch ancestry/protection metadata and later DIFF behavior.
    • production_entrypoint: CREATE TABLE ... CLONE, ... COPY GRANTS, and DATA BRANCH CREATE TABLE/DIFF through one client transaction.
    • automated_terminal_coverage: the authenticated embedded regression covers raw CLONE, COPY GRANTS, three-level branch chains, exact committed lineage/protect snapshots, dropped intermediate and zero-history LCA DIFF in both directions, and rollback cleanup; test/distributed/cases/git4data/clone/clone_can_rollback.sql also passed exact-head BVT.
    • remaining_validation: deployed Proxy + multi-CN verification of the same transaction, catalog, privilege, and cleanup terminals.

    Merge evidence:

    • PR final head: 5bf795867c2a23c13aff1b2f366f10f96353564a
    • Merge commit: 0a3e5a46faa92d2add7f925d084ebc929adadc07
    • Handoff baseline (main at preparation): d510c8c3c475d5255e2e31c5a53b4a079054533d; test current or newer main.
    • Exact-head Ubuntu UT, SCA, coverage, Proxy/Pessimistic BVT, and TKE BVT/SSB/TPCH/SYSBENCH/TPCC passed.

    Please verify on a deployed Proxy + multi-CN environment, using one connection:

    1. Retain an autocommit control and an explicit named-snapshot control.
    2. Inside BEGIN, build multi-level raw CLONE, COPY GRANTS, and Data Branch chains from objects created earlier in that transaction; verify read-your-own-DDL and grant visibility.
    3. Commit, then verify exact mo_branch_metadata ancestry and one matching branch-protect snapshot per live branch. Drop an intermediate ancestor and verify direct, deep, sibling-LCA, unchanged, mutated, and reverse DIFF results.
    4. Repeat the construction with ROLLBACK; verify no created tables, copied privileges, branch metadata, or branch snapshots remain.

    Pass: all statements and DIFF counts are correct, persisted ancestry/protection metadata is exact, and rollback leaves no state. Fail: source/grant lookup error, incorrect DIFF, missing/duplicate metadata or snapshots, or any rollback leak.

  5. Ariznawlll commented on Aug 1, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:15a2d07c687a62a0984cf62846b092912a28c0f1
    • 部署方式:本地双 CN + Proxy;显式事务通过同一会话执行。
    • 测试日期:2026-08-01

    原问题验证

    在一个显式事务内,先创建源表,再创建 raw CLONE、三级 Data Branch 和 COPY GRANTS CLONE。连续 3 轮提交后,五个对象均可读到两行;三级 branch lineage 元数据完整,且 COPY GRANTS 的 SELECT 授权存在。

    Happy Path 覆盖

    1. 覆盖同事务可见的 raw CLONE、Data Branch 链和 COPY GRANTS。
    2. 修改中间分支后 DATA BRANCH DIFF 可识别一处变化;删除中间分支后,深层分支与源表 DIFF 仍正确为 0。

    Unhappy Path 覆盖

    1. 对同样的 raw CLONE、三级 Data Branch 和 COPY GRANTS 路径执行 ROLLBACK。
    2. 回滚后 mo_tables 中不存在四个新对象,未泄漏表、branch 元数据或授权。

    白盒验证

    • 不适用:事务可见性、回滚原子性和授权复制均由 SQL/catalog 直接验证。

    回归测试

    • 本轮未新增 motr/BVT 文件;该多语句事务场景适合 Data Branch 黑盒回归。

    测试证据

    • 执行:Data Branch/CLONE 黑盒审计连续 3 轮。
    • 每轮均记录:PASS 26113_transaction_visibility_clone_branch_copy_grants_and_rollback_cleanup。

    测试结论

    测试通过。

  6. Ariznawlll commented on Aug 1, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:15a2d07c687a62a0984cf62846b092912a28c0f1
    • 部署方式:本地单 CN MatrixOne,motr 通过 MySQL 协议执行 SQL 黑盒用例
    • 测试日期:2026-08-01

    原问题验证

    在显式事务中创建源表 base,先执行 DATA BRANCH CREATE TABLE first_branch FROM base,再在同一事务中以 first_branch 为源创建 second_branch。这覆盖了原问题的“前一个 Data Branch 创建的表在同一事务内不可见”路径。

    本次新增黑盒回归连续执行 3 轮,每轮 47 条语句/断言,3/3 均成功;与 #26111、#26070 共用的回归用例总计 141 条语句/断言成功。

    Happy Path 覆盖

    1. 同一显式事务内连续创建两张 Data Branch 表;第二张表读取结果 nested_visible=1,证明首个 Data Branch 创建的表在该事务内可作为后续源表。
    2. 使用带主键和普通字符串列的基表,确认不是空表或无约束的偶然成功。

    Unhappy Path 覆盖

    1. 连续建表后执行 ROLLBACK,检查 mo_catalog.mo_tables;first_branch 与 second_branch 的计数为 0。
    2. 回滚不留下部分元数据或半创建表,验证原子性和事务可见性没有以脏状态为代价。

    白盒验证

    未增加独立故障注入。此问题是公开事务 SQL 的可观察行为,黑盒用例直接验证事务内可见性及 rollback 清理;不以内部 mock 替代实际 catalog 与事务路径。

    回归测试

    已加入 motr 黑盒回归:PR #74,测试文件:issue_26113_26111_26070_branch_integrity.test。

    测试证据

    执行命令:./motr --config /tmp/motr-git4data-fulltext-blackbox-config.yml --repeat 3 --do-test 'issue_(26144|26113)' -v。其中本用例 3 轮均为 success,共 141/141 条语句/断言成功;对应回归提交:8f0f759。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugphase/testing

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions