Skip to content

[Bug]: CHAR_LENGTH over binary string counts characters instead of bytes #25295

Closed

Description

@Ariznawlll

Environment

  • Branch: latest main
  • Commit tested locally: 200bfa7e0efb (fix: improve skills SKILL.md compatibility format (#25271))
  • MySQL oracle: local MySQL 8.x via mysql -u root -p...
  • MO: 8.0.30-MatrixOne-v1.3.0

Steps to Reproduce

select length(_binary '你好') as byte_len,
       char_length(_binary '你好') as char_len;

MySQL Result

byte_len  char_len
6         6

For a binary string, MySQL counts bytes for CHAR_LENGTH().

MatrixOne Result

byte_len  char_len
6         2

MatrixOne appears to count Unicode characters even though the literal is explicitly _binary.

Expected Behavior

For binary strings, CHAR_LENGTH() / CHARACTER_LENGTH() should match MySQL and count bytes, not decoded characters.

Notes

Found during active MySQL compatibility exploration, Module 4: String / Charset / Collation. I searched existing issues for CHAR_LENGTH binary and did not find a duplicate.

Activity

  1. added
    kind/bug
    severity/s1
    on Jul 1, 2026
  2. added
    severity/s0
    and removed
    severity/s1
    on Jul 2, 2026
  3. added this to the MO-202607 milestone on Jul 2, 2026
  4. added theissue type on Jul 2, 2026
  5. added and removed
    severity/s0
    on Jul 2, 2026
  6. added
    severity/s0
    and removed on Jul 31, 2026
  7. removed their assignment
    on Jul 31, 2026
  8. 2 remaining items

  9. added
    severity/s1
    and removed
    severity/s0
    on Aug 23, 2026
  10. assigned and unassigned on Sep 29, 2026
  11. slyunnn commented on Oct 8, 2026

    @slyunnn

    Regression and extended verification for #25295 (2026-10-08)

    Verification Environment

    • Tested fetched origin/main commit dce60631f8c857ae730a4d2f328df5962e4f2a8d: test(morpc): synchronize client gc tests (#29674).
    • Built locally with Go 1.27.0 on Linux/ARM64. The isolated services started after the build; binary version reports this commit. Binary SHA-256: a97882ce4eb6a5247c91965abebdbc427976e318762651f9bd2c726d6c7e302e.
    • Topology: 2 CN / 1 TN / 1 Log service / Proxy, using fresh isolated local-disk storage.
    • All three endpoints were reachable and executed the regression: Proxy 127.0.0.1:6641 (container 6009), CN1 127.0.0.1:16641 (container 16001), CN2 127.0.0.1:16642 (container 16002). Alternate host ports avoid existing services; this was not a test of the pre-existing 6001/16001/16002 deployment.
    • Client: MySQL CLI over TCP, utf8mb4, text protocol COM_QUERY, including SQL-level PREPARE / EXECUTE.

    What Was Covered

    • OK — Original _binary '你好': LENGTH, CHAR_LENGTH, and CHARACTER_LENGTH return 6 on all endpoints.
    • OK — Previously failing comment scenario X'e4bda0': all three functions return 3, not 1, on all endpoints.
    • OK — Text control '你好': byte length 6, character lengths 2.
    • OK — Empty binary string, ASCII, NULL, embedded zero and invalid UTF-8 bytes; X'ff00e4bda0' has character length 5 under binary semantics.
    • OK — CAST(... AS BINARY), BINARY operator, binary CONCAT and REPEAT preserve byte-count behavior.
    • OK — Persisted BINARY(8), VARBINARY(8), BLOB, and VARCHAR(8) values: lengths 8/6/6/2 for the Chinese input; fixed-width zero padding, empty values and NULL behave as expected.
    • OK — SQL prepared execution with binary then text user variables returns 3/3 then 1/1 for CHAR_LENGTH / CHARACTER_LENGTH.
    • OK — Invalid arity CHAR_LENGTH() returns error 20203; a subsequent statement on the same connection succeeds on every endpoint.
    • Not covered — Binary-protocol COM_STMT_PREPARE / COM_STMT_EXECUTE, independent live MySQL oracle execution, full BVT-suite replay, and forced distributed parallel plans. These are not required to reproduce this issue's reported literal/column semantics.

    Findings

    • Both the original report and the later hex-literal failure are no longer reproducible on the tested main commit.
    • Related merged fixes, both contained in the tested commit:
    • An initial fixture attempted table creation in the protected mysql database and was rejected. The complete checks were rerun successfully in separate issue-specific databases; that fixture failure is not attributed to this issue.

    MOTR / BVT Coverage

    • Existing test/distributed/cases/function/func_string_char_length.test covers the exact _binary reproduction and BINARY / VARBINARY / BLOB columns.
    • Existing test/distributed/cases/dtype/binary_string_function_semantics.test covers hex-literal length, binary expressions, invalid bytes, and prepared/domain propagation.
    • No duplicate MOTR case, new commit, or PR was created. Existing BVT files were inspected; this run used targeted SQL checks with explicit expected-output comparison, not a full BVT runner replay.
    • Endpoint checks ran concurrently with separate databases; dependent statements within each connection ran sequentially. This is test-client parallelism, not a claim of engine-parallel execution coverage.

    Final Conclusion

    Fixed on dce60631f8c857ae730a4d2f328df5962e4f2a8d for the original reproduction and the subsequently reported hex-literal case, verified through Proxy and both CNs.

    Large-data regression is not needed: the defect concerns binary-versus-text length semantics, not row count, block/batch boundaries, spill, or resource scale. Small explicit byte sequences exercise the relevant boundary without unnecessary CI cost.

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions