Repository navigation
Description
Environment
- MatrixOne
main:95b1d2bfd9d756d08320569858080cb16f230fff - Local standalone launch configuration
Problem
GREATEST() and LEAST() choose a different common comparison domain when every operand is a prepared parameter marker. With mixed DECIMAL, integer, and character runtime operands, the all-parameter form performs numeric comparison while the equivalent direct expression and a prepared statement with fixed candidates use the expected mixed string comparison.
Reproduction
SELECT GREATEST(2.0,1,2,'10'), LEAST(2.0,1,2,'10');
PREPARE p FROM
'SELECT GREATEST(?,?,?,?), LEAST(?,?,?,?)';
SET @v=2.0,@a=1,@b=2,@c='10';
EXECUTE p USING @v,@a,@b,@c,@v,@a,@b,@c;Results:
direct: 2.0 | 1
prepared: 10.0 | 1.0
The prepared result shows numeric comparison (10 > 2.0) while the direct mixed-domain expression uses character comparison ('2.0' > '10').
Controls
- Repeated the complete sequence three times with identical results.
PREPARE ... GREATEST(?,1,2,'10')and the correspondingLEASTform return the same values as direct SQL for DECIMAL, DOUBLE, and integer runtime needles.- The all-parameter statement returns the direct values when the first runtime operand is DOUBLE, integer, or character. The divergence occurs with a DECIMAL first operand combined with integer and character candidates.
- Rebinding the same statement from DECIMAL to DOUBLE/integer changes it back to the direct result; the statement remains reusable.
COALESCE,NULLIF,CASE, andINcontrols did not reproduce this specific domain selection error.
Relationship to closed issues
- [Bug]: Prepared DECIMAL arguments in COALESCE/GREATEST/LEAST lose precision and NULL rebinding panics #26879 covered prepared DECIMAL values combined with already-typed DECIMAL columns and precision/NULL-rebind failures. Its fixed regression remains correct on this revision.
- [Bug]: GREATEST/LEAST reject mixed string-number arguments unlike MySQL #25215 established that mixed string/number
GREATESTandLEASTcalls use string comparison, including prepared statements with typed/fixed operands.
This report is a distinct all-parameter-marker specialization gap: the binder has no typed operand at PREPARE time from which to derive the common domain, and execution does not reconstruct the same mixed-domain choice made for the equivalent direct expression.
Activity
fix: preserve prepared variadic comparison domains (#29345)
Ariznawlll commentedon Sep 27, 2026
测试版本
main5be6cd90b501da225be591ffffe6000bf01f515e原问题验证
在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交
426cf10b000b6a828e8c69f1af26082f26036ed3。Happy Path 覆盖
Unhappy Path 覆盖
10、02、10间切换,执行计划复用后结果恢复且无类型残留。白盒验证
确认修复提交
426cf10b000b6a828e8c69f1af26082f26036ed3是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。回归测试
已加入 MOTR PR #204 的
issue_29317_29318_29378_prepared_comparison.test,MOTR 提交2b4462f2;本地基线比对连续 3 次通过。测试证据
5be6cd90b501da225be591ffffe6000bf01f515e测试结论
测试通过。