Skip to content

[Bug]: CLONE and DATA BRANCH cannot handle table identifiers containing embedded backticks #26127

Closed

Description

@Ariznawlll

Summary

CREATE TABLE ... CLONE, database CLONE, and DATA BRANCH cannot handle a valid table identifier that contains an embedded backtick. The source table can be created, written, and queried normally when the embedded delimiter is doubled, but clone/branch resolution either looks for a different table name or emits malformed internal SQL.

Tested revision

2eb7f523e5a10f352d3e258183ed8440510388de

Reproduction

drop database if exists g4d_backtick_probe;
create database g4d_backtick_probe;
use g4d_backtick_probe;

create table `src``one` (id int primary key, v varchar(20));
insert into `src``one` values (1, 'row-one');

-- The source table is valid and readable.
select count(*), min(v) from `src``one`;

-- Both table-level paths fail.
create table ordinary_clone clone `src``one`;
data branch create table branch_clone from `src``one`;

The same result was reproduced independently with src``two and src``three.

Database-level paths fail as well:

create database g4d_backtick_scope;
use g4d_backtick_scope;
create table `src``table` (id int primary key, v varchar(20));
insert into `src``table` values (1, 'source-row');

data branch create database g4d_backtick_scope_branch from g4d_backtick_scope;
create database g4d_backtick_scope_clone clone g4d_backtick_scope;

Actual result

The table-level paths resolve a non-existent name:

ERROR 1146 (HY000): no such table g4d_backtick_probe.src``one

The database-level paths generate malformed SQL while reading the source table definition:

ERROR 1105 (HY000): ... syntax error ... near "table`"

Afterward, DROP DATABASE g4d_backtick_scope also fails while processing the same table. Dropping the table explicitly with DROP TABLE `srctable` `` and then dropping the database succeeds.

Expected result

All clone and Data Branch paths should resolve the catalog name as src + backtick + one, quote it as `srcone` ``, and preserve the source rows. Database cleanup should not require dropping such tables one by one.

Code observations

  • cloneTableRestoreSQL serializes the parsed clone AST with identifier quoting, but the table-level clone path behaves as if the doubled delimiter is retained in the identifier value.

  • getCreateTableSql builds show create table with:

    fmt.Sprintf("show create table `%s`.`%s`", dbName, tblName)

    without doubling embedded backticks in either identifier. This affects database clone/Data Branch source collection.

This is distinct from apostrophes inside SQL string literals: the failure here is identifier delimiter round-tripping.

Activity

  1. added this to the MO-202607 milestone on Jul 24, 2026
  2. added
    kind/bug
    on Jul 24, 2026
  3. added theissue type on Jul 24, 2026
  4. VioletQwQ-0 commented on Jul 29, 2026

    @VioletQwQ-0
    Collaborator

    PR #26317 merged as 1ce594dada6cae7feccd643078e0efc8f027636f (reviewed head b01486c8a3583dabc6901bf9531b2aaaf7d61fd4). Required CI and quoted-identifier regressions passed.

    QA handoff on main f6dab28046d70412cec132f0068840896852101c:

    • Verify table and database CLONE with identifiers containing embedded backticks.
    • Verify table and database DATA BRANCH paths with the same identifiers.
    • Verify DROP DATABASE cleanup and dependent FK/view handling.

    Pass: every quoted-identifier path creates, reads, and cleans up the intended objects only. Fail: syntax error, wrong object resolution, missing dependencies, or cleanup failure.

  5. Ariznawlll commented on Jul 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main 分支完成验证。

    测试版本:52ea9f874f492c368a20efef16b46ab8ced2de37
    测试拓扑:Proxy + 2 CN
    重复次数:3 轮

    测试过程:

    1. 创建名称中包含 embedded backtick 的数据库和表。
    2. 分别执行表级 CLONE、数据库级 CLONE、表级 Data Branch 和数据库级 Data Branch。
    3. 回读目标对象数据并检查对象解析是否指向预期表。
    4. 覆盖依赖对象及 DROP DATABASE 清理,连续重建场景 3 轮。

    测试结果:

    • 四种复制路径全部成功,没有出现反引号转义导致的语法错误。
    • 目标对象名称和数据与源对象一致,没有解析到其他同名对象。
    • 依赖对象处理及清理正常,重复执行未泄漏上轮状态。
    • 连续 3 轮均通过,未发现 panic。

    结论:该问题在上述最新 main commit 上验证通过。

  6. Ariznawlll commented on Jul 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    在最新 main 上补充依赖对象的扩展验证后,确认该问题尚未完全修复,补充更正上一条验证结论。

    测试版本:0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c
    测试拓扑:单 TN + 单 CN

    基础路径验证通过:

    • 名称包含 embedded backtick 的源表可以正常创建、写入和查询;
    • 该表的表级 CREATE TABLE ... CLONE 和表级 DATA BRANCH CREATE TABLE 均成功;
    • 源库只包含该 embedded-backtick 表时,数据库级 CLONE、数据库级 DATA BRANCH 及清理均成功;
    • 普通名称的 FK、View 依赖对象可随数据库级 CLONE / DATA BRANCH 正确复制,FK 拒绝非法子表写入,目标库之间及源库数据相互隔离。

    继续扩展到“依赖 View 自身的名称也包含 embedded backtick”时,仍可稳定复现失败:

    drop database if exists repro_embedded_view_branch;
    drop database if exists repro_embedded_view_clone;
    drop database if exists repro_embedded_view_src;
    
    create database repro_embedded_view_src;
    create table repro_embedded_view_src.base(
      id int primary key,
      note varchar(20)
    );
    insert into repro_embedded_view_src.base values(1,'source');
    create view repro_embedded_view_src.`view``v` as
      select id,note from repro_embedded_view_src.base;
    
    data branch create database repro_embedded_view_branch
      from repro_embedded_view_src;
    create database repro_embedded_view_clone
      clone repro_embedded_view_src;

    实际结果:

    DATA BRANCH:
    ERROR 20101 (HY000): internal error: invalid input
    
    CLONE:
    ERROR 1105 (HY000): ... syntax error ... near "`v"
    

    失败后检查:

    • 两个目标数据库均未残留;
    • 源表 repro_embedded_view_src.base 仍可读,数据为 (1, 'source');
    • 直接查询源 View repro_embedded_view_src.\viewv\ 也会返回 ERROR 20101: internal error: invalid input。

    结论:

    • 原 issue 的 embedded-backtick 表名四条复制路径已修复;
    • embedded-backtick View 名称 / 依赖 View 路径仍未修复,因此当前不建议关闭该 issue。

    稳定通过的表名、普通 FK/View、隔离性和清理路径已扩展到 motr#69。失败路径没有作为 expected error 写入回归,待产品修复后再补充成功基线。

  7. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充本轮黑盒和白盒验证结果,测试版本为 main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c。

    黑盒已通过的范围:

    • MOTR 用例:issue_26127_data_branch_embedded_backticks.test
    • embedded-backtick 源表的表级 CLONE、表级 Data Branch、数据库级 CLONE 和数据库级 Data Branch。
    • 普通名称 FK/View 依赖对象的 join、非法 FK 写入拒绝、源/branch/clone 数据隔离和清理。

    上述 MOTR case 25/25 条 SQL/断言通过;本轮 Data Branch 全集 13/13 case、280/280 条 SQL/断言通过。

    白盒验证:

    go test ./pkg/tests/issues \
      -run '^TestIssue26127CloneAndBranchEmbeddedBacktickTable$' \
      -count=1
    ok github.com/matrixorigin/matrixone/pkg/tests/issues
    

    但扩展边界仍未通过:

    • 当 dependent View 自身的名称也包含 embedded backtick 时,数据库 Data Branch 返回 ERROR 20101: internal error: invalid input;
    • 数据库 CLONE 返回生成 SQL 的 syntax error;
    • 该结果和最小复现已记录在上一条补充评论。

    Unhappy path / 依赖与失败边界:

    • branch/clone 目标中的非法 FK child 写入均被拒绝,检查目标 FK 不是只复制了 catalog 外观。
    • 对一个目标写入后检查源库和另一目标不变。
    • dependent View 自身含 embedded backtick 时,数据库 Data Branch 和 CLONE 均失败。
    • 两个失败目标数据库均未残留,源 base table 仍可读;但源 View 本身查询也返回 ERROR 20101,因此该边界明确判定为未修复。
    • 失败路径没有写进 MOTR expected result,避免把产品错误固化成“通过”。

    结论:原始 embedded-backtick 表名路径已经通过黑盒与白盒验证,但 embedded-backtick View 名称/依赖路径仍未修复,因此 issue 暂不建议关闭。稳定通过部分已加入 motr#69,失败部分没有录成 expected error。

  8. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    Unhappy Path / 未修复边界专项验证

    测试版本:main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c

    已通过的异常路径:

    1. 在 branch/clone 目标库分别写入不存在 parent 的 child。
    2. 两个目标的 FK 均正确拒绝非法写入。
    3. 向一个目标合法写入后,源库和另一目标保持不变。

    仍失败的扩展路径:

    1. dependent View 自身的名称包含 embedded backtick。
    2. 数据库 Data Branch 返回 ERROR 20101: internal error: invalid input。
    3. 数据库 CLONE 返回生成 SQL 的 syntax error。
    4. 两个失败目标数据库均未残留,源 base table 仍可读。
    5. 源 View 本身查询也返回 ERROR 20101。

    结论:embedded-backtick 表名路径通过;embedded-backtick View 名称/依赖路径仍未修复。该失败没有录成 expected result,当前 issue 不建议关闭。详细最小复现见 comment。

  9. removed their assignment
    on Jul 30, 2026
  10. 6 remaining items

  11. Ariznawlll commented on Aug 1, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:15a2d07c687a62a0984cf62846b092912a28c0f1
    • 部署方式:本地单 CN 黑盒服务;motr 新用例连续执行 3 轮
    • 测试日期:2026-08-01

    原问题验证

    创建合法的嵌入反引号源表 `srcone`` 后,分别执行表级CREATE TABLE ... CLONE与DATA BRANCH CREATE TABLE;另建含 `` srcscope` 的数据库,执行数据库级 CLONE 与 DATA BRANCH CREATE DATABASE。四条复制路径均保留原行和原始标识符语义,连续 3 轮一致。

    Happy Path 覆盖

    1. 表级 CLONE 返回 (2, backtick-source)。
    2. 表级 Data Branch 返回相同结果。
    3. 数据库级 CLONE 和数据库级 Data Branch 均返回 (3, database-scope)。

    Unhappy Path 覆盖

    1. 对带嵌入反引号的已复制表名不依赖字符串拼接断言,而是额外验证带单引号标识符分支表的重复主键写入会被拒绝,且原行数保持 1;用于确认异常 DML 不影响复制后的表状态。

    白盒验证

    不适用。本轮回归只使用公开 DDL/DML/查询接口验证标识符 round-trip。

    回归测试

    已加入 motr#74:issue_26194_26127_quoted_identifiers.test。

    测试证据

    ./motr --repeat 3 --do-test 'issue_(26194|26144|26113|24924|26095|26280|25625)':21/21 成功;12_git4data suite:69/69 成功。详细变更和可复跑基线见 motr#74。

    测试结论

    测试通过。

  12. VioletQwQ-0 commented on Aug 12, 2026

    @VioletQwQ-0
    Collaborator

    Correction to the previous lifecycle assessment: the dependent-View failure cited there was observed on pre-fix MatrixOne 0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c, before #26443 merged as 38ce3a774af775dd05f988decc1927fd3eaa3b69.

    The tester subsequently reported PASS on main@15a2d07c687a62a0984cf62846b092912a28c0f1, which contains the #26443 merge commit. There is no post-#26443 QA failure in this issue. The fact that the PASS report did not restate every handoff tuple does not turn the older pre-fix failure into a current failure.

    The exact ordinary-base-table plus embedded-backtick View fixture also passes through the authenticated cluster regression on current code. Draft PR #26995 is test-only regression hardening for that historical tuple; it is not a production fix and introduces no new QA gate.

    Therefore the test-verification-failed and phase/testing states introduced on August 12 were incorrect. The issue is restored to completed based on the existing post-fix QA PASS. This comment supersedes the earlier statement that QA remained failed.

  13. removed their assignment
    on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions