Skip to content

[Bug]: CAST overflow handling differs from MySQL clamp/wrap behavior #25252

Closed

Description

@Ariznawlll

Bug Report

MatrixOne Version

Latest origin/main verified locally at 33e96877604ad4b847ea7d5c55eb09429de1a5b6.

Reproduce Steps

select cast('999999999999999999999999' as signed);
select cast('999999999999999999999999' as unsigned);
select cast('9999999.99' as decimal(6,2));

Expected Behavior

MySQL returns saturated/wrapped cast results with warnings:

-1
18446744073709551615
9999.99

Actual Behavior

MatrixOne returns errors:

ERROR 1690 (HY000): data out of range: data type int64, value '999999999999999999999999'
ERROR 1690 (HY000): data out of range: data type uint64, value '999999999999999999999999'
ERROR 20301 (HY000): invalid input: 9999999.99 beyond the range, can't be converted to Decimal64(6,2).

Notes

Found during Batch A of the MySQL compatibility cast matrix. Overflow rows were excluded from passing BVT.

Activity

  1. added
    kind/bug
    severity/s1
    on Jun 30, 2026
  2. Ariznawlll commented on Jun 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional Batch A cast-matrix row with the same MySQL wrap/clamp vs MatrixOne range-error behavior:

    select cast(-1 as unsigned);

    MySQL returns:

    18446744073709551615
    

    MatrixOne on latest origin/main (33e96877604ad4b847ea7d5c55eb09429de1a5b6) returns:

    ERROR 1690 (HY000): data out of range: data type uint64, value '-1'
    

    This row was excluded from passing BVT.

  3. added
    severity/s0
    and removed
    severity/s1
    on Jul 2, 2026
  4. added this to the MO-202607 milestone on Jul 2, 2026
  5. added theissue type on Jul 2, 2026
  6. added and removed
    severity/s0
    on Jul 2, 2026
  7. added
    severity/s0
    and removed on Jul 17, 2026
  8. added
    ai-easy
    on Jul 21, 2026
  9. Ariznawlll commented on Jul 21, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main 分支完成验证,issue 中记录的显式 CAST 溢出行为已修复。

    测试版本

    测试步骤

    1. 使用上述 commit 构建并启动单机 MatrixOne。
    2. 连接 6001 端口并执行 issue 原始用例及补充用例:
    set session sql_mode = '';
    
    select cast('999999999999999999999999' as signed);
    select cast('999999999999999999999999' as unsigned);
    select cast('9999999.99' as decimal(6,2));
    select cast(-1 as unsigned);

    实际输出:

    cast(... as signed)
    -1
    
    cast(... as unsigned)
    18446744073709551615
    
    cast(... as decimal(6,2))
    9999.99
    
    cast(-1 as unsigned)
    18446744073709551615
    
    1. 补充验证合法边界和负数 DECIMAL 溢出:
    select cast('9223372036854775807' as signed) as signed_max,
           cast('18446744073709551615' as unsigned) as unsigned_max;
    
    select cast('9999.994' as decimal(6,2)) as decimal_in_range,
           cast('-9999999.99' as decimal(6,2)) as decimal_negative_overflow;

    实际输出:

    signed_max            unsigned_max
    9223372036854775807   18446744073709551615
    
    decimal_in_range   decimal_negative_overflow
    9999.99            -9999.99
    
    1. 运行显式 CAST 专项单测,以下场景均通过:
    TestExplicitCastStringIntegerOverflow     PASS
    TestExplicitCastNegativeIntegerToUnsigned PASS
    TestExplicitCastStringDecimalOverflow     PASS
    

    测试结论

    最新 main 上,显式 CAST 的超大有符号整数、超大无符号整数、负数转无符号整数以及 DECIMAL 超范围场景,均已按 MySQL 兼容语义返回 wrap/clamp 结果,不再返回原 issue 中的 range error。合法 signed/unsigned 边界值保持不变,正负 DECIMAL 溢出均正确收敛到目标精度范围,原问题验证通过。

  10. Ariznawlll commented on Jul 21, 2026

    @Ariznawlll
    CollaboratorAuthor

    已补充 motr 黑盒回归测试:matrixorigin/motr#61。

    回归内容包括:

    • 超大字符串显式转换为 SIGNED/UNSIGNED 的 wrap 行为;
    • -1 显式转换为 UNSIGNED;
    • 正、负 DECIMAL 超范围时的 clamp 行为;
    • signed/unsigned 合法最大边界;
    • DECIMAL 正常舍入及舍入后触达上界;
    • 非法数字字符串仍返回明确错误,不被当作 overflow 处理。

    在 MatrixOne main@3046f14d9 上连续执行 3 轮,24/24 条 SQL 全部通过。该用例无全局状态修改,可在普通并行回归池执行,无需独占。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions