Skip to content

[Feature Request]: Support schema evolution in DATA BRANCH DIFF / MERGE #24549

Closed

Description

@dengn

Version: 8.0.30-MatrixOne-v3.0.11 (MatrixOne v3.0.11)

DATA BRANCH DIFF/MERGE require the two tables to have an identical schema. Adding a column on a branch (a normal data-evolution step, e.g. a new feature column) breaks diff/merge.

Reproduce

CREATE TABLE a(id INT PRIMARY KEY, f0 DOUBLE);
DATA BRANCH CREATE TABLE b FROM a;
ALTER TABLE b ADD COLUMN f1 DOUBLE DEFAULT 0.0;
DATA BRANCH DIFF b AGAINST a;

Actual

ERROR 20101 (HY000): internal error: the target table schema is not equivalent to the base table.

Request
Support diff/merge across compatible schema changes (added / nullable columns), which is essential for evolving feature/label tables across versions.


Found while evaluating MatrixOne git4data / SQL as a data-versioning & agent-trace backend. Version: 8.0.30-MatrixOne-v3.0.11 (MatrixOne v3.0.11).

Testing background

Found in a feature-store experiment: a feature definition changed on a branch (we added a feature column via ALTER TABLE ... ADD COLUMN), then we tried to DATA BRANCH DIFF/MERGE the new feature values against the base.

Why it matters (expected purpose)

Feature/label/training tables evolve over time (new features get added). Requiring identical schemas means any column addition breaks diff/merge, blocking continuous feature engineering on branches. Supporting compatible schema evolution (added / nullable columns) is needed for iterative dataset work.

Activity

  1. added
    severity/s2
    on Jun 30, 2026
  2. added this to the MO-202607 milestone on Jun 30, 2026
  3. added 4 commits that reference this issue on Jul 23, 2026
    561b5c6
    2681441
    f645977
    6e1ccf4
  4. VioletQwQ-0 commented on Jul 30, 2026

    @VioletQwQ-0
    Collaborator

    QA handoff

    Merged implementation: #25882, merge commit 2ddf1d4c37c64e9b074aee9cab27a3234a667bc5 (final PR head c86eb01c76582c26971b535caad91c8191f26227).
    Current main at handoff: 41332062a6740978f269088a92ee362a888c7bd7.

    QA Decision

    • required: yes
    • reason: this is user-visible DATA BRANCH DIFF/MERGE schema-evolution functionality involving persisted lineage, historical ownership, snapshot/PITR, concurrency, and GC
    • production_entrypoint: DIFF/MERGE across supported schema evolution, plus COPY ALTER while branch/snapshot/PITR historical owners are created or removed
    • automated_terminal_coverage: the merged unit, race, embedded, and BVT coverage exercises stable-identity mapping, reorder/lineage-proven rename, supported target-only columns, fail-closed incompatible/redefined schemas, historical-owner publication barriers, and generation cleanup
    • remaining_validation: validate the supported/rejected schema matrix in a deployed environment, verify DIFF output and MERGE data preservation, exercise snapshot/PITR ownership and concurrent COPY ALTER, then confirm safe reclamation only after the final owner is removed

    PASS requires deterministic DIFF/MERGE results for supported evolution, explicit rejection without partial writes for ambiguous/incompatible evolution, preservation of target-only data, correct historical ownership across snapshot/PITR, and eventual cleanup after the last owner disappears. FAIL includes guessed column matching, silent casts, lost target data, false snapshot/PITR success, partial merge, stale ownership, or premature/leaked generation cleanup.

    Please record the tested build/commit, environment, schema scenarios, concurrency setup, and terminal catalog/data results. This feature should remain open after QA if product/reporter acceptance or additional regression coverage is still required; QA PASS alone is not permission for mechanical closure.

  5. removed
    severity/s2
    on Aug 6, 2026
  6. Ariznawlll commented on Aug 26, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:1891117aedce0419a81630b3011906b560b93d0a
    • 部署方式:隔离的单 CN 本地服务;使用 mo-tester 通过 MySQL 协议执行。该组使用 -n 忽略仅显示长度的 JDBC metadata 差异,仍逐行比较 SQL 结果与错误断言。
    • 测试日期:2026-08-26

    原问题验证

    复现 issue 中 CREATE TABLE a(id INT PRIMARY KEY, f0 DOUBLE) → DATA BRANCH CREATE TABLE b FROM a → ALTER TABLE b ADD COLUMN f1 DOUBLE DEFAULT 0.0 → DATA BRANCH DIFF/MERGE 的兼容 schema-evolution 路径。当前 main 的 DIFF 与 MERGE 均可完成,并保留共同列的数据语义。

    本轮回放四个已有 Data Branch BVT 文件,合计 TOTAL 736, SUCCESS 736, FAILED 0:branch_edge_cases 211 条、branch_matrix_coverage 108 条、diff_schema_evolve 278 条、merge_schema_evolve 139 条。

    Happy Path 覆盖

    1. 原问题:branch 添加带 DEFAULT 的 target-only 列后,DIFF 和 MERGE 成功;MERGE 仅写回共同列。
    2. 单 PK、复合 PK(含保留字/带空格列名)、target-only 列位于中间、多个 ALTER generation,以及 ALTER 前后的 INSERT/UPDATE/DELETE。
    3. DIFF、MERGE、重复 MERGE 幂等性、snapshot 视图下的 schema evolution 与历史 generation 映射。
    4. 宽类型和表结构矩阵:整数/无符号/decimal/时间/JSON/binary/enum/vector/geometry,PK/UNIQUE/FK/CHECK/NOT NULL/DEFAULT/AUTO_INCREMENT、二级索引、cluster-by、分区表和 view。

    Unhappy Path 覆盖

    1. 共同列类型不兼容、base-only 列被删除、PK 被移除、drop/add 同名但列 identity 改变,均被 fail-closed 拒绝。
    2. fake PK / cluster-by + target-only 列被拒绝;不允许以隐藏派生 key 进行错误匹配。
    3. UNIQUE、FK、NOT NULL 约束违反及 external table 分支操作被拒绝;后续表数据与元数据断言仍保持一致。
    4. 显式事务中对 data-branch lineage 执行 ALTER 被拒绝;rollback 后 DIFF 结果为空,确认拒绝不产生部分 DDL/DML。

    白盒验证

    不适用。本轮为部署后的公开 SQL 验收;未使用 injection。实现 PR 的 UT/race/embedded 覆盖由研发交接评论记录,本次没有把它们替代为黑盒验收。

    回归测试

    • BVT:diff_schema_evolve.sql、merge_schema_evolve.sql、branch_matrix_coverage.sql。
    • 1 亿 data-branch 基线现有 create/update/diff/merge 覆盖,但尚未在 1 亿数据上执行 ALTER ADD COLUMN 后的 DIFF/MERGE schema-evolve 流程;因此未把 big-data 验收记为已完成,也未生成非真实环境的 golden。
    • 未执行 node/network Chaos。该 issue 当前黑盒 SQL 结果不依赖故障注入;schema-evolve 的大数据恢复/重启场景仍需专用 stability 环境验证。

    测试证据

    已完成验证

    • 当前 main 的原问题路径、Happy/Unhappy BVT 均已完成(736/736);未发现 DIFF/MERGE schema-evolve 的 SQL 错误、错误数据、panic 或原子性问题。

    待补充验收项

    1. 1 亿数据 schema-evolve: 在既有 1 亿 Data Branch 基线上,执行 ALTER TABLE ... ADD COLUMN,再验证 DIFF/MERGE、共同列回写、target-only 默认列和清理。该流程尚未在真实 big-data 环境跑过,因此尚无真实环境生成的 golden。
    2. 大数据恢复稳定性: 完成上项后,在专用 stability 环境验证重启/恢复后 Data Branch schema、DIFF/MERGE 数据一致性。
    3. Chaos: 当前不作为阻塞项;功能 SQL 不依赖 node/network 故障注入。如后续纳入恢复场景,再走专用 stability 验证。
  7. Ariznawlll commented on Sep 18, 2026

    @Ariznawlll
    Collaborator

    测试补充(100M schema evolution 阶段进度)

    测试版本

    • MatrixOne 分支:main
    • MatrixOne commit:4ff27bb9b35c43c1b0961bb9a01bf8fc0b6a2171
    • 环境:本地隔离单 CN 黑盒环境 + TKE big-data 独立集群
    • 测试日期:2026-09-17~2026-09-18

    已完成验证

    1. 本地黑盒 10,000 行 schema-evolution

      • branch 创建后分别在 ALTER TABLE ... ADD COLUMN 前后执行 INSERT / UPDATE / DELETE。
      • 校验 target-only 中间列的默认值与显式更新值。
      • 重启前后表结构、数据聚合和 DIFF 结果一致。
      • MERGE 后共同列数据正确,base 未增加 target-only 列,MERGE 后 DIFF 为 0。
    2. 不兼容 schema 与原子性

      • 共同列 INT → BIGINT 类型漂移、删除 base 列、无 PK/fake-PK 配合 target-only 列均被拒绝。
      • 每种拒绝场景均回读 source/target,数据和结构保持不变,无部分写入。
    3. 当前 main 回归

      • 四组 schema-evolution BVT 合计 736/736:diff_schema_evolve 278、branch_edge_cases 211、branch_matrix_coverage 108、merge_schema_evolve 139。
      • 相关 frontend focused tests 重复 3 轮,覆盖列 identity 映射、rename、default hydration、LCA、snapshot/PITR ownership、COPY ALTER 以及不兼容 schema 拒绝。
    4. 100M 核心数据链路

      Actions #35198000419 已实际执行 100M schema-evolution SQL:

      校验项 实际结果
      branch target-only 非默认值行数 1,000,000
      MERGE 前 DIFF 数量 4,000,000
      MERGE 后 base 行数 100,000,000
      payload 数据不一致数 0
      base 中 target-only 列数量 0
      MERGE 后 DIFF 数量 0

      该轮业务 SQL 和数据正确性校验均已执行;末尾清理断言仍按 ALTER 后的 current rel_id 查询,未覆盖完整 generation lineage。

    清理校验补充

    清理断言已改为同时记录 branch root rel_id 和 ALTER 后 current rel_id,并校验:

    • 活跃 branch metadata:0
    • logical branch tombstone:1
    • current ALTER lineage metadata:0
    • branch protection snapshot:0

    测试资产 commit:9d24ecdaa439f64173a94e50216e4d0d83486815

    本轮待验证

    修正后的最终复跑 Actions #35208061617 在环境创建阶段因 TKE CPU/内存不足,Pod 持续 Pending,未进入 SQL 执行;这次未产生新的功能结果。

    现有测试资源可用后,将重新执行同一 100M case,补齐修正后 cleanup golden 的真实 TKE 结果,再发布完整测试结论。

  8. Ariznawlll commented on Sep 18, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:4ff27bb9b35c43c1b0961bb9a01bf8fc0b6a2171
    • 部署方式:TKE 独立 Data Branch 集群(3 CN / 1 TN)
    • 测试日期:2026-09-18

    原问题验证

    在 1 亿行基表上创建 Data Branch;branch 侧执行 common-column 更新、ALTER ADD COLUMN feature_tag、target-only 列更新、删除和插入,再执行 DATA BRANCH DIFF 与 MERGE。

    Happy Path 覆盖

    1. 合并前 DIFF 为 4,000,000,覆盖 pre-ALTER 与 post-ALTER 的 common-column 修改、target-only 列修改、删除和插入。
    2. MERGE 成功;基表行数为 100,000,000,payload 不一致行数为 0。
    3. MERGE 后 DIFF 为 0,确认 branch 与基表数据收敛。

    Unhappy Path 覆盖

    1. branch-only 的 feature_tag 不向基表传播:基表同名列计数为 0。
    2. 删除 branch 后检查清理边界:active metadata=0、logical tombstone=1、current ALTER lineage=0、branch protection snapshot=0。

    白盒验证

    不适用。本次验证通过公开 SQL 接口覆盖 schema evolution、DIFF / MERGE 与清理结果,未使用故障注入或内部 mock。

    回归测试

    • 已合入 mo-nightly-regression#1706,合入 commit:563db1b22366cca5883a68a7149f51c55243d568。
    • 用例追加到 nonsys_data_branch_100m.sql,由 main 的 Snapshot Backup Restore nightly 中 DATA BRANCH 100M job 执行;未新增 4.2-dev 入口。

    测试证据

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions