Skip to content

[Bug]: mo-dump SQL restore fails under NO_BACKSLASH_ESCAPES because script depends on backslash quoting #30587

Closed
matrixorigin/mo_dump
#58

Description

@Ariznawlll

问题

mo-dump 的 SQL 脚本用反斜杠转义字符串中的反斜杠和单引号,却不固定导入时的 sql_mode。当 MatrixOne 导入会话启用 NO_BACKSLASH_ESCAPES 时,合法数据的脚本会在 INSERT 处报语法错误,目标库只留下空表;同一脚本在默认 mode 下恢复成功。

环境

  • MatrixOne main:75ff736835c3d00d40dc00a0a1d3b11129388e5b
  • mo_dump main:324c33dbdc7075cd5d7beaafd1e15c76709dd442
  • 本地隔离 LOG/TN/CN;2026-10-19;目标会话 @@sql_mode=NO_BACKSLASH_ESCAPES

复现

CREATE DATABASE source_db;
CREATE TABLE source_db.t(id INT PRIMARY KEY, v VARCHAR(40));
INSERT INTO source_db.t VALUES
  (1, CONCAT('a', CHAR(92), 'b')),
  (2, CONCAT('O', CHAR(39), 'Reilly')),
  (3, 'plain');
mo-dump -u root -h 127.0.0.1 -P 26011 -db source_db > dump.sql
# 将脚本中的目标数据库名改为新的空库名,以保留源库;不改 INSERT 内容。
mysql -h 127.0.0.1 -P 26011 --init-command="SET sql_mode='NO_BACKSLASH_ESCAPES'" < dump.sql

生成脚本中是 INSERT INTO t VALUES (1,'a\\\\b'),(2,'O\\'Reilly'),...,没有 SET sql_mode。在上述导入会话下,返回 ERROR 1064 (42000) at line 14 ... near "Reilly')"。源表仍为三行;目标 t 已创建但为零行,连接随后可正常查询。期望导出文件在文档支持的恢复会话配置下可重建数据,或导出脚本明确固定所依赖的字符串解析 mode;不能报导出成功而留下无法恢复的脚本。

三套独立新建源库、三份 SQL dump、三套 NO_BACKSLASH_ESCAPES 空目标 3/3 同错。相同三份脚本在默认 mode 下导入均成功,源与目标的 HEX(v) 分别一致为 615C62、4F275265696C6C79、706C61696E,排除 SQL 文件损坏或数据本身非法。

白盒线索:cmd/mo-dump/main.go:729-781 的 convertValue 默认用 \\ 与 \\' 生成 SQL 字面量,而脚本只设置 foreign_key_checks,不设置 sql_mode。已搜索 MatrixOne/mo_dump open/closed issue、相关 PR 及 mysql-compatibility-contract,未发现同一 SQL 模式问题。mo_dump#44 是 CSV 模式下反斜杠被静默翻倍,不是本问题。

修复后建议增加“含反斜杠/单引号的 SQL dump → 默认及 NO_BACKSLASH_ESCAPES 会话导入 → 逐字节值、元数据、失败后状态”端到端回归。

Activity

  1. added this to the MO-202610 milestone on Oct 19, 2026
  2. added
    kind/bug
    on Oct 19, 2026
  3. added theissue type on Oct 19, 2026
  4. assigned and unassigned on Oct 26, 2026
  5. slyunnn commented on Oct 27, 2026

    @slyunnn

    Regression and extended verification for #30587 (2026-10-27)

    Verification Environment

    • MatrixOne latest main: 2465dae7a4ada1b277113cca5afff6fe10149b96 — refactor: consolidate unused code and bookkeeping cleanup (#31348). The binary was built from this commit; git_version() returned 2465dae7a4 on every route.
    • mo-dump latest main: d9d6375512620f12ff371b8602cc1d10d6f6caa0 — fix: make SQL/CSV dump scripts restore-safe (#30596 #30598 #30587 #30590 #30628 #30481) (#58). Associated fix: mo_dump PR #58.
    • Isolated topology: 2 CN / 1 TN / 1 Log service / Proxy. Container endpoints Proxy 6001, CN1 16001, CN2 16002 were mapped to host 6601, 16601, 16602; all three were connected and tested independently.
    • Export used mo-dump over the MySQL driver; restore used native mysql 9.7.1 over the MySQL text protocol. Each route used its own new source/restore database.

    What Was Covered

    • OK — The original NO_BACKSLASH_ESCAPES restore scenario completed with exit 0 on Proxy, CN1, and CN2. Rows containing a backslash, apostrophe, and plain text retained exact HEX(v) values 615C62, 4F275265696C6C79, and 706C61696E.
    • OK — The restore script saved the incoming session sql_mode, temporarily removed NO_BACKSLASH_ESCAPES, and restored the incoming mode afterward on all 3 routes.
    • OK — A second restore of each dump under the default session mode also completed with exit 0 and exact byte-for-byte values.
    • Not covered — A live dependent-view restore with a separately persisted view mode; the owning repository's regression tests cover the script/view variable separation.

    Findings

    The original parser failure no longer reproduces. The same dump is usable in both affected and default restore modes, without changing source bytes. This is a script/session-mode issue, not a row-count or resource-scale boundary. Large-data regression required: No; the 3-row fixture crosses the relevant quoting and mode boundary.

    MOTR / BVT Coverage

    The owning mo_dump repository's full make test passed at the tested commit, and the live native-client restores above passed on all 3 routes. No duplicate SQL-only MOTR case was added: the contract includes CLI output, restore-session mode, and process exit status, which a standalone SQL .test cannot assert.

    Final Conclusion

    Fixed for #30587 on the tested MatrixOne and mo-dump revisions. No issue-specific PR was created.

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