Skip to content

[Bug]: FLOAT/DOUBLE arithmetic and comparison with a BOOL operand fail with 'bad value [DOUBLE BOOL]' #31292

Closed

Description

@MatrixAdventurer

Bug description

Arithmetic and comparison between a FLOAT/DOUBLE and a BOOL fail to bind:

mysql> select 1e0 + true;
ERROR 20203 (HY000): invalid argument operator +, bad value [DOUBLE BOOL]
mysql> select cast(1.5 as float) + true;
ERROR 20203 (HY000): invalid argument operator +, bad value [FLOAT BOOL]
mysql> select * from t where d > b;        -- d DOUBLE, b BOOL
ERROR 20203 (HY000): invalid argument operator >, bad value [DOUBLE BOOL]

The same happens for -, *, /, %, DIV, =, <>, <, <=, >, >=, <=>, in either operand order, and for NULLIF(1e0, TRUE) (lowered to =).

MySQL treats TRUE/FALSE as the integers 1/0, so these evaluate as DOUBLE: 1e0 + TRUE = 2, 3e0 / TRUE = 3, 5e0 % TRUE = 0, 5e0 DIV TRUE = 5, 1e0 = TRUE = 1. MatrixOne already does this for integers (2 + true = 3).

Cause: fixedBinaryCastRule1 / fixedBinaryCastRule2 (type_check.go) have BOOL × INT*/UINT* rows but no BOOL × FLOAT32/FLOAT64 rows. BOOL → FLOAT casts already exist (boolToFloat).

Related: #31181 / #31193 fix the same gap for DECIMAL × BOOL.

How to reproduce

select 1e0 + true, 3e0 / true, 5e0 % true, 5e0 div true, 1e0 = true, true < 2e0;
create table tf(f float, d double, b bool);
insert into tf values (1.5, 2.5, true), (0, 0, false), (null, null, null);
select f + b, d - b, d * b, f = b, d > b from tf;
select * from tf where d > b;
select nullif(1e0, true), nullif(2e0, true);

Observed (main e033d4a)

Every statement fails with bad value [DOUBLE BOOL] / [FLOAT BOOL].

Expected (MySQL 8)

2 3 0 5 1 1; table rows 2.5 1.5 2.5 0 1 / 0 0 0 1 0 / NULL…; the WHERE returns the first row; NULL 2.

Environment

  • matrixone main e033d4a, local single-node

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

Activity

  1. added
    kind/bug
    severity/s0
    ai-easy
    on Oct 26, 2026
  2. added a commit that references this issue on Oct 30, 2026
    bc16835
  3. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    QA handoff for merged #31296 at bc168358728aaa8141ae7a3c9d8f27bb8cb33e75. This round reviewed the issue and change only; no build or functional test ran at this SHA because the existing memory guard was exceeded. Author-reported tests are separate evidence.

    Please verify FLOAT/DOUBLE with BOOL in both operand orders across arithmetic and comparisons, NULL, division/error controls and prepared execution. This handoff does not claim a pass.

  4. Ariznawlll commented on Oct 31, 2026

    @Ariznawlll
    Collaborator

    结论

    测试通过。

    关键证据

    • 2026-10-31 本地隔离双 CN、TN、LogService;服务为官方 main@4f894474ad10e1b9dc338868145a118a71c1fa23,修复 fix(function): treat BOOL as 1/0 next to FLOAT/DOUBLE in arithmetic and comparison #31296 在祖先链。
    • 原始 FLOAT/DOUBLE 与 BOOL 的算术、比较、表列 WHERE 和 NULLIF 示例返回预期;额外覆盖正反操作数顺序、加减乘除、取模、DIV、各比较及 NULL-safe 等值。NULL 保持 NULL;prepared 参数 2 与 NULL 分别得到预期结果,除零后连接可继续使用,3/3。
    • 实际 SQL 回归见 MOTR #298 的 issue_31292_31295_bool_numeric.py(提交 3fcb79e5);该 PR 尚未合入,完整 suite 未运行。

    待解决点

    • 无。
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