Skip to content

[Bug]: ORD reverses the byte order of multibyte characters #28207

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

#22941 and #22997 were closed feature requests from before ORD() was implemented. No issue covers the implemented function's multibyte result.

Branch Name

main

Commit ID

e7bb0572235ec4bac81eb098eb0ad8900f0065ab

Other Environment Information

  • Local standalone MatrixOne; MySQL text protocol
  • Reference: MySQL 8.3.0

Actual Behavior

ORD() assembles the UTF-8 bytes of the first character in little-endian order. MySQL defines the result in left-to-right (big-endian) byte order.

SELECT HEX('é'), ORD('é');
-- MatrixOne: C3A9, 43459     (0xA9C3)
-- MySQL:    C3A9, 50089     (0xC3A9)

SELECT HEX('中'), ORD('中');
-- MatrixOne: E4B8AD, 11385060  (0xADB8E4)
-- MySQL:    E4B8AD, 14989485  (0xE4B8AD)

SELECT HEX('😀'), ORD('😀');
-- MatrixOne: F09F9880, 2157486064  (0x80989FF0)
-- MySQL:    F09F9880, 4036991104  (0xF09F9880)

Constants and VARCHAR column values produce the same wrong values; all cases were reproduced three times.

Expected Behavior

The first character's bytes must be combined in MySQL order. For bytes b1 ... bn, the result is b1 * 256^(n-1) + ... + bn.

Steps to Reproduce

SELECT HEX('é'), ORD('é');
SELECT HEX('中'), ORD('中');
SELECT HEX('😀'), ORD('😀');

Additional information

OrdString currently multiplies byte i by 1 << (8*i), which reverses every multibyte character.

Activity

  1. added this to the MO-202609 milestone on Sep 5, 2026
  2. added
    kind/bug
    on Sep 5, 2026
  3. added theissue type on Sep 5, 2026
  4. self-assigned this
    on Sep 5, 2026
  5. added
    severity/s0
    and removed on Sep 5, 2026
  6. added a commit that references this issue on Sep 6, 2026
    e60b3eb
  7. Ariznawlll commented on Sep 7, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:bcd5ed833b5400fe95f322e4028adb2bde3de0a4
    • 部署方式:本地 standalone MatrixOne,MySQL 协议端口 6001
    • 测试日期:2026-09-07

    原问题验证

    1. 创建包含 é、中、😀 的表,分别执行 HEX 和 ORD。
    2. 通过表列再次执行 ORD,检查 2/3/4 字节 UTF-8 字符的返回值。
    3. 连续执行 3 轮,每轮结束删除测试数据库。

    Happy Path 覆盖

    1. é、中、😀 的 HEX 分别为 C3A9、E4B8AD、F09F9880;ORD 分别为 50089、14989485、4036991104。
    2. 表列读取返回三行 1/50089、2/14989485、3/4036991104,结果与字面量一致。

    Unhappy Path 覆盖

    1. 使用多字节字符作为边界输入验证字节序计算;3/3 轮均无错误、无截断或错误字符位置。
    2. 每轮执行连接健康检查并完成数据库清理,未观察到会话异常或残留对象。

    白盒验证

    不适用。本轮验证公开 SQL 标量函数行为,未使用内部故障注入。

    回归测试

    已加入 MOTR PR #145:suites/14_issue_regression/t/issue_28207_ord_utf8.test。

    测试证据

    测试结论

    测试通过。

  8. added 3 commits that reference this issue on Sep 17, 2026
    e6856c5
    4f8668e
    83bf44b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions