Skip to content

[Feature Request]: support new data branching syntax #21979

Closed

Description

@XuPeng-SH

Is there an existing issue for the same feature request?

  • I have checked the existing issues.

Is your feature request related to a problem?

Describe the feature you'd like

Support new data branching syntax

Describe implementation you've considered

No response

Documentation, Adoption, Use Case, Migration Strategy

Additional information

No response

Activity

  1. added this to the MO-2507 milestone on Jun 6, 2025
  2. added
    priority/p0
    on Jun 6, 2025
  3. added theissue type on Jun 6, 2025
  4. Repository owner unassigned on Aug 28, 2025
  5. gouhongshen commented on Oct 29, 2025

    @gouhongshen
    Contributor

    data branch (data branch 功能需要 clone 功能支持) 描述:

    data branch 能够让用户像使用 git 一样操纵 mo 的数据,提供了如下的功能:

    创建 branch:

    data branch create table/db/account x clone ...
    (暂不支持, 目前是用 clone 创建 branch, 只要执行 clone, 即创建了一个 branch, 可以通过 mo_catalog.mo_branch_metadata 查看)

    create table t2 clone t1 {snapshot}: 从 t1.snapshot 分支生成 t2.

    |

    比较两个表的不同

    data branch diff t1 against t2 output_option

    1. data branch diff t1 against t2 会返回所有的 diff
    2. data branch diff t1 against t2 output limit x只返回 x 个 diff
    3. data branch diff t1 against t2 output count只返回 diff 的数量

    两个表的 diff 是通过 pk 去比较的,如果 pk 相同就认为是同一行,如果剩余的列的值不同,就判定为 diff,如果没有 pk, 那么所有列的组合构成 pk. 例子:

    create table t1(a varchar(10) primary key, b varchar(10));
    create table t2 clone t1 {snapshot}
    insert into t1 values("pk1", "a");
    insert into t2 values("pk1", "b");
    

    那么,data branch diff t2 against t1 的 结果就是:

    mysql> data branch diff t2 against t1;
    +--------------------+------+------+------+
    | diff t2 against t1 | flag | a    | b    |
    +--------------------+------+------+------+
    | t2                 | -    | pk1  | a    |
    | t2                 | +    | pk1  | b    |
    +--------------------+------+------+------+
    2 rows in set (0.01 sec)
    

    merge 两个表

    将 diff t1 against t2 的结果 merge 进 t2. 根据 conflict 有下面三种情况:

    1. data branch merge t1 into t2 when conflict fail. 默认,等同于省略 conflict_opt,遇到 conflict就报错返回。
    2. data branch merge t1 into t2 when conflict skip. 跳过 conflict 的行,保留 t2 对应的行
    3. data branch merge t1 into t2 when conflict accept. 接受 conflict的行,用 t1 的行替代 t2 对应的行。

    同样是上面的例子:

    mysql> data branch merge t2 into t1;
    ERROR 20101 (HY000): internal error: merge diff conflict happend
    
    
    mysql> data branch merge t2 into t1 when conflict fail;
    ERROR 20101 (HY000): internal error: merge diff conflict happend
    
    
    mysql> data branch merge t2 into t1 when conflict skip;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> select * from t1;
    +------+------+
    | a    | b    |
    +------+------+
    | pk1  | a    |
    +------+------+
    1 row in set (0.00 sec)
    
    
    mysql> data branch merge t2 into t1 when conflict accept;
    Query OK, 0 rows affected (0.02 sec)
    
    mysql> select * from t1;
    +------+------+
    | a    | b    |
    +------+------+
    | pk1  | b    |
    +------+------+
    1 row in set (0.00 sec)
    
    

    更多的细节,可以参考 BVT cases: snapshot/branch

  6. ghost added a commit that references this issue on Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/featurepriority/p0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions