Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
#27573 covers empty subjects, #25299 covers binary operands, and #27217 covers dynamic parameter provenance. None covers utf8mb4 character positions.
Branch Name
main
Commit ID
e7bb0572235ec4bac81eb098eb0ad8900f0065ab
Other Environment Information
- Deployment: local standalone MatrixOne, 1 CN / 1 TN / 1 Log service
- Client: MySQL text protocol
- Reference: MySQL 8.3.0
Actual Behavior
The positional REGEXP functions interpret utf8mb4 strings as byte arrays instead of character sequences.
SELECT REGEXP_INSTR('甲😀乙😀丙', '😀');
-- MatrixOne: 4
-- MySQL: 2
SELECT REGEXP_INSTR('甲😀乙😀丙', '😀', 1, 2, 0);
-- MatrixOne: 11
-- MySQL: 4
SELECT REGEXP_INSTR('甲😀乙😀丙', '😀', 1, 2, 1);
-- MatrixOne: 15
-- MySQL: 5The same byte/character mismatch affects the input pos argument. Position 3 is the 乙 character, so the search must skip the first emoji. MatrixOne starts at byte offset 2 and still selects or replaces the first emoji:
SELECT REGEXP_SUBSTR('甲😀乙😀丙', '😀', 3, 1);
-- MatrixOne: first emoji (character 2)
-- MySQL: second emoji (character 4)
SELECT REGEXP_REPLACE('甲😀乙😀丙', '😀', 'X', 3, 1);
-- MatrixOne: 甲X乙😀丙
-- MySQL: 甲😀乙X丙The behavior is identical for constants and values read from a VARCHAR column, and was reproduced three times.
Expected Behavior
For nonbinary utf8mb4 strings, pos, start positions, and end positions must be one-based character positions, matching MySQL. Byte offsets must not leak into SQL-visible REGEXP positions.
MySQL reference: https://dev.mysql.com/doc/refman/8.4/en/regexp.html#function_regexp-instr
Steps to Reproduce
CREATE DATABASE regexp_utf8_probe;
USE regexp_utf8_probe;
CREATE TABLE t (id INT PRIMARY KEY, s VARCHAR(40));
INSERT INTO t VALUES (1, '甲😀乙😀丙');
SELECT REGEXP_INSTR(s, '😀'),
REGEXP_INSTR(s, '😀', 1, 2, 0),
REGEXP_INSTR(s, '😀', 1, 2, 1),
REGEXP_INSTR(s, '😀', 3, 1, 0)
FROM t;
SELECT REGEXP_SUBSTR(s, '😀', 3, 1),
REGEXP_REPLACE(s, '😀', 'X', 3, 1)
FROM t;Additional information
regexpSet.regularInstr validates pos against len(str), slices with str[pos-1:], and returns indexes from Go's regexp engine directly. All three operations are byte-based. The substring and replacement helpers use the same byte-index approach for their positional arguments.
Activity
fix(sql): align ORD, BIT_COUNT and REGEXP UTF-8 semantics (#28267)
Ariznawlll commentedon Sep 7, 2026
测试版本
mainbcd5ed833b5400fe95f322e4028adb2bde3de0a46001原问题验证
甲😀乙😀丙,执行REGEXP_INSTR的首次匹配、第二次匹配、指定起始位置和 end 参数场景。REGEXP_SUBSTR与REGEXP_REPLACE,核对字符位置而非 UTF-8 字节位置。Happy Path 覆盖
REGEXP_INSTR返回2、4、5、4,第二个 emoji 的字符区间正确。REGEXP_SUBSTR返回😀;从第 3 个字符开始替换一次得到甲😀乙X丙。Unhappy Path 覆盖
白盒验证
不适用。本轮验证公开 REGEXP SQL 接口,未使用内部故障注入。
回归测试
已加入 MOTR PR #145:
suites/14_issue_regression/t/issue_28202_regexp_utf8_positions.test。测试证据
stmts=24 ok=24 fail=0。测试结论
测试通过。
fix(sql): align ORD, BIT_COUNT and REGEXP UTF-8 semantics (matrixorig…
fix(sql): align ORD, BIT_COUNT and REGEXP UTF-8 semantics (matrixorig…
fix(sql): align ORD, BIT_COUNT and REGEXP UTF-8 semantics (matrixorig…