Skip to content

[Bug]: Data Branch snapshot registration fails for quoted source identifiers #26194

Closed

Description

@Ariznawlll

Describe the bug

DATA BRANCH CREATE cannot finish branch-protection snapshot bookkeeping when
the source database or table identifier contains an apostrophe.

The source identifier is legal when quoted by the SQL parser. After cloning,
createBranchProtectSnapshot writes the parent database and table names to
mo_catalog.mo_snapshots, but interpolates those names into SQL string
literals without escaping apostrophes.

Tested revision

origin/main: 3f3cdcdda64fddb93b6668a301ff38d41e73fb76

Reproduction

A legal source identifier can contain an apostrophe when backtick quoted:

create table `quote'src` (id int primary key);
data branch create table `quote'dst` from `quote'src`;

During branch-protection snapshot registration, the current implementation
constructs a fragment equivalent to:

..., 'sys', 'db'name', 'quote'src', 1, 'branch')

The literal is malformed because the apostrophes terminate it. Valid SQL must
preserve the names as escaped string literals, for example:

..., 'sys', 'db''name', 'quote''src', 1, 'branch')

Expected behavior

Data Branch CREATE should complete for legal quoted identifiers. The
branch-protection snapshot row should preserve the source database and table
names exactly.

Code context

pkg/frontend/data_branch_snapshot.go,
createBranchProtectSnapshot, uses fmt.Sprintf to place
parentAccountName, receipt.srcDb, and receipt.srcTbl between literal
quote characters. This path should use the shared SQL-string-literal quoting
helper before building the insert.

Duplicate check

The same behavior was previously reported in closed issue #24925. The current
main implementation retains the direct interpolation, so this is filed as a
new issue rather than reopening the historical report.

Activity

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

    @VioletQwQ-0
    Collaborator

    PR #26218 merged as f2807845d90be1e683cb7e5fd5e735c86665bc8b (reviewed head 47577212df67146a86a8b6ba2bdcecddd37cc725). Required product CI passed; the remaining merge-update-moc result was a post-merge synchronization workflow, not a product-test failure.

    QA handoff on main f6dab28046d70412cec132f0068840896852101c:

    • Create source database/table identifiers containing legal quote and backslash characters.
    • Exercise Data Branch snapshot registration and the affected FK/master lookup paths.
    • Verify the intended snapshot/metadata rows are created exactly once and cleanup succeeds.

    Pass: the operation succeeds without malformed internal SQL and produces only the intended metadata. Fail: syntax/internal error, missing or duplicated metadata, or unintended additional SQL effects.

  5. Ariznawlll commented on Jul 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main 分支进行黑盒复测。

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

    测试过程:

    1. 创建名称中包含单引号的源表,并向表中写入数据。
    2. 从该源表创建 Data Branch,目标对象使用普通合法名称。
    3. 查询 branch protect snapshot 及相关元数据,校验对象 ID、对象名称、原始字节和记录唯一性。
    4. 按 QA handoff 要求执行源对象及数据库清理。
    5. 另外使用包含单引号的目标标识符执行原始边界场景。

    测试结果:

    • 从带单引号源表向普通目标表创建 Data Branch:3/3 成功。

    • snapshot 元数据:3/3 只生成一条目标记录,对象 ID 正确,标识符字节未被改变。

    • 但清理阶段仍稳定失败:

      DROP TABLE quote'srcN
      DROP DATABASE ...
      

      均返回单引号附近的 SQL 语法错误。

    • 使用同类带单引号目标标识符的完整场景也仍无法正常完成。

    结论:snapshot registration 子问题已经修复,但 issue 的 QA 验收条件还包含“cleanup succeeds”,当前最新 main 仍不满足。本轮验证未通过,暂不建议关闭该 issue。

  6. VioletQwQ-0 commented on Jul 30, 2026

    @VioletQwQ-0
    Collaborator

    QA retest correction and renewed handoff on current main.

    The previous QA run used 52ea9f874f492c368a20efef16b46ab8ced2de37. After that run, PR #25471 merged as f74a8d89109bc389cf5752cebb8a3ae3b552c7cc; it added the missing quoted-identifier formatting path and BVT coverage for a Data Branch target table whose legal quoted name contains an apostrophe.

    The reported cleanup statements were shown without identifier quoting (DROP TABLE quote'srcN). An apostrophe-containing identifier must remain backtick-quoted in every SQL statement; the syntax error from an unquoted statement is not evidence that Data Branch cleanup failed.

    Fresh local falsification on exact current main 41332062a6740978f269088a92ee362a888c7bd7 passed. An embedded cluster test exercised:

    • quoted apostrophe source and target table names;
    • Data Branch creation and exactly one matching branch-protect snapshot;
    • correctly quoted ordinary DROP TABLE of the target;
    • terminal mo_branch_metadata.table_deleted = true;
    • removal of the corresponding kind='branch' __mo_branch_* snapshot;
    • correctly quoted source-table and database cleanup.

    The same production path was also checked for DATA BRANCH DELETE TABLE and DATA BRANCH DELETE DATABASE on 0e6dfa93e1c7a2907ae6d8bad3a7ed1b943e9c81; both completed and reached the same metadata/snapshot terminal state. No production change is required from this QA return.

    Please retest on main >= f74a8d89109bc389cf5752cebb8a3ae3b552c7cc (prefer current main), keeping apostrophe-containing table identifiers backtick-quoted for CREATE, DATA BRANCH, query, and DROP. Pass requires successful create/query/cleanup, one exact protect-snapshot row before deletion, table_deleted=true after deletion, and no matching branch snapshot afterward.

    Scope note: an apostrophe-containing database name is rejected by the existing database-name/runtime contract at CREATE DATABASE, before Data Branch runs; it is not a valid cleanup oracle for this table-identifier issue. The issue's executable reproduction and the merged fix concern quoted table identifiers and SQL literal preservation.

  7. Ariznawlll commented on Aug 1, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:15a2d07c687a62a0984cf62846b092912a28c0f1
    • 部署方式:本地双 CN + Proxy;所有 SQL 经 Proxy 执行。
    • 测试日期:2026-08-01

    原问题验证

    源库中创建带单引号的表名和带反斜杠的表名,写入不同数据后执行 DATA BRANCH CREATE DATABASE。连续 3 轮均成功注册并复制两个对象,目标库分别读回 (11,'quoted-source') 与 (22,'quoted-source')。

    Happy Path 覆盖

    1. 覆盖单引号、反斜杠两种源表标识符,并验证数据和表名均被正确保留。
    2. 使用数据库级 Data Branch,而不是只验证表级路径,覆盖 snapshot 注册及全库对象遍历。

    Unhappy Path 覆盖

    1. 在包含特殊标识符的目标库上执行 DATA BRANCH DELETE DATABASE。
    2. 删除后 mo_catalog.mo_database 不再可见该目标库,未出现清理失败或残留元数据。

    白盒验证

    • 不适用:引用、快照注册和删除清理由公开 SQL 及 catalog 结果可观察。

    回归测试

    • 本轮未新增 motr/BVT 文件;此场景属于稳定的 Data Branch SQL 黑盒候选。

    测试证据

    • 执行:Data Branch/CLONE 黑盒审计连续 3 轮。
    • 每轮均记录:PASS 26194_quoted_source_table_snapshot_lifecycle。

    测试结论

    测试通过。

  8. Ariznawlll commented on Aug 1, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

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

    原问题验证

    使用合法的带单引号表名 `src'name` 创建源表并写入一行,再执行 DATA BRANCH CREATE TABLE。分支表能够创建并返回原始行 (1, apostrophe-source);该路径连续 3 轮结果一致。

    Happy Path 覆盖

    1. 源表、分支表均使用带单引号标识符,验证复制后的行值保持一致。
    2. 同一回归还覆盖了嵌入反引号标识符的表级 CLONE 与 DATA BRANCH CREATE TABLE,用于防止标识符转义路径相互回归。

    Unhappy Path 覆盖

    1. 向分支表再次写入相同主键,预期报重复键错误;随后查询行数仍为 1,确认失败写入没有污染已复制的数据。

    白盒验证

    不适用。本轮回归只通过公开 SQL 接口验证快照登记和表复制结果。

    回归测试

    已加入 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。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugphase/testing

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions