You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: DECIMAL values in a boolean context (AND/OR/NOT/XOR/CASE WHEN/WHERE) fail with 'bad value [DECIMAL64 BOOL]' #30922
Using a DECIMAL value in a boolean context fails at plan time:
ERROR 20203 (HY000): invalid argument operator cast, bad value [DECIMAL64 BOOL]
([DECIMAL128 BOOL] for decimal(19..38, x) values.) This affects AND, OR, NOT, XOR, IS [NOT] TRUE/FALSE, CASE WHEN <decimal>, and WHERE <decimal> / WHERE <decimal column>. FLOAT, integer and string operands already work, and so does IF(<decimal>, ...).
How to reproduce
select0.5and1;
select0.5or0;
select not 0.5;
select0.5 xor 0;
select0.5 is true;
select case when 0.5 then 'y' else 'n' end;
select1from dual where0.5;
select cast(0.5asdecimal(38,10)) and1; -- [DECIMAL128 BOOL]createtablet(a decimal(10,3));
insert into t values (0.5),(0),(-2.25),(null),(0.001);
select a from t where a;
Every statement above returns ERROR 20203 ... invalid argument operator cast, bad value [DECIMAL64 BOOL] (or DECIMAL128 BOOL).
Expected behavior (MySQL 8.0)
Any non-zero value is TRUE, zero is FALSE, and NULL stays NULL:
query
MySQL
select 0.5 and 1
1
select not 0.5
0
select 0.5 xor 0
1
select case when 0.5 then 'y' else 'n' end
y
select 1 from dual where 0.5
1 row
select a from t where a
-2.250, 0.001, 0.500
Environment
MatrixOne main 2b388dd1, single-node launch.toml.
Additional information
supportedTypeCast in pkg/sql/plan/function/func_cast.go has no T_bool target for T_decimal64, T_decimal128 or T_decimal256, and decimal*ToOthers has no BOOL branch, so the implicit BOOL cast inserted for logical operators and filters is rejected.
本轮不重复测试原 issue 的 DECIMAL 用例,而是验证同一隐式 BOOL 转换表的相邻类型 BIT:SELECT b AND 1 报 20203/HY000: invalid argument operator and, bad value [BIT BOOL],SELECT NOT b 报 [BIT]。三份全新表均可复现。
So the DECIMAL-vs-BOOL incompatibility spans +, -, *, / (and likely % and comparison) in addition to the AND/OR/NOT/XOR/WHERE boolean contexts already listed. MySQL coerces BOOLEAN to 1/0 in all of these.
So the DECIMAL-vs-BOOL incompatibility is total: every operator family (arithmetic, comparison, logical) rejects a BOOLEAN operand against a DECIMAL, while MySQL coerces BOOLEAN to 1/0 everywhere. The fix should be one place — the DECIMAL↔BOOL coercion rule.
Thanks for the extra cases. I re-ran them on a local single-node build of the #30923 fix commit (e69ef6f):
Fixed by #30923 (DECIMAL→BOOL implicit cast in boolean contexts): x AND 1, x OR 0, x XOR 1, NOT x, WHERE x, CASE WHEN x on a DECIMAL(10,2) column with 0 / 1.5 / NULL now return the MySQL results.
Not fixed by #30923, still ERROR 20203 on the PR build:
BIT in logical operators: b AND 1, b OR 0, NOT b (BIT(1) and BIT(8)) → [BIT BOOL] / [BIT]. (WHERE b and IF(b,1,0) already work.)
DECIMAL arithmetic with a BOOL operand: + - * / %, both operand orders → [DECIMAL64 BOOL].
DECIMAL comparison with a BOOL operand: = > < <= >= → [DECIMAL64 BOOL].
These go through different rules (BIT→BOOL implicit cast; BOOL operand in arithmetic/comparison operator overloads) than the cast #30923 adds, so #30923 stays scoped to the original report. The remaining cases are small and will be followed up separately.
CN1/CN2/CN1 三轮,原始 0.5 AND 1、OR 0、NOT 0.5、XOR 0、IS TRUE、CASE WHEN、WHERE 0.5 及 CAST(0.5 AS DECIMAL(38,10)) AND 1 均返回预期真值,不再报 [DECIMAL64/128 BOOL]。每轮新建 5 行 DECIMAL 表(0.5、0、-2.25、NULL、0.001),WHERE a ORDER BY a 精确返回 -2.250, 0.001, 0.500,全表仍为 5 行。
Activity
Ariznawlll commentedon Oct 23, 2026
测试版本
maind4c37f4d8722dd91b80f5f5547940004bf1b293f原问题验证
本轮不重复测试原 issue 的 DECIMAL 用例,而是验证同一隐式 BOOL 转换表的相邻类型
BIT:SELECT b AND 1报20203/HY000: invalid argument operator and, bad value [BIT BOOL],SELECT NOT b报[BIT]。三份全新表均可复现。Happy Path 覆盖
BIT(1)/BIT(8)四行(0、1、128、NULL)写入成功,b+0/w+0数值为预期的 0、1、128、NULL。IF(b,1,0)与WHERE b中可正确筛出真值行id=2,3;失败之后源表仍有四行,SELECT 1正常。Unhappy Path 覆盖
SELECT id,b AND 1 FROM t ORDER BY id:3/3 报[BIT BOOL],无任何结果行。SELECT id,NOT b FROM t ORDER BY id:3/3 报[BIT],而不是返回 1、0、0、NULL。白盒验证
pkg/sql/plan/function/type_check.go的implicitCastSupported为T_bit只列出T_int64、T_uint64,没有T_bool;list_operator.go的AND/NOT检查走隐式 BOOL 转换。这与本 issue 中 DECIMAL 缺少隐式 BOOL 路由属于同一类根因,因此把 BIT 边界补在这里,不重复新提。未修改源码或跑该点 UT。回归测试
本轮未向仓库新增 BVT/motr/UT 或 PR。建议修复时把 BIT(1)/BIT(8) 的 0、1、非零、NULL 和
AND/OR/NOT/WHERE/IF一并补入现有转换用例。测试证据
/private/tmp/mo-explore-run-20261023/prepared_121443/jdbc.jsonl/private/tmp/mo-explore-run-20261023/BitTruthCross.javab'1' AND 1字面量另报运行时字节解析错误;它经过不同路径,不作为本 issue 的 BIT 列隐式转换复现计算。测试结论
测试不通过。
Ariznawlll commentedon Oct 23, 2026
Same root cause also breaks arithmetic with a BOOLEAN operand (not just boolean/logical contexts), worth covering in the same fix:
So the DECIMAL-vs-BOOL incompatibility spans
+,-,*,/(and likely%and comparison) in addition to theAND/OR/NOT/XOR/WHEREboolean contexts already listed. MySQL coerces BOOLEAN to 1/0 in all of these.Ariznawlll commentedon Oct 23, 2026
Confirmed — comparison operators are also affected (the earlier comment listed arithmetic
+``-``*; this adds=``>``<``<=``>=):So the DECIMAL-vs-BOOL incompatibility is total: every operator family (arithmetic, comparison, logical) rejects a BOOLEAN operand against a DECIMAL, while MySQL coerces BOOLEAN to 1/0 everywhere. The fix should be one place — the DECIMAL↔BOOL coercion rule.
fix(sql): support DECIMAL to BOOL cast for boolean contexts (#30923)
MatrixAdventurer commentedon Oct 26, 2026
Thanks for the extra cases. I re-ran them on a local single-node build of the #30923 fix commit (e69ef6f):
Fixed by #30923 (DECIMAL→BOOL implicit cast in boolean contexts):
x AND 1,x OR 0,x XOR 1,NOT x,WHERE x,CASE WHEN xon a DECIMAL(10,2) column with 0 / 1.5 / NULL now return the MySQL results.Not fixed by #30923, still
ERROR 20203on the PR build:b AND 1,b OR 0,NOT b(BIT(1) and BIT(8)) →[BIT BOOL]/[BIT]. (WHERE bandIF(b,1,0)already work.)+ - * / %, both operand orders →[DECIMAL64 BOOL].= > < <= >=→[DECIMAL64 BOOL].These go through different rules (BIT→BOOL implicit cast; BOOL operand in arithmetic/comparison operator overloads) than the cast #30923 adds, so #30923 stays scoped to the original report. The remaining cases are small and will be followed up separately.
MatrixAdventurer commentedon Oct 26, 2026
Follow-ups for the extra cases above. They are tracked separately and #30923 is unchanged:
Ariznawlll commentedon Oct 26, 2026
测试版本
main;commit:7b80dbdbd398d171a47875f2a6196bf195a535eb。原 DECIMAL 布尔上下文修复 PR #30923 已 MERGED,commitc88752332cb29ec9a2774497c2cb179ddfe6cb6a是该 main 祖先。git_version()=7b80dbdbd3、SHA-2560549f8b3fcb4303f8220a15163e8b44b9c8c834e3c1ab1b19ce7ced84da999e2。日期:2026-10-27。原问题验证
CN1/CN2/CN1 三轮,原始
0.5 AND 1、OR 0、NOT 0.5、XOR 0、IS TRUE、CASE WHEN、WHERE 0.5及CAST(0.5 AS DECIMAL(38,10)) AND 1均返回预期真值,不再报[DECIMAL64/128 BOOL]。每轮新建 5 行 DECIMAL 表(0.5、0、-2.25、NULL、0.001),WHERE a ORDER BY a精确返回-2.250, 0.001, 0.500,全表仍为 5 行。Happy Path 覆盖
Unhappy Path 覆盖
0.0 AND 1得 0,NULL AND 1得 SQL NULL;无错误或额外行。每轮测试库清理。此前 QA 扩展发现的 BIT 与 DECIMAL/BOOL 算术、比较问题已由研发分别另列 #31180、#31181,不把这些不同运算符范围伪称为本 PR 覆盖。白盒验证
本次用公共 SQL 检查产品返回值;未重复 Go UT。该修复 PR 对应布尔转换用例和 CI 已提供内部覆盖。
回归测试
现有 DECIMAL 布尔上下文 BVT 与配对结果覆盖原入口;MOTR #278 不重复。PR 的 CI Required 通过。
测试证据
qa-night/verify_new_five.py:每轮 10 个标量真值断言加 5 行表值/行数检查,3/3;修复 PR/BVT/CI 链接如上。测试结论
测试通过。
sql/plan: support BIT columns in AND/OR/XOR/NOT (#31682)
fix(plan): MySQL implicit boolean semantics for ENUM/SET, BIT literal…