Repository navigation
Description
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
[-][Bug]: DATA BRANCH MERGE writes generated columns explicitly and fails[/-][+][Bug]: DATA BRANCH apply paths write generated columns explicitly and fail[/+]Ariznawlll commentedon Jul 27, 2026
补充一组索引组合证据:
从
base创建src、dst后,在src修改id=1的raw_value并新增id=3:两种操作均稳定复现相同报错:
MERGE 与 PICK 均各执行 3 次,结果一致。MERGE 失败后
dst仍保持原来的两行;随后普通INSERT INTO dst(id, raw_value) VALUES (4, 9)成功,doubled自动得到18,并且WHERE doubled = 18可通过idx_doubled查询到该行。因此该场景也覆盖了带二级索引的计算列,问题仍位于分支写入时对该列的显式赋值。fix(data branch): skip generated columns during apply (#26580)
gouhongshen commentedon Aug 3, 2026
fixed
Ariznawlll commentedon Aug 4, 2026
测试版本
mainc58cd292d3e6e039a8882654d3b20ad345171e87原问题验证
使用包含 stored/virtual generated column 的表重跑 PICK 和 MERGE。apply 过程不再显式写 generated column,目标表生成值正确;连续执行 3 轮通过。
Happy Path 覆盖
DIFF OUTPUT FILE不输出 generated column,文件可独立回放且结果正确。Unhappy Path 覆盖
WHEN CONFLICT FAIL返回冲突后,目标表所有原始行及生成值保持不变,没有部分 apply。白盒验证
定向覆盖 generated column 分类、apply batch 排除、逻辑列身份和 schema compatibility;相关前端测试连续执行 3 轮通过。
回归测试
test/distributed/cases/git4data/branch/merge/merge_generated_column.sql测试证据
测试结论
测试通过。
fix(data branch): skip generated columns during apply (matrixorigin#2…
fix(data branch): skip generated columns during apply (matrixorigin#2…
fix(data branch): skip generated columns during apply (matrixorigin#2…