Skip to content

[Bug]: hex-like ordinary strings cast to numeric as hex values instead of MySQL zero #25265

Open

Description

@Ariznawlll

Bug Report

MatrixOne Version

Latest origin/main verified locally at 33e96877604ad4b847ea7d5c55eb09429de1a5b6.

Reproduce Steps

select cast('0x10' as unsigned),
       cast('0x10' as signed),
       cast('0x10' as decimal(6,0));

Expected Behavior

MySQL treats '0x10' as an ordinary string in decimal numeric conversion, stops at x, and returns zero with warnings:

0    0    0

Actual Behavior

MatrixOne parses the string as a hexadecimal number:

16    16    16

Notes

Found during Batch A of the MySQL compatibility CAST / CONVERT matrix. These rows were excluded from passing BVT.

Activity

  1. added
    kind/bug
    severity/s1
    on Jun 30, 2026
  2. added this to the MO-202607 milestone on Jul 1, 2026
  3. added theissue type on Jul 1, 2026
  4. added
    ai-light
    on Jul 1, 2026
  5. daviszhen commented on Jul 3, 2026

    @daviszhen
    Contributor

    初步建议[保持 mo目前的行为. "0x1234"作为16进制字符串看待.

    postgresql 与mo的行为类似

    Image
  6. added
    severity/s0
    and removed
    severity/s1
    on Jul 6, 2026
  7. added a commit that references this issue on Jul 7, 2026
  8. daviszhen commented on Jul 7, 2026

    @daviszhen
    Contributor

    修改了行为

  9. Ariznawlll commented on Jul 8, 2026

    @Ariznawlll
    CollaboratorAuthor

    Verified on latest main.

    Build tested:

    Validation SQL and result:

    select cast('0x10' as unsigned) as hex_unsigned,
           cast('0x10' as signed) as hex_signed,
           cast('0x10' as decimal(6,0)) as hex_decimal;
    
    -- result
    -- hex_unsigned | hex_signed | hex_decimal
    -- 16           | 16         | 16
    
    select cast('0b1010' as unsigned) as bin_unsigned,
           cast('0o17' as signed) as oct_signed,
           cast('0123' as signed) as leading_zero_decimal;
    
    -- result
    -- bin_unsigned | oct_signed | leading_zero_decimal
    -- 10           | 15         | 123
    
    select cast('+0b1010' as decimal(6,2)) as plus_bin_decimal,
           cast('+0o17' as decimal(6,2)) as plus_oct_decimal,
           cast('+0x123' as decimal(6,2)) as plus_hex_decimal;
    
    -- result
    -- plus_bin_decimal | plus_oct_decimal | plus_hex_decimal
    -- 10.00            | 15.00            | 291.00

    Conclusion:

    • Latest main keeps/extends MO's radix-string behavior: 0x, 0o, and 0b prefixed strings are parsed as hexadecimal/octal/binary numeric strings.
    • This matches the behavior implemented by fix cast digital string #25449, but it is intentionally different from MySQL's ordinary-string conversion behavior where '0x10' returns 0 with warnings.

    Added motr regression coverage in matrixorigin/motr#39:

    • suites/14_issue_regression/t/issue_25265_cast_radix_strings.test
    • suites/14_issue_regression/r/issue_25265_cast_radix_strings.result

    motr validation:

    [ISSUE_25265_CAST_RADIX_STRINGS] success | stmts=3 ok=3 fail=0
    
  10. 1 remaining item

  11. Ariznawlll commented on Oct 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    Regression on current main nightly — the fix no longer holds

    Re-verified on the latest nightly build b14d67a (docker registry.cn-shanghai.aliyuncs.com/matrixorigin/matrixone:nightly-b14d67a2-arm64, built 2026-10-26; standalone, single CN). The three cases from this issue's description, which the fix PR #25449 resolved at merge time (my verification comment above, on ec01c62e4), all return hex-parsed values again:

    statement at fix verification (ec01c62e4) now, nightly b14d67a MySQL 8.0 (official image, verified today)
    SELECT CAST('0x10' AS UNSIGNED) 0 16 0
    SELECT CAST('0x10' AS SIGNED) 0 16 0
    SELECT CAST('0x10' AS DECIMAL(6,0)) 0 16 0

    And the same hex-parsing leaks through every implicit path beyond the original CAST scope:

    statement MO nightly b14d67a MySQL 8.0 (verified)
    SELECT '0x10' + 0 16 0.0
    SELECT '0xff' + 0 255 0.0
    SELECT '0deadbeef' + 0 → '0xdeadbeef' 3735928559 0.0
    SELECT '0b101' + 0 (binary prefix too) 5 0.0
    SELECT '0x10' = 16 1 0
    SELECT '0x10' > 15 1 0

    Most dangerous real-world shape — a row-filter accept that MySQL would reject:

    -- varchar column containing mixed codes
    SELECT COUNT(*) FROM (SELECT '0x10' x UNION ALL SELECT '20') t WHERE x > 15;
    -- MO b14d67a: 2   ('0x10' parsed as 16 > 15, row admitted)
    -- MySQL 8.0: 1   ('0x10' coerces to 0, row rejected)

    For comparison, a genuinely invalid hex string errors instead of coercing — so the current behavior is neither MySQL-compatible nor internally consistent:

    SELECT '0xzz' + 0;   -- ERROR 20203 (cast to int, bad value) on MO; MySQL: 0.0

    Suggest re-opening: the regression window is somewhere between ec01c62e4 (fix verified) and b14d67a (current nightly). A BVT row for '0x10'-style strings in numeric contexts (CAST, arithmetic, comparison, and column-filter) with a MySQL-8 control would pin all four paths and prevent the next regression.

    Related same-day findings in the string→numeric coercion family: '1e2'+0, ' 12abc'+0, ' +3.5'+0, '1,234.5'+0, ''+5 all error with 20203 on b14d67a where MySQL coerces leniently (prefix-parse or 0) — tracked in #30730's comment thread.

  12. removed
    kind/bug
    on Oct 28, 2026
  13. Ariznawlll commented on Nov 4, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。按 Issue 所要求的 MySQL 普通字符串转数值语义,最新 main 仍将带进制前缀的字符串按进制解析,并会在过滤条件中产生不同结果。

    关键证据

    • 2026-11-04 官方 main@0f6c07639604c40d7ca880cb63d1d282239def08,本地独立 1 Log / 1 TN / 2 CN;对照为独立 MySQL 8.0.45。以下每组在两个 CN 和 MySQL 各重复 3 次,结果一致。
    • 原始 SQL SELECT CAST('0x10' AS UNSIGNED), CAST('0x10' AS SIGNED), CAST('0x10' AS DECIMAL(6,0)):MO 为 (16,16,16),MySQL 为 (0,0,0)。普通十进制 123 和 -7 转换在两端一致。
    • 扩展路径:'0x10'+0、'0xff'+0、'0b101'+0 在 MO 为 16/255/5,MySQL 均为 0;'0x10'=16 在 MO 为 1、MySQL 为 0。混合 '0x10' 和 '20' 的行过滤 x>15 在 MO 计数 2、MySQL 计数 1;'0xzz'+0 在 MO 报 20203、MySQL 返回 0。
    • Issue 的历史评论对这类行为是预期差异还是回归有不一致表述;本轮只确认最新 main 与 Issue 声明的 MySQL 预期不同,不据此判断引入时间或产品兼容性策略。

    待解决点

    • 请研发确认普通字符串的进制前缀兼容性合同并处理 CAST、算术、比较和过滤路径;修复后覆盖无效前缀及错误后的会话状态。已有 MOTR 对当前行为的历史预期不能直接当作 MySQL 兼容验收依据。
  14. XuPeng-SH commented on Nov 30, 2026

    @XuPeng-SH
    Contributor

    Consolidated duplicate #31353 here as the same quoted-string radix coercion defect.

    Additional acceptance coverage retained:

    • '0xff' + 0, '0x10' + 0, and '0b101' + 0 must use MySQL's ordinary-string numeric-prefix semantics rather than hexadecimal/binary interpretation.
    • Arithmetic and equality forms such as '0x10' = 16 and '0b101' = 5 must agree with MySQL.
    • Unquoted 0xff, 0x41, X'41', and B'..' literal forms remain independent controls; their valid literal behavior must not be broken.
    • Preserve the existing CAST, +0, comparison, and row-filter cases already recorded here.

    Administrative consolidation only; the quoted-string coercion defect remains open and is not fixed or QA-verified.

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

Metadata

Metadata

Assignees

Labels

ai-lightseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions