Skip to content

[Bug]: all-parameter GREATEST and LEAST choose the wrong mixed runtime domain #29318

Closed

Description

@Ariznawlll

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 corresponding LEAST form 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, and IN controls did not reproduce this specific domain selection error.

Relationship to closed issues

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

  1. added this to the MO-202609 milestone on Sep 24, 2026
  2. added
    kind/bug
    on Sep 24, 2026
  3. added theissue type on Sep 24, 2026
  4. self-assigned this
    on Sep 24, 2026
  5. added a commit that references this issue on Sep 25, 2026
    426cf10
  6. Ariznawlll commented on Sep 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地单机(1 CN / 1 TN / 1 LogService)
    • 测试日期:2026-09-27

    原问题验证

    在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交 426cf10b000b6a828e8c69f1af26082f26036ed3。

    Happy Path 覆盖

    1. 全参数 GREATEST/LEAST 在整数、DECIMAL 和字符串混合绑定下选择正确运行时域。

    Unhappy Path 覆盖

    1. 将字符串参数在 10、02、10 间切换,执行计划复用后结果恢复且无类型残留。

    白盒验证

    确认修复提交 426cf10b000b6a828e8c69f1af26082f26036ed3 是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。

    回归测试

    已加入 MOTR PR #204 的 issue_29317_29318_29378_prepared_comparison.test,MOTR 提交 2b4462f2;本地基线比对连续 3 次通过。

    测试证据

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions