Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked existing issues. [Bug]: prepared SET inserts reject label strings as uint64 #27331 / [Bug]: Server-prepared INSERT and UPDATE must bind ENUM/SET label parameters #27332 are about prepared-statement parameter markers for SET/ENUM (different code path: parameter binding, not literal value conversion). No issue found for ENUM/SET literal value matching semantics (searched: "enum trailing space", "enum truncation", "convert to MySQL enum failed", "enum insert invalid value").
Environment
- MatrixOne commit:
beffc64c486d369406a41cdb1447b120bc93cb41(main, 2026-10-18), standalonemo-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):
- 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). - 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. - 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'sstrconv.ParseUint(name, 0, 64)interprets Go base-0 syntax (0x,0b,0o, and_separators), producing numeric values MySQL never derives. - 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
- Start standalone
mo-service(any recent main, verified onbeffc64c486d) and connect with a mysql client. - Create the table from the
reprofield. SET sql_mode=''; then run each INSERT/output pair from thereprofield. Compare with MySQL 8.0.46.- 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:
pkg/container/types/enum.go:56parseEnumNamematches withstrings.EqualFold(n, name)— no trimming of trailing spaces, so'xs 'can never match'xs'(MySQL strips trailing spaces before matching).pkg/container/types/enum.go:32-48ParseEnum: when the name does not match it falls tostrconv.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 becomesmoerr.NewInternalErrorNoCtxf(...).pkg/container/types/set.go:90ParseSetbehaves 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.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 -vFound by Loom bug hunt (module: column-data; tests: unit, black-box, fuzzing)
Activity
test: make ENUM rejection BVT strict-mode explicit
Ariznawlll commentedon Oct 21, 2026
测试版本
mainfdcb37a5212a4bbc82fd958e6f54f195081bb56b(执行时官方 main;修复 PR Fix ENUM and SET assignment compatibility with MySQL #30683 的 merge commit1179c9d61db014b24a85998f013ccd4c1ca1fade已在其中)原问题验证
使用 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 覆盖
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 一致。NULL的 ENUM/SET 列读回仍为NULL/NULL,没有误转为序号 0。每轮数据库均已清理,6/6。Unhappy Path 覆盖
INSERT中含非法 ENUM'bad':两个 CN 各 3/3 返回ERROR 1265,随后查询两个目标主键的行数均为0,证明整条语句没有部分写入。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 原始字符串/整数复现,不能据本次结果声称这些路径已修复。测试证据
INSERT IGNORE、NULL 和清理,均为预期值。隔离服务已正常停止,端口释放,主工作区未触碰。TOTAL:74, SUCCESS:74, FAILED:0;CI Required SUCCESS。测试结论
测试通过。
fix(enum): trim trailing spaces from ENUM labels like MySQL (#32885)