You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: CHAR_LENGTH over binary string counts characters instead of bytes #25295
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.
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.
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.
Activity
fix: count binary char length in bytes (#26488)
2 remaining items
fix: add binary string metadata foundation (#26906)
fix: count binary char length in bytes (matrixorigin#26488)
fix: add binary string metadata foundation (matrixorigin#26906)
fix: count binary char length in bytes (matrixorigin#26488)
fix: add binary string metadata foundation (matrixorigin#26906)
fix: count binary char length in bytes (matrixorigin#26488)
fix: add binary string metadata foundation (matrixorigin#26906)
slyunnn commentedon Oct 8, 2026
Regression and extended verification for #25295 (2026-10-08)
Verification Environment
origin/maincommitdce60631f8c857ae730a4d2f328df5962e4f2a8d:test(morpc): synchronize client gc tests (#29674).1.27.0on Linux/ARM64. The isolated services started after the build; binary version reports this commit. Binary SHA-256:a97882ce4eb6a5247c91965abebdbc427976e318762651f9bd2c726d6c7e302e.2 CN / 1 TN / 1 Log service / Proxy, using fresh isolated local-disk storage.127.0.0.1:6641(container6009), CN1127.0.0.1:16641(container16001), CN2127.0.0.1:16642(container16002). Alternate host ports avoid existing services; this was not a test of the pre-existing6001/16001/16002deployment.utf8mb4, text protocolCOM_QUERY, including SQL-levelPREPARE/EXECUTE.What Was Covered
_binary '你好':LENGTH,CHAR_LENGTH, andCHARACTER_LENGTHreturn6on all endpoints.X'e4bda0': all three functions return3, not1, on all endpoints.'你好': byte length6, character lengths2.NULL, embedded zero and invalid UTF-8 bytes;X'ff00e4bda0'has character length5under binary semantics.CAST(... AS BINARY),BINARYoperator, binaryCONCATandREPEATpreserve byte-count behavior.BINARY(8),VARBINARY(8),BLOB, andVARCHAR(8)values: lengths8/6/6/2for the Chinese input; fixed-width zero padding, empty values andNULLbehave as expected.3/3then1/1forCHAR_LENGTH/CHARACTER_LENGTH.CHAR_LENGTH()returns error20203; a subsequent statement on the same connection succeeds on every endpoint.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
60e36bef641e7bf918c64bf44fe481b8bdf016c1: binary byte-count handling.d3e8aced873a96aeb45078177d4aa04fe47c7303: binary-string function semantics and domain propagation.mysqldatabase 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
test/distributed/cases/function/func_string_char_length.testcovers the exact_binaryreproduction andBINARY/VARBINARY/BLOBcolumns.test/distributed/cases/dtype/binary_string_function_semantics.testcovers hex-literal length, binary expressions, invalid bytes, and prepared/domain propagation.Final Conclusion
Fixed on
dce60631f8c857ae730a4d2f328df5962e4f2a8dfor 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.