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
Casting a JSON value larger than 65,535 bytes to CHAR silently truncates it. The result may no longer be valid JSON. This can corrupt applications that extract a JSON column as text.
Reproduced with 8.0.30-MatrixOne-v4.2.8. The same SQL on MySQL 8.0.46 preserves the full value.
Minimal reproduction
SET @chunk = REPEAT('a', 10000);
SET @payload = CONCAT(@chunk, @chunk, @chunk, @chunk, @chunk,
@chunk, @chunk, @chunk, @chunk, @chunk);
SELECT LENGTH(@payload) AS input_bytes,
LENGTH(CAST(JSON_OBJECT('s', @payload) ASCHAR)) AS cast_bytes,
JSON_VALID(CAST(JSON_OBJECT('s', @payload) ASCHAR)) AS valid_json;
Actual MatrixOne output: 100000 | 65535 | 0.
MySQL 8.0.46 output: 100000 | 100009 | 1 (the JSON serializer includes a space after the colon). The expected behavior is to preserve the entire value and produce valid JSON, or report an explicit error if a limit applies, rather than silently return truncated data.
This also reproduces for a stored JSON column read over the MySQL protocol, not just the JSON_OBJECT expression.
Workaround
Consumers that can decode the protocol's native JSON value can select the JSON column directly instead of casting it to CHAR. JSON_UNQUOTE is not a general replacement when callers need the original JSON representation of scalar strings.
Administratively consolidated into #32336. The reproduction and acceptance criteria remain tracked there. This does not claim that the defect is fixed or that every consolidated case has the same root cause. Assignee metadata is unchanged.
Activity
MatrixAdventurer commentedon Nov 9, 2026
分级建议:
severity/s2 —— 超上限 JSON 经 CAST 提取落库被静默截断、无告警,正确性缺陷,但需 >64KB 负载且限于该提取写路径,触发面窄。
模块:pkg/sql/plan/function/operator/cast.go(CastFromJsonToChar)及目标文本列写入。
疑似重复:未发现同因;最接近 #31808 为长度上限边界类,不同缺陷。
建议负责人:matrix-meow(现 assignee);目录 CODEOWNERS 为 XuPeng-SH/aunjgr/aptend。
本操作由LW授权的MOI智能体提交
Ariznawlll commentedon Nov 9, 2026
结论
测试不通过。当前 main 对超过 64 KiB 的 JSON 转 CHAR 仍静默截断并产生无效 JSON,复现与本 issue 同根。
关键证据
main@c99234dcf4c94d1ff9d372917cd35041f1a3a682,隔离本地 CN,运行时git_version()为c99234dcf4。CAST(JSON_OBJECT('s', REPEAT('a',100000)) AS CHAR),输入字符串长度均为 100000,转换结果均为 65535 字节且JSON_VALID为 0。CAST(REPEAT('x',100000) AS CHAR)则返回 100000 字节。故此处观察到的是 JSON→CHAR 路径的独立限制/缺陷,不以普通字符串 CAST 结果替代 JSON 验收。待解决点
Ariznawlll commentedon Nov 9, 2026
结论
测试不通过。存储 JSON 列的直接协议读取保留完整值,但显式 JSON→CHAR 转换仍静默截断,与本 issue 同根。
关键证据
main@c99234dcf4c94d1ff9d372917cd35041f1a3a682,隔离本地 CN,运行时git_version()为c99234dcf4。JSON_OBJECT('s',REPEAT('a',100000))。直接 SELECT 通过 MySQL 协议解码后长度均为 100009 字节且JSON_VALID(j)=1;CAST(j AS CHAR)长度均为 65535 且JSON_VALID(...)=0。LENGTH(j)被 MO 明确拒绝(JSON 参数类型不支持 LENGTH),该尝试未纳入结果;改用明确的CAST(j AS CHAR)后得到上述重复结论。待解决点
test(plan): align omitted-length CHAR cast UTs with unbounded TEXT ta…
fix(sql): keep REVERSE and LEAST/GREATEST intact for TEXT cast results
test(function): align greatest JSON+date TEXT peer with its VARCHAR r…
fix(sql): keep string/numeric, temporal and EXTRACT paths for TEXT casts
fix(sql): keep timestampdiff string temporal paths for TEXT casts
fix(sql): keep operator rewrites and date-extraction string paths for…
fix(sql): keep signed INT64 coercion, DATE parsing and HEX encoding f…
test(dtype): align BIN/SPACE TEXT-column expectations with signed INT…
fix(sql): keep FLOAT64 domain of composed CEIL/FLOOR over omitted-len…
fix(sql): keep base numeric domains for all CEIL/FLOOR render composi…
fix(sql): keep omitted-CHAR CEIL/FLOOR numeric contract across query …
fix(sql): keep omitted-CHAR numeric contracts across set operations
fix(sql): keep ENUM order-key rewrite firing for untagged bind scopes
XuPeng-SH commentedon Nov 20, 2026
Administratively consolidated into #32336. The reproduction and acceptance criteria remain tracked there. This does not claim that the defect is fixed or that every consolidated case has the same root cause. Assignee metadata is unchanged.