Repository navigation
Description
Describe the bug
DATA BRANCH DIFF fails for sibling branches when a primary-key column name requires identifier quoting.
The failure occurs while reconstructing rows deleted on one branch from the common ancestor. The generated join query quotes projected columns and table names, but inserts primary-key names into the VALUES alias list and join predicates without quoting.
Tested at commit 2eb7f523e5a10f352d3e258183ed8440510388de.
Steps to reproduce
Single-column primary key using a reserved word:
drop database if exists g4d_lca_names;
create database g4d_lca_names;
use g4d_lca_names;
create table base_single(`select` int primary key, payload varchar(20));
insert into base_single values (1,'one'),(2,'two');
data branch create table left_single from base_single;
data branch create table right_single from base_single;
delete from left_single where `select`=1;
update right_single set payload='two-right' where `select`=2;
data branch diff left_single against right_single;Composite primary key using a reserved word and punctuation:
create table base_composite(
`left` int,
`a-b` varchar(10),
payload varchar(20),
primary key(`left`,`a-b`)
);
insert into base_composite values (1,'x','one'),(2,'y','two');
data branch create table left_composite from base_composite;
data branch create table right_composite from base_composite;
delete from left_composite where `left`=1 and `a-b`='x';
update right_composite set payload='two-right' where `left`=2 and `a-b`='y';
data branch diff left_composite against right_composite;The same generated query is shared by MERGE and PICK when applying a deletion from a sibling branch:
create table apply_base(`select` int primary key, payload varchar(20));
insert into apply_base values (1,'one'),(2,'two');
data branch create table apply_src from apply_base;
data branch create table apply_dst from apply_base;
delete from apply_src where `select`=1;
data branch merge apply_src into apply_dst;
-- or, on a freshly recreated pair:
data branch pick apply_src into apply_dst keys(1);Actual behavior
The single-key case fails near this generated fragment:
... as pks(__idx_,select) on lca.select = cast(pks.select as INT) ...
The composite-key case fails near:
... as pks(__idx_,left,a-b) on lca.left = ... AND lca.a-b = ...
DIFF, MERGE, and PICK return a SQL syntax error instead of completing. MERGE and PICK leave the destination table unchanged after the failure.
Expected behavior
Every generated reference to a user-defined primary-key column should use identifier quoting. Both DIFF commands should return their rows normally, regardless of valid primary-key names.
Reproducibility
Reproduced in 3/3 runs for both the single-column and composite-primary-key DIFF cases, and in 3/3 runs for the MERGE and PICK variants.
Code context
handleDelsOnLCA in pkg/frontend/data_branch_hashdiff.go builds the LCA lookup query. It uses raw pkNames in:
- the
VALUESalias list; lca.<pk>expressions;pks.<pk>expressions.
The projected LCA columns in the same query already use quoteIdentifierForSQL, but these primary-key references do not.
Activity
fix(frontend): quote LCA primary key references (#26200)
Ariznawlll commentedon Jul 29, 2026
已在最新
main分支完成黑盒验证。测试版本:
52ea9f874f492c368a20efef16b46ab8ced2de37测试拓扑:Proxy + 2 CN
重复次数:3 轮
测试过程:
测试结果:
结论:该问题在上述最新 main commit 上验证通过。
Ariznawlll commentedon Jul 30, 2026
已在
main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c补充完成黑盒和白盒验证。黑盒验证:
结果:该 case
36/36条 SQL/断言通过;本轮 Data Branch 全集13/13case、280/280条 SQL/断言通过。白盒验证:
该 UT 检查 LCA 删除行查询生成路径,包含需要引用的主键列,确认生成的
VALUESalias 和 join predicate 均使用合法标识符引用。Unhappy path / 边界验证:
结论:原 issue 涉及的 quoted PK DIFF/PICK/MERGE 路径在上述提交验证通过,黑盒回归已加入 motr#69。
Ariznawlll commentedon Jul 30, 2026
Unhappy Path 专项验证
测试版本:
main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c本轮专门覆盖正常新增/更新之外的 LCA 删除与选择性应用路径:
结果:
专项用例
36/36条 SQL/断言通过。回归见 motr#69。fix(frontend): quote LCA primary key references (matrixorigin#26200)
fix(frontend): quote LCA primary key references (matrixorigin#26200)
fix(frontend): quote LCA primary key references (matrixorigin#26200)