Skip to content

[Bug]: ENUM and SET reject trailing-space and non-strict values that MySQL accepts #30538

Closed

Description

@iamlinjunhong

Is there an existing issue for the same bug?

Environment

  • MatrixOne commit: beffc64c486d369406a41cdb1447b120bc93cb41 (main, 2026-10-18), standalone mo-service (ports shifted; mysql protocol on 31201). macOS 15.7 arm64.
  • Reference: local temp MySQL 8.0.46 instance, same SQL, same client.

Actual Behavior

Table used on both engines:

CREATE TABLE e (id INT PRIMARY KEY, e ENUM('xs','s','m'), s SET('a','b','c'));

With SET SESSION sql_mode='' (non-strict), inserting strings and reading back e+0 / s+0:

value (ENUM column) MySQL 8.0.46 MatrixOne
'xs' 1 1 (ok)
'xs ' (trailing space) 1 — accepted, matches ERROR 20101: internal error: convert to MySQL enum failed: item xs is not in enum [xs s m]
' xs' (leading space) 0 + truncation warning ERROR 20101
'XS' 1 1 (case-insensitive matching works)
'1_0' 0 + truncation warning ERROR 20101: "convert to MySQL enum failed: number 10 overflow enum boundary [1, 3]" — the string was parsed as Go-style numeric literal 10
'zz' 0 + truncation warning ERROR 20101
'0' 0 ERROR 20101: number 0 overflow enum boundary
'5' / '6' (out of range) 0 + truncation warning ERROR 20101
value (SET column) MySQL 8.0.46 MatrixOne
'a,c' 5 5 (ok)
'a,c ' / 'A,C' 5 5 (ok; trailing space after last member is handled)
'b,b' 2 + duplicate warning 2 (ok)
'' 0 0 (ok)
'0' 0 0 (ok)
'a,c,x' 5 — keeps a,c, warns ERROR 20101: item a,c,x is not in set [a,b,c] (whole value rejected)
'a,,c' 5 — keeps a,c, warns ERROR 20101 (whole value rejected)
'a , c' 0 (parts fail to match) ERROR 20101
'255' / '9' (out of bitmap) 0 + truncation warning ERROR 20101: value ... overflow set boundary 7
'1_0' 0 + truncation warning ERROR 20101: value 10 overflow set boundary 7

The ENUM trailing-space rejection also happens in the default strict mode (SET sql_mode='STRICT_TRANS_TABLES'), i.e. values that MySQL accepts without any warning in strict mode fail on MatrixOne. Because the failure comes from plan-time literal folding, a single bad row aborts the whole INSERT statement:

mysql> SET sql_mode=''; INSERT INTO e VALUES (1, 'xs ', 'a,c');
ERROR 20101 (HY000): internal error: convert to MySQL enum failed: item xs  is not in enum [xs s m]

Expected Behavior

MySQL 8.0 semantics (all verified on the local 8.0.46 instance, outputs above):

  1. Trailing spaces are stripped from a value before matching ENUM members: 'xs ' is a perfectly valid value for ENUM('xs','s','m') in every sql_mode (returns index 1, no warning).
  2. Under non-strict sql_mode, a value that does not match any member and is not a valid member index degrades to the type sentinel (e+0 = 0, the empty string member value) with a truncation warning (1292/1265), not an error; under strict mode it errors — MatrixOne never consults sql_mode here.
  3. A quoted value like '1_0' is not a number in MySQL; it is an unmatched string (degrades to 0/warning, or strict error). MatrixOne's strconv.ParseUint(name, 0, 64) interprets Go base-0 syntax (0x, 0b, 0o, and _ separators), producing numeric values MySQL never derives.
  4. For SET values under non-strict mode, MySQL keeps the members that match and warns about the unknown parts ('a,c,x' → a,c); it does not reject the entire value.

Steps to Reproduce

  1. Start standalone mo-service (any recent main, verified on beffc64c486d) and connect with a mysql client.
  2. Create the table from the repro field.
  3. SET sql_mode=''; then run each INSERT/output pair from the repro field. Compare with MySQL 8.0.46.
  4. The unit-level statement of the same behaviors (executed as a Go test on this build) is included in the repro field.

Additional information

Root cause, single conversion path:

  1. pkg/container/types/enum.go:56 parseEnumName matches with strings.EqualFold(n, name) — no trimming of trailing spaces, so 'xs ' can never match 'xs' (MySQL strips trailing spaces before matching).
  2. pkg/container/types/enum.go:32-48 ParseEnum: when the name does not match it falls to strconv.ParseUint(name, 0, 64) — base 0 is Go syntax (0x41→65, 1_0→10, 0b101→5), not MySQL semantics for quoted ENUM values; every failure becomes moerr.NewInternalErrorNoCtxf(...).
  3. pkg/container/types/set.go:90 ParseSet behaves the same: unknown member or out-of-range bitmap → hard error containing "convert to MySQL set failed"; valid-prefix inputs (a,c,x) are rejected wholesale instead of keeping matched members with a warning.
  4. pkg/sql/plan/mysql_special_types.go:357 (mysqlEnumLiteralIndex → types.ParseEnum(enumValues, value.String())) propagates these errors at bind/fold time, so sql_mode is never consulted — non-strict inserts die exactly like strict ones.

Recommended fix, preserving compatibility with existing data: (a) strip trailing spaces from the value before ENUM matching (matches MySQL; harmless for stored data), (b) make the numeric fallback only accept plain-decimal integer syntax instead of Go base-0, (c) when sql_mode is non-strict (or for statements where MySQL would only warn), degrade unmatched ENUM values to index 0 and unmatched SET parts to skipped members with a truncation warning, matching the behavior already documented in MySQL. Existing stored data is unaffected because these are value-matching rules, not storage-format changes.

Related open issues in the ENUM/SET family but different roots: #27331 (prepared SET parameter markers), #27332 (prepared UPDATE parameter binding). Neither covers literal folding semantics.

Full reproduction, exactly as Loom ran it
-- Run on MatrixOne (commit beffc64c486d) and MySQL 8.0.46.
CREATE TABLE e (id INT PRIMARY KEY, e ENUM('xs','s','m'), s SET('a','b','c'));

SET sql_mode='';
-- ENUM: MySQL returns e+0 = 1 for the first two; MatrixOne errors on the second:
INSERT INTO e VALUES (1, 'xs ', 'a,c'); SELECT e+0 FROM e; DELETE FROM e;   -- MySQL: 1 | MO: ERROR 20101
INSERT INTO e VALUES (1, 'zz', 'a,c');  SELECT e+0 FROM e; DELETE FROM e;   -- MySQL: 0 | MO: ERROR 20101
INSERT INTO e VALUES (1, '1_0', 'a,c'); SELECT e+0 FROM e; DELETE FROM e;   -- MySQL: 0 | MO: ERROR 20101 ("number 10 overflow") -- '1_0' parsed as numeric literal 10
INSERT INTO e VALUES (1, '0', 'a,c');   SELECT e+0 FROM e; DELETE FROM e;   -- MySQL: 0 | MO: ERROR 20101
-- SET: MySQL keeps valid members with a warning; MatrixOne rejects the whole value:
INSERT INTO e VALUES (1, 's', 'a,c,x'); SELECT s+0 FROM e; DELETE FROM e;  -- MySQL: 5 | MO: ERROR 20101
INSERT INTO e VALUES (1, 's', 'a,,c');  SELECT s+0 FROM e; DELETE FROM e;  -- MySQL: 5 | MO: ERROR 20101
-- strict mode: MySQL ACCEPTS 'xs ' silently (valid value after trailing-space strip); MatrixOne still errors:
SET sql_mode='STRICT_TRANS_TABLES';
INSERT INTO e VALUES (1, 'xs ', 'a,c');

-- Unit-level confirmation (Go test run on this build, pkg/container/types/loom_test_enum_set_edges_test.go):
//  ParseEnum("xs,s,m,l,xl", "xs ") -> error "convert to MySQL enum failed: item xs  is not in enum [...]"
//  ParseEnum("xs,s,m,l,xl", "1_0") -> error "convert to MySQL enum failed: number 10 overflow enum boundary"
//  ParseSet("a,b,c", "a,c,x") -> error "convert to MySQL set failed: item a,c,x is not in set [a,b,c]"
//  ParseSet("a,b,c", "1_0")     -> error "convert to MySQL set failed: value 10 overflow set boundary 7"
// Run with: CGO_CFLAGS="-I$PWD/cgo -I$PWD/thirdparties/install/include" go test ./pkg/container/types/ -run Loom -v

Found by Loom bug hunt (module: column-data; tests: unit, black-box, fuzzing)

Activity

  1. added
    kind/bug
    on Oct 18, 2026
  2. added
    ai-easy
    on Oct 21, 2026
  3. Ariznawlll commented on Oct 21, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:fdcb37a5212a4bbc82fd958e6f54f195081bb56b(执行时官方 main;修复 PR Fix ENUM and SET assignment compatibility with MySQL #30683 的 merge commit 1179c9d61db014b24a85998f013ccd4c1ca1fade 已在其中)
    • 部署方式:隔离的 macOS arm64 新数据目录,1 LogService / 1 TN / 2 CN;分别经 MySQL 协议连接两个 CN(16001、16002)。
    • 测试日期:2026-10-21

    原问题验证

    使用 issue 原表结构 e ENUM('xs','s','m'), s SET('a','b','c'),每个 CN 独立执行 3 轮(共 6/6),每轮使用独立数据库。严格模式下原先错误拒绝的 ENUM 'xs '、SET 'a,c ' 均写入成功,读回序号分别为 1、5。非严格模式下原先整体报错的 ENUM 'zz' 与 SET 'a,c,x' 写入后读回 0、5,同一语句立即 SHOW COUNT(*) WARNINGS 返回 2,而不是静默吞错。

    Happy Path 覆盖

    1. 两个 CN 各 3/3:非严格模式逐行核对 ENUM '1_0'→0、'0'→0、'5'/'6'→0、'XS'→1;SET 'a,,c'→5、'a , c'→0、'255'/'9'/'1_0'→0、'A,C'→5、'b,b'→2、'a,c '→5,与 issue 给出的 MySQL 数值 oracle 一致。
    2. 严格模式的合法尾随空格输入和非严格模式的普通值均通过;NULL 的 ENUM/SET 列读回仍为 NULL/NULL,没有误转为序号 0。每轮数据库均已清理,6/6。

    Unhappy Path 覆盖

    1. 严格模式多行 INSERT 中含非法 ENUM 'bad':两个 CN 各 3/3 返回 ERROR 1265,随后查询两个目标主键的行数均为 0,证明整条语句没有部分写入。
    2. 严格模式 INSERT IGNORE 输入非法 ENUM 与含未知成员的 SET:两个 CN 各 3/3 保留 ENUM 错误成员序号 0 和合法 SET 位图 5,立即读取警告数为 2;未把拒绝或截断误判为无告警成功。

    白盒验证

    pkg/container/types 的 TestEnumAssignmentParsing、TestSetAssignmentParsing,以及 pkg/sql/plan/function 的五项 ENUM/SET 赋值模式、策略、掩码、告警和边界测试,均以 -count=3 -p=1 通过。现有真实 MySQL 协议集成用例 TestEnumSetAssignmentCompatibilityOverMySQLProtocol 亦独立运行 -count=3 -p=1 通过;它还断言 UPDATE 原子性、告警保留上限和预处理语句复用。该问题没有并发/race 触发条件,未额外运行 race。

    回归测试

    修复 PR #30683 已合入 main;已有成对公开 SQL/BVT issue_30538_enum_set_assignment.sql / .result。PR 的 Linux 多 CN BVT 日志显示该文件 74/74 语句成功、0 失败,CI Required 为 SUCCESS。本地未另跑完整 BVT suite;已有公开 SQL 回归和真实协议 Go 集成覆盖该缺陷,不重复向 MOTR 添加同一用例。PR 声明未覆盖的十进制/浮点转换及历史分组哨兵歧义不属于本 issue 原始字符串/整数复现,不能据本次结果声称这些路径已修复。

    测试证据

    • 本次独立公开 SQL:16001 与 16002 各 3/3;每轮核对 11 组非严格数值、尾随空格、警告、严格失败原子性、INSERT IGNORE、NULL 和清理,均为预期值。隔离服务已正常停止,端口释放,主工作区未触碰。
    • PR 多 CN BVT job 日志明确记录该 SQL 文件 TOTAL:74, SUCCESS:74, FAILED:0;CI Required SUCCESS。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions