Skip to content

[Bug]: DECIMAL arithmetic/comparison with a BOOL operand fails with 'bad value [DECIMAL64 BOOL]' #31181

Closed

Description

@MatrixAdventurer

Bug description

Arithmetic and comparison between a DECIMAL value and a BOOL value fail at plan time in both operand orders:

ERROR 20203 (HY000): invalid argument operator +, bad value [DECIMAL64 BOOL]
ERROR 20203 (HY000): invalid argument operator =, bad value [DECIMAL64 BOOL]

This affects + - * / % DIV and = <> > < >= <=, for DECIMAL64 and DECIMAL128 (including decimal literals like 1.5 + TRUE). MySQL treats TRUE/FALSE as 1/0 here: CAST(1.5 AS DECIMAL(10,2)) + TRUE is 2.50. MatrixOne already does this for integers (2 + TRUE = 3), because the fixed binary cast tables have BOOL×INT* rows, but they have no BOOL×DECIMAL* rows. BOOL → DECIMAL is also missing from the cast table, so CAST(TRUE AS DECIMAL(10,2)) fails with [BOOL DECIMAL64].

Reported by QA as a follow-up on #30922 (comment 1, comment). #30922 / PR #30923 cover DECIMAL in a boolean context (DECIMAL → BOOL), which is the opposite direction.

How to reproduce

create table td(id int primary key, d decimal(10,2), d2 decimal(30,4));
insert into td values (1,1.50,1.50),(2,0,0),(3,null,null);
select id, d + true, true + d, d - true, d * true, d / true, d % true from td order by id;
select id, d = true, d > true, d < true, d <= true, d >= true, d <> true from td order by id;
select id, d2 + true, d2 > false from td order by id;
select cast(1.5 as decimal(10,2)) + true, 1.5 + true, cast(true as decimal(10,2));

Observed (main 5fe08a3)

Every statement fails with ERROR 20203 ... [DECIMAL64 BOOL] / [DECIMAL128 BOOL] / [BOOL DECIMAL64].

Expected (MySQL 8)

TRUE/FALSE act as 1/0, e.g. row 1: d + true = 2.50, true + d = 2.50, d - true = 0.50, d * true = 1.50, d = true = 0, d > true = 1. 1.5 + true = 2.5, cast(true as decimal(10,2)) = 1.00. NULL stays NULL.

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 30, 2026

    @gouhongshen
    Contributor

    PR #31937 is trying to fix this issue.

  4. gouhongshen commented on Oct 31, 2026

    @gouhongshen
    Contributor

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

  5. XuPeng-SH commented on Oct 31, 2026

    @XuPeng-SH
    Contributor

    转 QA 验证(不代表验收通过):#31937 已合入 main,merge SHA fe3b5591edac949af74ced9e0f3d61433826c582。已核对 issue 全部评论及 PR 修复范围,未见适用于本次合入版本的已验证反例或未完成开发 follow-up。

    证据来源:PR 作者报告 DECIMAL/BOOL 绑定与转换 UT 先红后绿、function 包通过;decimal_bool_arithmetic BVT 90/90,两个 EXISTS 相关 BVT 分别 235/0/14 skipped、340/0/20 skipped。远端评审记录 CI 成功及静态审计,但并非本轮本地复测,本轮未运行 Go、SQL 或完整 BVT。

    请 @Ariznawlll 在上述 main 版本验证原始 DECIMAL64/128 双操作数顺序、TRUE/FALSE/NULL、除零、非字面 BOOL、显式转换和各写入路径的精度拒绝/原子性;补测 DECIMAL256 与协议精度边界。BOOL 贡献一位精度,与 INT64 字面量协议 Length 可不同;BOOL / DECIMAL256 反向除法仍与现有 INT64 / DECIMAL256 一样不支持,SUM/AVG BOOL 模式及反向 DECIMAL→BOOL 不属于本次新增覆盖。保留 issue open,交接后由 QA 验证。

  6. Ariznawlll commented on Oct 31, 2026

    @Ariznawlll
    Collaborator

    结论

    测试通过。DECIMAL 与 BOOL 的原始运算、比较、转换及精度拒绝在本轮验证范围内符合研发定义。

    关键证据

    • 官方 main@ae40f12a647880a63466de32a9f507c2c72dca0b;本地隔离双 CN / 单 TN / LogService,服务二进制对应该 SHA 且 vcs.modified=false。修复 fix(function): support DECIMAL arithmetic and comparison with BOOL operands #31937 的合并提交 fe3b5591edac949af74ced9e0f3d61433826c582 在祖先链。
    • DECIMAL64/128 的双操作数顺序、算术和比较、非字面 BOOL、TRUE/FALSE/NULL、除零及显式转换均逐行断言;DECIMAL256 加法与转换也检查值和协议类型/scale。两 CN 各 3 轮通过。
    • DECIMAL(1,1)、DECIMAL(19,19)、DECIMAL(40,40) 的 TRUE 越界写入均被拒绝;DECIMAL(1,1) 的单行、多行、INSERT SELECT、UPDATE 和 ODKU 错误后原始数据不变。按研发说明,BOOL / DECIMAL256 反向除法仍不支持,实测返回 20203,不把它记作新增能力。
    • 本次 MOTR 回归 双 CN 各 3 轮成功;当前源码 TestDecimalBool*、TestBoolToDecimal* 及关联函数定向测试重复 3 次成功。

    待解决点

    • 本轮未运行完整 MOTR 全量 suite;BOOL / DECIMAL256 反向除法、SUM/AVG BOOL 及 DECIMAL→BOOL 不属于此修复新增范围。
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