Skip to content

[Bug]: comparing an ENUM column with a SMALLINT UNSIGNED column panics (type mismatch casting SMALLINT UNSIGNED vector to []types.Enum) #31901

Closed

Description

@MatrixAdventurer

问题描述

ENUM 列和 SMALLINT UNSIGNED 列比较时,MO 在执行阶段 panic(被捕获后返回 20101 internal error: panic type mismatch: casting SMALLINT UNSIGNED vector to []types.Enum)。WHERE e = s、WHERE s = e、SELECT e = s 都会触发。<、+、* 则在绑定阶段报 bad value [ENUM SMALLINT UNSIGNED]。

同样的写法把 SMALLINT UNSIGNED 换成 INT UNSIGNED 或 TINYINT UNSIGNED 就正常,所以问题只出在 SMALLINT UNSIGNED 上(ENUM 的物理存储正好也是 uint16,看起来是被当成了同一种类型)。

环境

  • 分支:main(c32e75a2,2026-10-30)
  • 对照:MySQL 8.4.9

复现步骤

create table t (e enum('a','b','c'), s smallint unsigned, u int unsigned, ti tinyint unsigned);
insert into t values ('b', 2, 2, 2);
select e = u, e = ti, e + u from t;   -- 正常:1 1 4
select e = s from t;
select * from t where e = s;
select * from t where s = e;
select e < s from t;
select e + s from t;
select s * e from t;

实际结果(MO)

select e = s               -> ERROR 20101 (HY000): internal error: panic type mismatch: casting SMALLINT UNSIGNED vector to []types.Enum:
                              github.com/matrixorigin/matrixone/pkg/container/vector.checkType[...] vector.go:227
                              ... vector.ToFixedCol ... function.opBinaryFixedFixedToFixed ... function.equalFn (func_compare.go:1248)
select * where e = s       -> 同上
select * where s = e       -> ERROR 20101 (HY000): internal error: panic type mismatch: casting ENUM vector to []uint16: ...
select e < s               -> ERROR 20203 (HY000): invalid argument operator <, bad value [ENUM SMALLINT UNSIGNED]
select e + s               -> ERROR 20203 (HY000): invalid argument operator +, bad value [ENUM SMALLINT UNSIGNED]
select s * e               -> ERROR 20203 (HY000): invalid argument operator *, bad value [SMALLINT UNSIGNED ENUM]

服务端日志里是 panic in pipeline: internal error: panic type mismatch ...。

期望结果(MySQL 8.4.9)

ENUM 在数值上下文里取成员序号('b' → 2):

e = s -> 1;WHERE e = s / WHERE s = e 都返回那一行;e < s -> 0;e + s -> 4;s * e -> 4

本操作由 LW 授权的 Grok Bot 智能体执行。

Activity

  1. added
    kind/bug
    on Oct 30, 2026
  2. assigned and unassigned on Nov 7, 2026
  3. added a commit that references this issue on Nov 8, 2026
    fbcca45
  4. XuPeng-SH commented on Nov 8, 2026

    @XuPeng-SH
    Contributor

    QA 交接:#32358 已于 2026-11-08 01:55:18 UTC 合入 main,merge SHA fbcca458c3f8543236594841f22914cec78c0e3f,最终 PR head b86c8d8045463ddd315986b16e5614d2659dd0f2(base 7a73a7395506a04e2555422fee7dd5c766416f0f)。

    修复范围:保留操作数原始 ENUM 身份,仅在恰好一侧为 ENUM、另一侧为 SMALLINT UNSIGNED 的 uint16 同型分支中强制使用现有序号转换,覆盖两种操作数顺序。这样避免等值比较把 ENUM 与 uint16 物理向量混用,也让排序比较和算术运算得到可执行的共同类型。ENUM/ENUM、ENUM/varchar 的标签比较、ENUM 展示及成员元数据、普通 uint16 对和其他数值拓宽路线保持原有语义。这是 SQL 产品缺陷,不按 CI flaky 关闭。

    已核实的证据与限制:

    • 本轮读取了 issue 正文和全部评论(写前为 0 条)、合并元数据、最终四文件差异及 PR 全部讨论。原工单反例来自旧 main c32e75a2;目前未见适用于该新修复的已验证反例或未完成的开发 follow-up。
    • PR 作者报告:在 e8765aa... 基线上做 production-only overlay,未修复实现的定向 function/planner 回归语义失败,修复后定向测试通过;早期 planner 测试对单一过滤节点的错误假设已改为遍历全部保留的谓词消费者。作者另报告 336 个相关包的增量 SCA 通过,新增公共 SQL fixture 所属包随后单独复查通过,不是全仓重新检查。
    • 作者报告原生 fixture TestIssue31901EnumSmallintUnsignedNumericCoercion 一次运行通过,覆盖五类运算、WHERE 行集合、NULL、标签对照、真实 prepared 执行及严格模式错误后的连接/语句复用。该运行及二进制证据属于作者报告,本轮没有复跑。
    • 批准评审 对应较早 head d1023d77f14c649433aa42036068cc1c3a07ce8a,复用了该 head 的 UT/SCA/coverage/多 CN BVT 成功元数据,不能直接当作最终 b86c8d8 或 merge SHA 的验证。最新队列记录 显示因 fork 编辑权限退出队列、无队列 CI 运行,且当时 CI Required 条件未满足;没有把此记录写成 CI 通过。合入 main 的事实由 PR 元数据独立确认。
    • 本轮仅做远端状态核对和静态范围审阅,未执行 Go、SQL、race 或 BVT,也未独立查看作者原始运行日志;转测不代表验收通过。

    建议 QA 在包含上述 merge SHA 的 main 上优先验证:

    1. 原复现的 SELECT / WHERE 等值、排序、加法和乘法,两个操作数顺序都测;再覆盖 <=>、<>、<=、>、>=、减法和取模。对照完整返回值、NULL 位图及排序后的主键集合,不能只看“不再 panic”。
    2. ENUM 一侧 NULL、数值一侧 NULL、两侧 NULL,匹配/不匹配序号及 uint16 边界;区分已有算术范围/溢出语义,不把此次修复扩写为所有数值类型改造。
    3. ENUM/ENUM 不同成员顺序、ENUM/varchar 标签、ENUM 显示与成员元数据、纯 uint16 以及 TINYINT/INT UNSIGNED 等既有路线的对照。
    4. prepared 多次执行、普通与 NULL 参数、严格模式无效 ENUM 标签的 1265/01000 拒绝、拒绝行未落库,以及同一连接和 prepared statement 仍可使用。现有 fixture 的参数用于筛选 id,不能据此宣称“ENUM 与任意参数直接比较”已覆盖。
    5. 补核最终合并版本的公共 CI、多 CN/协议路径及需要的较宽回归;已报告的定向通过不等于整包或 race 全通过。

    转交 @Ariznawlll 进行 QA;issue 保持开放。

  5. slyunnn commented on Nov 10, 2026

    @slyunnn

    Regression and extended verification for #31901 (2026-11-10)

    Verification Environment

    • Frozen latest origin/main at test start, 11d2e1ef7e1b3ed3a20e6d7f29f912e55118db5b, fix(python): reconnect ORM export shortcuts to current exporters (#32447).
    • Freshly built CPU binary, matching native-library provenance, and runtime git_version()=11d2e1ef7e at every endpoint. macOS 26.6, arm64, Go 1.27.1.
    • Complete co-hosted topology of 2 CN / 1 TN / 1 Log service / Proxy, launched in one service process. Proxy 6001, CN1 16001 and CN2 16002 were reachable. Original and extended SQL actually ran through each endpoint.
    • PyMySQL 1.1.2 using MySQL text protocol (COM_QUERY). Additional Go database/sql + go-sql-driver/mysql tests used interpolateParams=false and actual COM_STMT_PREPARE / COM_STMT_EXECUTE on one checked-out connection per endpoint.

    What Was Covered

    • OK — Replayed the original e=s, s=e, both WHERE orders, ordering comparison, addition and multiplication through every endpoint. The ordinal 2 compares equal to 2, and arithmetic returns 4 without a vector type panic.
    • OK — Both operand orders for =, <=>, <>, <, <=, >, >=, +, * and %, including all NULL permutations and matching/nonmatching rows.
    • OK — Unsigned boundaries 0 / 65535, bounded subtraction, and existing checked 1690 overflow/underflow diagnostics. Arithmetic boundary errors retain their existing contract.
    • OK — ENUM/ENUM, label comparisons, displayed member strings, ENUM metadata, ordinary uint16 pairs, and the original wider/narrower unsigned controls.
    • OK — Native prepared execution reuses the same statement for normal and NULL filters. A strict invalid ENUM insert returns 1265 / 01000, stores no invalid row, and the same prepared insert handle subsequently succeeds.
    • Not covered — Exhaustive ENUM cardinality and every numeric-width combination. Existing focused neighboring-coercion tests passed.

    Findings

    • Associated fix fbcca458c3f8543236594841f22914cec78c0e3f, fix(sql): cast mixed ENUM and SMALLINT UNSIGNED operands. The merge is an ancestor of the frozen main commit. PR #32358
    • Mixed ENUM/uint16 operations use the ENUM ordinal conversion while preserving label and same-family controls. No panic occurred in the verified comparison, arithmetic, prepared or checked-error paths.

    MOTR / BVT Coverage

    • Added suites/14_issue_regression/t/issue_31901_enum_uint16.test and the matching .result. Recording passed, followed by 2 successful replays through each of the 3 endpoints.
    • Independent branch test/issue-31901-enum-uint16, source commit cd022508b5a88401a8e3a3e88d44ca0cd6bfd6ae, pushed and remote/upstream verified. Weekly cherry-pick 304bf4ca559c332caa2adb0c2e5523406533ee09 is included in the existing weekly summary. MOTR PR #321
    • Combined weekly tests passed with -j 5 --repeat 2, 7 isolated cases, 14/14 executions per endpoint and 42/42 total. Databases and connections are independent, with session-local settings.
    • Focused product tests recorded 142 test/subtest passes. Complete external, function and value_scan packages recorded 18,182 passes with 1 unrelated Arrow/MinIO integration skip. These counts include subtests.

    Final Conclusion

    Fixed for the issue contract on the verified main build and topology.

    Large-data regression — Not required. The failure depends on operand types and physical vector identity. Small rows and focused vector tests cover the relevant boundary.

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

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions