Skip to content

[Compatibility]: string position and count functions reject MySQL numeric-prefix arguments #28396

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

No issue was found for numeric position/count arguments across the string-function family. Existing numeric-prefix issues cover bitwise operators, CONV/BIN, or SHA2 rather than string positions and lengths.

Branch Name

main

Commit ID

f72ca9efbeb3a7c673701e4a135cc6670c33cfde

Other Environment Information

  • Local standalone MatrixOne
  • Reference: MySQL 8.3.0

Actual Behavior

MatrixOne applies a strict character-to-integer cast to string-function position, length, count, index, and bitmask arguments. MySQL consumes a valid leading numeric prefix and converts a character value without a numeric prefix to zero.

The difference affects all 15 tested call shapes:

SELECT LEFT('abcdef','2tail'), RIGHT('abcdef','2tail');
SELECT SUBSTRING('abcdef','2tail'), SUBSTRING('abcdef',2,'2tail');
SELECT INSERT('abcdef','2tail','2tail','X');
SELECT LOCATE('a','banana','2tail');
SELECT REPEAT('x','3tail'), LENGTH(SPACE('3tail'));
SELECT LPAD('x','3tail','0'), RPAD('x','3tail','0');
SELECT SUBSTRING_INDEX('a,b,c',',','2tail');
SELECT ELT('2tail','a','b');
SELECT MAKE_SET('3tail','a','b');
SELECT EXPORT_SET(5,'Y','N',',','3tail');

MatrixOne aborts each statement with an error such as:

invalid argument cast to int, bad value 2tail

MySQL uses the leading 2/3 and returns the corresponding substring, position, repetition, padding, selected item, set, or exported bits. For example:

LEFT('abcdef','2tail')                  -> ab
SUBSTRING('abcdef',2,'2tail')           -> bc
INSERT('abcdef','2tail',2,'X')          -> aXdef
REPEAT('x','3tail')                     -> xxx
LPAD('x','3tail','0')                   -> 00x
ELT('2tail','a','b')                    -> b
MAKE_SET('3tail','a','b')               -> a,b
EXPORT_SET(5,'Y','N',',','3tail')       -> Y,N,Y

Replacing the numeric-prefix value with 'abc' or the empty string also raises a MatrixOne cast error. MySQL converts those values to zero and returns the function-specific zero result, such as an empty string for LEFT/REPEAT/LPAD, the unchanged source for zero-position INSERT, and NULL for ELT(0,...).

The same behavior occurs with a VARCHAR column and with values bound through the MySQL binary protocol. Every constant form was repeated three times.

Expected Behavior

Numeric argument coercion for these MySQL-compatible string functions should consume a leading numeric prefix and convert character values with no numeric prefix to zero. The converted integer should then be passed to each function's existing position/length/count logic.

Steps to Reproduce

CREATE DATABASE codex_string_numeric_args;
USE codex_string_numeric_args;
CREATE TABLE t(n VARCHAR(20));
INSERT INTO t VALUES ('2'),('2tail'),('abc'),(''),(NULL);

SELECT n, LEFT('abcdef',n) FROM t ORDER BY n IS NULL,n;
SELECT n, INSERT('abcdef',n,n,'X') FROM t ORDER BY n IS NULL,n;
SELECT n, ELT(n,'a','b') FROM t ORDER BY n IS NULL,n;
SELECT n, MAKE_SET(n,'a','b') FROM t ORDER BY n IS NULL,n;

Controls

  • Integer arguments produce the same results in both engines.
  • Pure numeric strings such as '2' and '3' produce the same results.
  • NULL remains NULL.
  • The ordinary boundary behavior after successful conversion (zero, negative, and out-of-range positions/counts) was checked separately and agrees with MySQL for the tested functions.

Activity

  1. added this to the MO-202609 milestone on Sep 8, 2026
  2. added theissue type on Sep 8, 2026
  3. self-assigned this
    on Sep 8, 2026
  4. added a commit that references this issue on Sep 8, 2026
    b7eca64
  5. Ariznawlll commented on Sep 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:a9d3b8b857c44f1249e682c91d4d62a914eb7d20
    • 环境:本地单机 MatrixOne,2026-09-09。

    原问题验证

    验证数值前缀到字符串的转换被 12 个相关字符串函数一致支持。

    Happy Path 覆盖

    • 12 个函数均验证数字前缀输入的结果;
    • 表列和 prepared statement 路径均通过,连续 3 轮一致。

    Unhappy Path 覆盖

    • abc、空字符串走 zero conversion 控制路径;
    • NULL 保持 NULL,验证没有把缺失值错误转换为文本或数值。

    白盒验证

    不适用:以函数族的黑盒输出验证公共转换行为。

    回归测试

    • 已加入 MOTR PR #152:suites/14_issue_regression/t/issue_28395_28400_28396_string_numeric_coercion.test。
    • --record --repeat 3 和非 record --repeat 3 均通过;PR 共 21/21 用例、321/321 条语句成功。

    测试证据

    12 个函数、表列、prepared 与 zero/NULL 边界均重复 3 次。

    测试结论

    测试通过。

  6. added 3 commits that reference this issue on Sep 17, 2026
    f570367
    4ad1fa4
    d573c81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions