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]: comparing BOOL with an integer literal other than 0/1 is wrong: b = 2 matches TRUE rows #31295
Comparing a BOOL with an integer literal other than 0/1 gives wrong results. The literal is turned into TRUE before the comparison, so b = 2 behaves like b = true:
mysql> select 2 = true, -1 = true, 2 > true, 2 in (true);
1 1 0 1 -- MatrixOne
0 0 1 0 -- MySQL 8
mysql> create table t(id int, b bool); insert into t values (1, true), (2, false);
mysql> select id from t where b = 2;
1 -- MySQL: empty set
mysql> select id from t where b < 2;
2 -- MySQL: 1, 2
EXPLAIN shows the rewritten filter: Filter Cond: (t.b = true). Comparing with a column or a non-literal (b = i, b = cast(2 as bigint)) is already correct, because it casts the BOOL to BIGINT.
In MySQL TRUE/FALSE are the integers 1/0, so b = 2 is false for every row and b < 2 is true for every non-NULL row. This is a silent wrong-result bug in WHERE clauses.
Cause: convertValueIntoBool (build_util.go) runs for =, <=>, <, <=, >, >=, <> when one side is BOOL, and rewrites any integer literal to value != 0. That truth conversion is right for AND/OR/NOT/XOR, but in a comparison only 0 and 1 are the same value as a BOOL.
How to reproduce
select2= true, true =2, -1= true, 2<> true, 2> true, true <2, 2<=> true, 2in (true);
createtablet(id intprimary key, b bool);
insert into t values (1, true), (2, false), (3, null);
select id, b =2, b <>2, b <2, b >=2, b >-1from t order by id;
select id from t where b =2;
select id from t where b <2and b >-1;
QA handoff for merged #31299 at 3686e1622a7e7fcf08fa9f31829df6556861e2e6. 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 BOOL comparisons with integer literals 0, 1, negative and greater than 1 in both operand orders, NULL and IN, while retaining logical truthiness controls. This handoff does not claim a pass.
Activity
fix(plan): only rewrite integer literals 0/1 to BOOL in comparisons (#…
XuPeng-SH commentedon Oct 30, 2026
QA handoff for merged #31299 at
3686e1622a7e7fcf08fa9f31829df6556861e2e6. 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 BOOL comparisons with integer literals 0, 1, negative and greater than 1 in both operand orders, NULL and IN, while retaining logical truthiness controls. This handoff does not claim a pass.
Ariznawlll commentedon Oct 31, 2026
结论
测试通过。
关键证据
main@4f894474ad10e1b9dc338868145a118a71c1fa23,修复 fix(plan): only rewrite integer literals 0/1 to BOOL in comparisons #31299 在祖先链。2 = TRUE、TRUE = 2、负数字面量、<>、大小比较、<=>、IN返回预期;含 TRUE、FALSE、NULL 的表中b=2无结果,b<2 AND b>-1返回两条非 NULL 行。0/1 和逻辑 AND/OR 对照保持正确,3/3,测试库每轮清理。issue_31292_31295_bool_numeric.py(提交3fcb79e5);该 PR 尚未合入,完整 suite 未运行。待解决点