Repository navigation
Description
Description
LENGTH(), CHAR_LENGTH(), and OCTET_LENGTH() error out on a BIT column with invalid argument function length, bad value [BIT], while MySQL returns the byte/char count of the BIT value. Notably the same functions work on a BIT literal, and other functions (HEX, arithmetic) work on the column — so the column's type is not routed through the string-coercion path that literals and other types use.
Environment
- MatrixOne dev build (local multi-CN,
main) - MySQL 8.0.45 control
Reproduction
CREATE TABLE bt2 (b BIT(8));
INSERT INTO bt2 VALUES (b'11111111');| Expression | MO | MySQL 8.0.45 |
|---|---|---|
SELECT LENGTH(b) FROM bt2 |
ERROR 20203 invalid argument function length, bad value [BIT] |
1 |
SELECT CHAR_LENGTH(b) FROM bt2 |
ERROR 20203 invalid argument function char_length, bad value [BIT] |
1 |
SELECT OCTET_LENGTH(b) FROM bt2 |
ERROR 20203 invalid argument function octet_length, bad value [BIT] |
1 |
SELECT HEX(b) FROM bt2 |
FF ✓ |
FF |
SELECT b+0 FROM bt2 |
255 ✓ |
255 |
The inconsistency: literals work, columns don't
SELECT LENGTH(b'101'); -- MO: 1 ✓ (same as MySQL)
SELECT LENGTH(b); -- via column: ERRORSo LENGTH accepts a BIT literal but rejects a BIT column. Whatever coercion path the literal takes is not applied when the argument is a typed column reference — which suggests the function's type-matching only consults the literal's inferred type, not the BIT column type.
Impact
- Schema-introspection / data-dictionary queries fail outright. It is common to size a column with
MAX(LENGTH(col))orSUM(LENGTH(col)); over a BIT column (flags, permission bitmasks, legacy boolean packs) that query errors and cannot be worked around without casting every column name. - Generic tooling breaks. ORMs and BI tools that measure string width use
LENGTH/CHAR_LENGTHfrominformation_schemametadata; a BIT column makes the whole profiling query fail rather than returning one column's value. CAST(b AS CHAR)returns a raw byte, not a readable string:SELECT CAST(b AS CHAR) FROM bt2yields a single unprintable0xFFbyte rather than MySQL's behaviour, so the intended workaround also produces unusable output.- Because the same query works on MySQL, a migrated schema with BIT columns turns previously-working health-check and profiling SQL into hard errors.
Expected behavior
LENGTH/CHAR_LENGTH/OCTET_LENGTH on a BIT column should coerce the value to its binary string form and return its width, matching MySQL and matching the already-working literal path:
SELECT LENGTH(b) FROM bt2; -- 1
SELECT CHAR_LENGTH(b) FROM bt2; -- 1
SELECT OCTET_LENGTH(b) FROM bt2; -- 1More generally, BIT columns should participate in the same implicit string/numeric coercion matrix as other types, rather than raising a hard "bad value [BIT]" error in string functions.
Activity
gouhongshen commentedon Nov 3, 2026
PR #32103 is trying to fix this issue.
fix(plan): support LENGTH/OCTET_LENGTH/CHAR_LENGTH on BIT columns (#3…
gouhongshen commentedon Nov 3, 2026
PR #32103 has merged and is awaiting manual validation. The issue remains open.
XuPeng-SH commentedon Nov 4, 2026
QA handoff after #32103 merged into main (
a7aed8b70ff5ee012d7c631f94b1d47f594876e7). Native BIT overloads for LENGTH/OCTET_LENGTH/CHAR_LENGTH/CHARACTER_LENGTH return ceil(M/8), preserve declared width and propagate NULL.Author reports the complete function package and 204/204 changed BVT statements passing; the final reviewer reused author/CI evidence rather than executing the SQL suite locally. This handoff run performed only remote review and no local tests.
Please verify BIT widths 1/8/9/16/64, zero/leading-zero/max values, NULLs, aggregates, literals and non-BIT controls. Scope is the reported LENGTH-family behavior, not all BIT coercions. The unsupported invalid-width metadata fallback has no demonstrated supported SQL producer and is not asserted covered. QA acceptance remains pending.
Ariznawlll commentedon Nov 5, 2026
结论
测试通过。LENGTH 系列函数接受 BIT 列,并按声明宽度返回字节数。
关键证据
main@80224b0314c6008ecb4de82d1e37b019d5e355df,隔离本地 2 CN / 1 TN / 1 LogService / Proxy;三个入口的git_version()均为该提交。待解决点
无。本次验证 LENGTH 系列,不将结论扩展到全部 BIT 字符串转换。