Skip to content

[Bug]: DATA BRANCH apply paths write generated columns explicitly and fail #26040

Closed

Description

@Ariznawlll

Describe the bug

DATA BRANCH MERGE cannot apply changes to a table that contains a generated column. The merge path includes the generated column in its insert/apply column list and attempts to write its computed value explicitly.

Both STORED and VIRTUAL generated columns are affected. DATA BRANCH PICK reaches the same failure, and SQL produced by DATA BRANCH DIFF ... OUTPUT FILE also explicitly includes the generated column, so replaying that SQL against the original schema fails for the same reason.

Tested on main commit e15943929885c2c5c83daed90f0f8caeb9a1f0d0. The result reproduced in 3 out of 3 runs.

To Reproduce

DROP DATABASE IF EXISTS g4d_generated;
CREATE DATABASE g4d_generated;
USE g4d_generated;

CREATE TABLE base_t (
  id INT PRIMARY KEY,
  a INT,
  b INT,
  c INT GENERATED ALWAYS AS (a + b) STORED
);
INSERT INTO base_t(id, a, b) VALUES (1, 10, 20), (2, 30, 40);

DATA BRANCH CREATE TABLE branch_t FROM base_t;
UPDATE branch_t SET a = 11 WHERE id = 1;
INSERT INTO branch_t(id, a, b) VALUES (3, 50, 60);
DELETE FROM branch_t WHERE id = 2;

DATA BRANCH DIFF branch_t AGAINST base_t OUTPUT SUMMARY;
DATA BRANCH MERGE branch_t INTO base_t WHEN CONFLICT ACCEPT;
SELECT id, a, b, c FROM base_t ORDER BY id;

The diff correctly reports one inserted, one deleted, and one updated row. The merge then fails with:

ERROR 20301 (HY000): invalid input: the value specified for generated column 'c' in table 'base_t' is not allowed

The base table remains unchanged. Replacing STORED with VIRTUAL produces the same result.

The corresponding PICK form fails before changing the destination:

DATA BRANCH PICK branch_t INTO base_t KEYS(1, 3) WHEN CONFLICT ACCEPT;

The portable SQL output includes statements equivalent to:

CREATE TABLE apply_stage AS SELECT id, a, b, c FROM base_t WHERE 1=0;
INSERT INTO apply_stage VALUES (1,11,20,31),(3,50,60,110);
INSERT INTO base_t (id,a,b,c) SELECT id,a,b,c FROM apply_stage;

The final INSERT fails because c is generated.

Expected behavior

The generated column should be omitted from every destination apply/export column list and recomputed by the destination table. MERGE, PICK, and the generated SQL replay should succeed and leave these rows:

1, 11, 20, 31
3, 50, 60, 110

Additional context

isDataBranchUserVisibleColumn currently excludes hidden/internal columns but does not exclude columns with GeneratedCol != nil. The resulting visible-column list is then used to build the online apply layout and INSERT values.

Activity

  1. added this to the MO-202607 milestone on Jul 22, 2026
  2. added
    kind/bug
    on Jul 22, 2026
  3. added theissue type on Jul 22, 2026
  4. changed the title [-][Bug]: DATA BRANCH MERGE writes generated columns explicitly and fails[/-] [+][Bug]: DATA BRANCH apply paths write generated columns explicitly and fail[/+] on Jul 22, 2026
  5. Ariznawlll commented on Jul 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充一组索引组合证据:

    CREATE TABLE base (
      id INT PRIMARY KEY,
      raw_value INT NOT NULL,
      doubled INT GENERATED ALWAYS AS (raw_value * 2) STORED,
      KEY idx_doubled(doubled)
    );

    从 base 创建 src、dst 后,在 src 修改 id=1 的 raw_value 并新增 id=3:

    DATA BRANCH MERGE src INTO dst WHEN CONFLICT ACCEPT;
    DATA BRANCH PICK src INTO dst KEYS(1, 3) WHEN CONFLICT ACCEPT;

    两种操作均稳定复现相同报错:

    ERROR 20301 (HY000): invalid input: the value specified for generated column 'doubled' in table 'dst' is not allowed
    

    MERGE 与 PICK 均各执行 3 次,结果一致。MERGE 失败后 dst 仍保持原来的两行;随后普通 INSERT INTO dst(id, raw_value) VALUES (4, 9) 成功,doubled 自动得到 18,并且 WHERE doubled = 18 可通过 idx_doubled 查询到该行。因此该场景也覆盖了带二级索引的计算列,问题仍位于分支写入时对该列的显式赋值。

  6. added
    severity/s0
    ai-easy
    and removed on Aug 2, 2026
  7. added a commit that references this issue on Aug 2, 2026
    4a747e4
  8. gouhongshen commented on Aug 3, 2026

    @gouhongshen
    Contributor

    fixed

  9. added and removed
    severity/s0
    on Aug 3, 2026
  10. Ariznawlll commented on Aug 4, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:c58cd292d3e6e039a8882654d3b20ad345171e87
    • 部署方式:macOS arm64,本地 MatrixOne 单 CN 黑盒环境
    • 测试日期:2026-08-04

    原问题验证

    使用包含 stored/virtual generated column 的表重跑 PICK 和 MERGE。apply 过程不再显式写 generated column,目标表生成值正确;连续执行 3 轮通过。

    Happy Path 覆盖

    1. stored 和 virtual generated column 均覆盖 INSERT、UPDATE、DELETE 的 PICK/MERGE。
    2. generated column 上存在普通索引时,apply 后索引查询与全表结果一致。
    3. DIFF OUTPUT FILE 不输出 generated column,文件可独立回放且结果正确。

    Unhappy Path 覆盖

    1. 覆盖 generated/ordinary column 不匹配及不同生成表达式,schema compatibility 会拒绝不兼容结构。
    2. WHEN CONFLICT FAIL 返回冲突后,目标表所有原始行及生成值保持不变,没有部分 apply。
    3. 失败后普通 INSERT 仍能由引擎正常计算 generated value。

    白盒验证

    定向覆盖 generated column 分类、apply batch 排除、逻辑列身份和 schema compatibility;相关前端测试连续执行 3 轮通过。

    回归测试

    测试证据

    测试结论

    测试通过。

  11. added 3 commits that reference this issue on Sep 17, 2026
    c3c6389
    178afce
    ee5ce42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions