Repository navigation
Description
Bug
Data branch currently has several user-visible behavior bugs around cloned view SQL rewriting, quoted identifiers, and edge table/column paths found by the coverage BVT.
1. DATA BRANCH CREATE DATABASE rewrites string literals in cloned views
rewriteCloneViewInfos rewrites the whole CREATE VIEW SQL text with strings.ReplaceAll(info.createSql, srcDBName, dstDBName). This changes string literals, not only real database/table references.
Reproduce:
drop database if exists br_view_literal_copy;
drop database if exists br_view_literal_src;
create database br_view_literal_src;
use br_view_literal_src;
create table t(a int primary key);
insert into t values (1);
create view v_literal as select 'br_view_literal_src' as marker, a from t;
data branch create database br_view_literal_copy from br_view_literal_src;
select marker from br_view_literal_copy.v_literal;Current result:
br_view_literal_copy
Expected result:
br_view_literal_src
Only real table/database references in the view definition should be rewritten. String literals must not be modified.
2. DATA BRANCH CREATE TABLE should accept quoted identifiers containing spaces
Legal quoted identifiers such as `branch table` should work. The branch-create path parsed raw SQL text with a regexp using \S+, so names containing spaces could be split incorrectly.
Reproduce:
drop database if exists br_matrix_quoted;
create database br_matrix_quoted;
use br_matrix_quoted;
create table `base table`(a int primary key, b varchar(20));
insert into `base table` values (1, 'space-name'), (2, 'space-name');
data branch create table `branch table` from `base table`;
select count(*) from `branch table`;Expected: the branch table is created and contains the cloned rows.
3. Branch-protect snapshot metadata should escape apostrophes in identifiers
When data branch creates the branch-protect snapshot row in mo_snapshots, source account/database/table names are embedded into SQL string literals. Legal identifiers containing an apostrophe can break the internal insert SQL unless the string literals are escaped.
Reproduce:
drop database if exists br_matrix_quoted;
create database br_matrix_quoted;
use br_matrix_quoted;
create table `quote'src`(a int primary key, b varchar(20));
insert into `quote'src` values (1, 'single-quote');
data branch create table `quote'dst` from `quote'src`;
select count(*) from `quote'dst`;Expected: the branch table is created successfully and branch-protect snapshot metadata is inserted with correctly escaped string literals.
4. Data branch merge with geometry columns fails and can panic
Found in PR #24851 CI: https://github.com/matrixorigin/matrixone/actions/runs/27322774160/job/80717356232?pr=24851
Reproduce:
drop database if exists br_matrix_types;
create database br_matrix_types;
use br_matrix_types;
create table wide_base(
id int primary key,
g geometry
);
insert into wide_base values (1, 'POINT(1 1)');
data branch create table wide_branch from wide_base;
update wide_branch set g = 'POINT(2 2)' where id = 1;
insert into wide_branch values (2, 'POINT(3 3)');
data branch merge wide_branch into wide_base;Current behavior:
invalid argument function cast_geometry_to_subtype, bad value [CHAR VARCHAR]
internal error: panic No Support
The panic stack reaches pkg/vm/engine/disttae/logtailreplay/change_handle.go:2427 in appendFromEntry; the supported type switch does not handle geometry values.
Expected: data branch should support MO's geometry column type in diff/merge, or at minimum return a clean unsupported error instead of panicking.
5. Data branch merge on cluster by table fails with column-count mismatch
Reproduce:
create table clustered_base(
tenant int not null comment 'cluster tenant',
seq int default 0,
payload varchar(20)
) cluster by (tenant, seq);
insert into clustered_base values (1, 1, 'base'), (1, 2, 'old'), (2, 1, 'keep');
data branch create table clustered_branch from clustered_base;
update clustered_branch set payload = 'new' where tenant = 1 and seq = 2;
insert into clustered_branch(tenant, payload) values (3, 'default-seq');
delete from clustered_branch where tenant = 2;
data branch merge clustered_branch into clustered_base;Current behavior:
Column count doesn't match value count at row 1
Expected: merge should preserve the cluster-by table definition and apply update/insert/delete correctly.
6. Data branch merge on partitioned table panics in CollectChanges
Reproduce:
create table part_base(
id int primary key,
val int,
note varchar(16)
) partition by range columns(id) (
partition p0 values less than (10),
partition p1 values less than (MAXVALUE)
);
insert into part_base values (1, 10, 'p0'), (11, 110, 'p1'), (12, 120, 'p1');
data branch create table part_branch from part_base;
update part_branch set val = val + 1 where id = 11;
insert into part_branch values (2, 20, 'new-p0'), (21, 210, 'new-p1');
delete from part_branch where id = 12;
data branch merge part_branch into part_base;Current behavior:
internal error: panic not implemented
The panic stack reaches pkg/vm/engine/disttae/txn_table_combined.go:286 in combinedTxnTable.CollectChanges.
Expected: data branch merge/diff should support partitioned base tables or return a clear unsupported error instead of panicking.
7. Some data branch unhappy paths return incorrect or unstable errors
Current behaviors observed in PR #24851 CI:
data branch diff missing_branch against base;
-- returns: no such table br_unhappy.missing_branch
data branch diff br against missing_base;
-- returns: no such table br_unhappy.missing_base
data branch pick single_right into single_left;
-- returns a generic SQL syntax error near ";" instead of the data branch validation error
data branch pick single_right into single_left keys(select a, b from single_right);
-- returns: KEYS subquery returns 0 columns but table has a single-column primary key
data branch pick single_right into single_left between snapshot missing_from and missing_to keys(3);
-- returns: cannot resolve snapshot 'missing_from': internal error: find 0 snapshot records by name(...)Expected: data branch validation errors should be deterministic, user-facing, and should not leak internal snapshot lookup details. The subquery column-count error should report the actual column count.
8. DATA BRANCH DIFF/MERGE are incorrectly rejected in explicit transactions
getBackExecutor is written to reuse the session shared transaction when TxnOptions().ByBegin is true, and existing data branch create/delete paths are covered inside explicit transactions. However statementCanBeExecutedInUncommittedTransaction only lists create/delete data branch statements and DataBranchPick; DataBranchDiff and DataBranchMerge are omitted. As a result they are rejected before reaching the data branch handler.
Reproduce:
drop database if exists br_txn_src;
create database br_txn_src;
use br_txn_src;
create table base(a int primary key, b varchar(20));
insert into base values (1, 'one'), (2, 'two');
data branch create table txn_merge_dst from base;
data branch create table txn_merge_src from base;
update txn_merge_src set b = 'two-txn' where a = 2;
insert into txn_merge_src values (3, 'three');
delete from txn_merge_src where a = 1;
begin;
data branch diff txn_merge_src against txn_merge_dst output count;
rollback;
begin;
data branch merge txn_merge_src into txn_merge_dst when conflict accept;
rollback;
select a, b from txn_merge_dst order by a;
begin;
data branch merge txn_merge_src into txn_merge_dst when conflict accept;
commit;
select a, b from txn_merge_dst order by a;Current behavior:
internal error: unclassified statement appears in uncommitted transaction
Expected behavior: DATA BRANCH DIFF should run as a read operation in the explicit transaction, and DATA BRANCH MERGE should honor explicit transaction boundaries: rollback leaves the destination unchanged, commit applies the merge.
9. Data branch diff on decimal256 columns panics in CollectChanges
Found in PR #24851/#24852 CI after removing the geometry happy-path UT case:
- PR add case for data branch(4.0 dev) #24851 UT: https://github.com/matrixorigin/matrixone/actions/runs/27337458277/job/80765524403
- PR add case for data branch(main) #24852 UT: https://github.com/matrixorigin/matrixone/actions/runs/27337456850/job/80765755710
Reproduce:
drop database if exists br_decimal256;
create database br_decimal256;
use br_decimal256;
create table type_matrix_base (
id int primary key,
d256 decimal(65,30)
);
insert into type_matrix_base values
(1, cast('12345678901234567890123456789012345.123456789012345678901234567890' as decimal(65,30))),
(2, cast('-0.000000000000000000000000000001' as decimal(65,30)));
data branch create table type_matrix_branch from type_matrix_base;
update type_matrix_branch set d256 = cast('42.000000000000000000000000000000' as decimal(65,30)) where id = 1;
insert into type_matrix_branch values (3, cast('7.000000000000000000000000000000' as decimal(65,30)));
delete from type_matrix_branch where id = 2;
data branch diff type_matrix_branch against type_matrix_base output summary;Current behavior:
internal error: panic No Support
The panic stack reaches pkg/vm/engine/disttae/logtailreplay/change_handle.go in appendFromEntry. The supported type switch handles decimal64 and decimal128, but not decimal256.
Expected: data branch diff/merge should support decimal256 columns, or return a clean unsupported error instead of panicking.
Activity
[-]data branch create database rewrites string literals in cloned views[/-][+][Bug] data branch create database rewrites string literals in cloned views[/+][-][Bug] data branch create database rewrites string literals in cloned views[/-][+]data branch has incorrect behavior for cloned views and quoted identifiers[/+][-]data branch has incorrect behavior for cloned views and quoted identifiers[/-][+][Bug] data branch has incorrect behavior for cloned views and quoted identifiers[/+][-][Bug] data branch has incorrect behavior for cloned views and quoted identifiers[/-][+][Bug] data branch has incorrect behavior in edge table and identifier paths[/+]Ariznawlll commentedon Jul 24, 2026
补充定位证据:分支保护快照由
createBranchProtectSnapshot组装内部mo_snapshotsINSERT。该路径直接把receipt.srcDb、receipt.srcTbl放入单引号 SQL 字面量。当对象名包含单引号时,生成的片段形如:
我用同一函数的最小白盒用例捕获实际生成 SQL,再交给 SQL 解析器处理;连续 3 次均在解析阶段报错。因此第 3 项可在 SQL 组装阶段独立复现,与运行时表数据无关。
Ariznawlll commentedon Jul 24, 2026
补充第 3 项的最小白盒现象:
createBranchProtectSnapshot在库名或表名含单引号时,写入快照元数据的 SQL 仍直接生成:期望的字面量应为:
在提交
3f3cdcdda64fddb93b6668a301ff38d41e73fb76上以该生产 helper 连续执行 3 次,三次均得到相同的未转义 SQL。gouhongshen commentedon Jul 31, 2026
the fix merged into the main by #25471
Ariznawlll commentedon Aug 1, 2026
测试版本
main15a2d07c687a62a0984cf62846b092912a28c0f1原问题验证
连续 3 轮覆盖 edge table 路径:Geometry 表 CLONE/branch merge、支持的 cluster-by 表 branch merge、range partition 表 branch merge、
decimal(39,4)(decimal256 运行时类型)branch merge。各目标行数和关键值均正确。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
回归测试
decimal(39,4)、VARBINARY、JSON、ENUM、DATETIME、BOOL、UNIQUE/CHECK/NOT NULL,以及分支写入、merge 和三类拒绝路径;Geometry/partition/cluster-by 的扩展审计结论保留在本 comment 的原问题验证中。测试证据
PASS 24924_geometry_partition_clusterby_decimal_and_merge_unhappy_paths。测试结论
测试通过。