Skip to content

[Bug]: SQL dump emits invalid literal for BIT value containing quote byte #50

Closed as not planned

Description

@Ariznawlll

Description

默认 SQL 模式下,mo-dump 导出 BIT(8) 列时只转义零字节,不转义单引号或反斜杠字节。合法 BIT(8) 值 0x27(单引号)被输出为 _binary ''',这是无效 SQL;导出返回成功,但恢复中断并留下空表。

Environment

  • MatrixOne main: 75ff736835c3d00d40dc00a0a1d3b11129388e5b,本地隔离 LOG/TN/CN,frontend 127.0.0.1:26011。
  • mo_dump main: 324c33dbdc7075cd5d7beaafd1e15c76709dd442,macOS arm64,Go 1.26.5 make build。
  • 日期:2026-10-19。

Steps to reproduce

CREATE DATABASE d;
CREATE TABLE d.t(id INT PRIMARY KEY,b BIT(8));
INSERT INTO d.t VALUES(1,b'00100111'); -- HEX(b)=27
./mo-dump -u root -h 127.0.0.1 -P 26011 -db d > d.sql
mysql --login-path=mo-local -h127.0.0.1 -P26011 --binary-mode=1 < d.sql

受保护的本地登录路径只用于复现;命令行中不包含密码。

Actual behavior

  • mo-dump 退出 0,末尾写出 MODUMP SUCCESS。
  • 导出文件关键行形如 INSERT INTO t VALUES (1,_binary ''');(实际表名带反引号)。
  • 导入返回 ERROR 1064 (42000) ... near " '''。目标数据库/表已被重建,但 SELECT COUNT(*) FROM d.t 为 0。
  • 三个独立新数据库分别复现,3/3 相同。显式开启 mysql --binary-mode=1 仍失败,因此不是 [Bug]: SQL dump embeds raw NUL in VARBINARY and default import stops after replacing database #47 中默认客户端拒绝 NUL 的问题。

Expected behavior

BIT(8) 的任意合法 8-bit 值都应被编码为可执行且无损的 SQL,例如 0x27 或正确转义的二进制字面量。恢复后 HEX(b) 应仍为 27。

Stability and controls

  • 3/3 独立复现:每份导出均返回 0,导入均返回 1064,失败后目标表 0 行,连接可继续查询。
  • 正常控制:同一工具对 BIT(8)=0x41 所在的混合类型表导出/导入成功;VECF32/UUID/ENUM/SET/YEAR/TIMESTAMP/BIT 值与 NULL 均往返一致。
  • 扩展探针:BIT(8)=0x5C 被写成 _binary '\',也会干扰 SQL 引号;0x00 被写成 _binary '\0'。本 issue 的 3/3 门禁只针对单引号字节 0x27。

Code analysis

cmd/mo-dump/main.go 的 convertValue 在 case "bit" 中遍历原始字节,只对 b==0 写入 \\0,其余字节直接 WriteByte(b),最终包在 _binary '...' 中。该分支没有处理 0x27、0x5C 或其他 SQL 特殊字节。

Evidence and related

Regression coverage

修复后建议对 BIT(1)、BIT(8)、BIT(16) 的 0x00/0x27/0x5C/0xFF 和 NULL 做 SQL 导出→普通及 binary-mode 客户端导入→HEX() 全量比对,并确保导入失败不会被误判为备份成功。

Activity

  1. Ariznawlll commented on Oct 19, 2026

    @Ariznawlll
    Author

    cc @matrix-meow:BIT(8)=0x27 在默认 SQL dump 中导出为无效字面量,3/3 独立库可复现;当前账号无本仓库 assignee 管理权限(403),烦请协助认领/分配。

  2. Ariznawlll commented on Oct 19, 2026

    @Ariznawlll
    Author

    已在主库建立统一追踪入口:matrixorigin/matrixone#30557(完整复现、3/3 结果、白盒分析和本 issue 链接均已保留)。后续请在主库 issue 讨论和验收;这里关闭的是重复追踪,不代表问题已经修复。

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions