Skip to content

[Bug]: BIT not-equal comparisons panic in the string comparison executor #33136

Description

@Ariznawlll

Summary

The <> and != operators on BIT values panic inside the comparison executor. Other BIT comparison operators work on the same data.

Environment

  • Branch: main
  • Commit: 07d7baa32a35c2ebf7c5f5a1ef806f1d9815701b
  • Local mo-service, MySQL protocol

Reproduction

CREATE TABLE t (b BIT(8));
INSERT INTO t VALUES (39);

SELECT b = b FROM t;   -- returns 1
SELECT b <> b FROM t;  -- should return 0, but errors
SELECT b != b FROM t;  -- same failure

Actual result:

ERROR 20101 (HY000): internal error: panic unsafe slice cast:
from length 8 is not enough for length 24

The same failure reproduces with:

  • BIT(1), BIT(8), BIT(16), and BIT(64);
  • column-to-column and column-to-constant comparisons;
  • comparisons in JOIN / WHERE as well as the select list.

As controls, =, <=>, <, <=, >, >=, IN, and NOT IN completed normally.

Expected behavior

Both b <> b and b != b should return false (0) without an internal error.

Root cause

BIT is represented as fixed-width uint64. Most comparison operators in pkg/sql/plan/function/func_compare.go use opBinaryFixedFixedToFixed[uint64], but notEqualFn handles types.T_bit with opBinaryStrStrToFixed[bool]. The string wrapper then interprets the fixed-width storage as byte slices and panics.

Duplicate check

Searched open and closed issues for BIT not-equal, unsafe slice cast, notEqualFn, and opBinaryStrStrToFixed; no matching report was found.

Activity

  1. added
    kind/bug
    severity/s2
    and removed
    severity/s2
    on Nov 24, 2026
  2. added theissue type on Nov 24, 2026
  3. added this to the MO-202611 milestone on Nov 24, 2026
  4. added a commit that references this issue on Nov 25, 2026
    ba76881
  5. XuPeng-SH commented on Nov 25, 2026

    @XuPeng-SH
    Contributor

    转 QA:#33146 已合入 main,merge SHA ba768818c9f61be24338e223587baeb7c47a3a85。

    • 修复:BIT 的 <> / != 共用现有的定长 uint64 比较,不再走字符串向量;同步移除主键分组消除的旧规避分支。
    • 证据:作者记录旧版单测失败、修复后通过,并通过本地 BIT BVT;独立评审通过了混合位宽、常量、NULL 和选择掩码的定向用例。最终 PR head 两项多 CN BVT 作业通过,但 x86 UT 取消、CI Required 红,不能视作全绿。本轮未本地重跑。
    • 请用上述合并版本通过 MySQL 协议复验两种写法,在投影、过滤和 JOIN 中分别核对相等/不等、混合位宽(含 BIT(64) 高位)、NULL,并查主键分组消除后的结果与 LIMIT。这里只确认 main,不代表 4.2-dev 已修复。
  6. Ariznawlll commented on Nov 25, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在 main 修复 merge ba768818c9f61be24338e223587baeb7c47a3a85 上独立复测通过,关闭本 Issue。

    验证环境:从上述确切 SHA 的源码归档本地构建,单 CN 隔离实例,git_version() 返回 ba76881,通过 MySQL 协议执行。

    • 原始复现中 b = b 返回 1,b <> b 与 b != b 均返回 0,不再出现 internal error / panic。
    • BIT(1)、BIT(8)、BIT(16)、BIT(64) 的列自比较和列对常量比较通过;NULL 结果保持 NULL。
    • 在投影、WHERE、JOIN 投影及 JOIN 条件中分别核对 <>、!= 和 =;混合 BIT(8)/BIT(64)、BIT(64) 高位值 9223372036854775808 / 18446744073709551615、选择掩码及 NULL 过滤均与独立预期逐行一致。
    • 主键分组 + LIMIT 1 两种不等写法均返回 (3,1);EXPLAIN 为 Project -> Table Scan,过滤及 Limit 下推且无 Aggregate,确认走到了分组消除路径。
    • 定向 UT Test_NotEqualFn、TestPrimaryKeyGroupEliminationRequiresTotalResolvedComparisons 均以 -count=3 通过。
    • 全部 SQL 用例连续三轮通过,共 50 项断言;最终健康检查通过,测试期间服务日志无 panic: / FATAL。

    结论仅覆盖 main 上述修复版本,不代表 4.2-dev 或生产环境已经包含该修复。

  7. Ariznawlll commented on Nov 25, 2026

    @Ariznawlll
    CollaboratorAuthor

    验收通过,按上述复测结果关闭。

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions