Skip to content

[Bug]: BIT columns fail in AND/OR/XOR/NOT with 'bad value [BIT BOOL]' #31180

Closed

Description

@MatrixAdventurer

Bug description

A BIT column used as an operand of the logical operators AND / OR / XOR / NOT (and && / || / !) fails at plan time:

ERROR 20203 (HY000): invalid argument operator and, bad value [BIT BOOL]
ERROR 20203 (HY000): invalid argument operator not, bad value [BIT]

MySQL treats BIT as a number in a boolean context (non-zero = TRUE, 0 = FALSE, NULL = NULL). MatrixOne already does this for WHERE b and IF(b,1,0), and an explicit CAST(b AS BOOL) works. Only the logical operators reject it, because their type check asks whether BIT can be implicitly cast to BOOL, and the T_bit row of implicitCastSupported (pkg/sql/plan/function/type_check.go) lists only INT64/UINT64.

Reported by QA as a follow-up on #30922 (comment); #30922 / PR #30923 only cover DECIMAL. This is the BIT column case; the b'1' AND 1 bit-value literal case goes through a different path and is tracked in #30930 / #30931.

How to reproduce

create table tb(id int primary key, b bit(1), w bit(8));
insert into tb values (1,0,0),(2,1,1),(3,1,128),(4,null,null);
select id, b and 1, b or 0, not b, b xor 1 from tb order by id;
select id, w and 1, w or 0, not w, w xor 0 from tb order by id;
select id from tb where not w order by id;

Observed (main 5fe08a3)

All three statements fail with ERROR 20203 ... [BIT BOOL] / [BIT]. select id from tb where b and w returns 2, 3, so WHERE truthiness works.

Expected (MySQL 8)

id  b and 1  b or 0  not b  b xor 1
1   0        0       1      1
2   1        1       0      0
3   1        1       0      0
4   NULL     NULL    NULL   NULL

For w, 128 is TRUE. where not w returns id 1.

Environment

  • matrixone main 5fe08a3, local single-node

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

Activity

  1. added
    kind/bug
    on Oct 26, 2026
  2. added
    severity/s0
    ai-easy
    and removed on Oct 26, 2026
  3. gouhongshen commented on Oct 29, 2026

    @gouhongshen
    Contributor

    PR #31682 is trying to fix this issue.

  4. gouhongshen commented on Oct 29, 2026

    @gouhongshen
    Contributor

    PR #31682 has merged and is awaiting manual validation. The issue remains open.

  5. XuPeng-SH commented on Oct 29, 2026

    @XuPeng-SH
    Contributor

    QA handoff for merged #31682 (2fa5b0c945499475e1f2e7c3035a6169f9aa4ce8): this isolated QA run inspected the source and issue history but did not run current-head functional tests or live SQL because the existing resource guard left insufficient headroom. Please verify BIT logical operators, NULL, high bits and conditional result type controls. Author-reported PR tests are separate evidence and are not results of this QA run.

  6. Ariznawlll commented on Oct 30, 2026

    @Ariznawlll
    Collaborator

    结论

    测试通过。BIT 列可参与逻辑运算,非零、零与 NULL 的结果符合预期。

    关键证据

    • 官方 main@415068ce4d3a9188a8ba82c24742de0f1b1765c0,修复 PR sql/plan: support BIT columns in AND/OR/XOR/NOT #31682 合并提交 2fa5b0c945499475e1f2e7c3035a6169f9aa4ce8 位于该版本祖先链。实际二进制构建信息与完整 SHA 一致;本地隔离 1 CN / 1 TN / 1 LogService,Python 3.12、PyMySQL 1.2.3。
    • 3 个独立数据库中按原始四行 BIT(1)/BIT(8) 数据验证 AND、OR、NOT、XOR;BIT(8) 的 128 按真值处理,NULL 运算保持 NULL,WHERE NOT w 仅返回 id=1;另验证 &&、||、!、WHERE 和 IF 的结果与逻辑表达式整型协议元数据。
    • 重复主键批量写入被拒绝且原四行仍在;每轮测试库已清理。MOTR #295 定向 3/3 通过、0 skipped。

    待解决点

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions