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]: GREATEST/LEAST reject a BOOL argument mixed with numeric or string arguments #31293
GREATEST / LEAST reject a BOOL argument mixed with any other type:
mysql> select greatest(2, true);
ERROR 20203 (HY000): invalid argument function greatest, bad value [BIGINT BOOL]
mysql> select least(0.5e0, true);
ERROR 20203 (HY000): invalid argument function least, bad value [DOUBLE BOOL]
mysql> select greatest('a', true);
ERROR 20203 (HY000): invalid argument function greatest, bad value [VARCHAR BOOL]
mysql> select greatest(int_col, bool_col) from t;
ERROR 20203 (HY000): invalid argument function greatest, bad value [INT BOOL]
MySQL treats TRUE/FALSE as the integers 1/0: GREATEST(2, TRUE) = 2, LEAST(2, TRUE) = 1, LEAST(0.5e0, TRUE) = 0.5, GREATEST('a', TRUE) = 'a' (string comparison with '1'), LEAST('a', TRUE) = '1'. GREATEST(TRUE, FALSE) (BOOL only) already works.
Cause: resolveLeastGreatestType (func_builtin_leastgreatest.go) has no rule for BOOL next to another type, so leastGreatestCommonNumericType / leastGreatestStringMixedType reject it (BOOL is not numeric there).
GREATEST(1.5, TRUE) (DECIMAL with BOOL) fails the same way. It also needs a BOOL → DECIMAL cast, which #31193 (for #31181) adds.
How to reproduce
select greatest(2, true), least(2, true), greatest(true, 0), least(false, 3);
select greatest(1e0, true), least(0.5e0, true);
select greatest('a', true), least('a', true);
createtablet(i int, u bigint unsigned, d double, s varchar(10), b bool);
insert into t values (5, 7, 2.5, 'x', true), (-5, 0, 0.25, '0', false);
select greatest(i, b), least(i, b), greatest(u, b), greatest(d, b), least(s, b) from t;
Activity
fix(function): GREATEST/LEAST accept BOOL mixed with numeric or strin…
XuPeng-SH commentedon Oct 30, 2026
暂不整体转测:#31297 已合入并修复 BOOL 混合整数/浮点/字符串的 GREATEST/LEAST 绑定,但 issue 正文明确包含 DECIMAL+BOOL;#31297 明确依赖额外 BOOL→DECIMAL 修复。当前相关 #31937 仍是 open/draft、未合并,不能把本地合并组合的作者验证算作 main 已交付。保留研发负责人,待该剩余开发路径合入后再转测;本轮为合并状态与源码说明静态核对,未执行 SQL。
XuPeng-SH commentedon Oct 31, 2026
更新此前暂不转测结论,现转 QA 验证(不代表验收通过):#31297 已合入 main,merge SHA
c431c1e9b58c20756631a0c5223c2d121e5533dd;此前等待的 BOOL→DECIMAL 开发依赖现由 #31937 合入 main,merge SHAfe3b5591edac949af74ced9e0f3d61433826c582补齐。已重读 issue 全部评论及两项修复范围,原“依赖未合并”理由已失效,未见当前版本已验证反例或其余未完开发 follow-up。已有证据而非本轮实测:#31297 作者报告 mixed BOOL UT 先红后绿、BVT 14/14,评审记录 36 个 focused tests 及 function 包通过;作者曾在本地组合修复上验证 DECIMAL+BOOL。#31937 作者报告 BOOL→DECIMAL 绑定/转换 UT 与相关 BVT 通过。上述作者组合测试不等于本轮对最新 main 的复测,本轮没有运行 Go、SQL 或完整 BVT。
请 @Ariznawlll 在 main
fe3b5591edac949af74ced9e0f3d61433826c582重点验证GREATEST(1.5, TRUE)/LEAST(1.5, TRUE)及 BOOL 与 signed/unsigned 混合而提升到 DECIMAL 的路径,同时回归整数、浮点、字符串、NULL、BOOL-only 和列参数。关注 unsigned 大值不误转有符号、DECIMAL 精度/scale 和返回类型。最新 main 的组合运行及更宽数据范围留给 QA,不自动关闭 issue。Ariznawlll commentedon Oct 31, 2026
结论
测试通过。GREATEST/LEAST 的 BOOL 与数值及字符串混合场景在本轮验证范围内返回预期值和类型。
关键证据
main@ae40f12a647880a63466de32a9f507c2c72dca0b;本地隔离双 CN / 单 TN / LogService,服务二进制对应该 SHA 且vcs.modified=false。修复 fix(function): GREATEST/LEAST accept BOOL mixed with numeric or string arguments #31297 与其 DECIMAL 依赖 fix(function): support DECIMAL arithmetic and comparison with BOOL operands #31937 均已合入并在祖先链。GREATEST(1.5,TRUE)=1.5、LEAST(1.5,TRUE)=1.0,DECIMAL 协议类型与 scale 也被检查。UINT64_MAX与 BOOL 混合不发生有符号截断;再与有符号 -1 混合时,最大值仍为 18446744073709551615、最小值为 -1,结果提升到 scale 0 的 DECIMAL。查询结束后连接正常。TestLeastGreatest*等定向测试重复 3 次成功。待解决点