Skip to content

[Compatibility]: JSON constructors drop MySQL binary type tags for binary, BLOB, and BIT values #28057

Closed

Description

@Ariznawlll

Description

MatrixOne JSON constructors encode binary-like SQL values as bare Base64 strings. MySQL 8 encodes the same values as base64:type<field-type>:<payload>, preserving the original SQL type in the JSON value. The lost tag changes JSON text, equality, and values returned through JSON_EXTRACT/JSON_UNQUOTE.

Environment

  • Branch: main
  • Commit: 95d04586eb80864499d0fde27aeb912b463ae4cd
  • Deployment: local single-CN MatrixOne

Steps to reproduce

CREATE TABLE t (
  id INT PRIMARY KEY,
  vb VARBINARY(8),
  bl BLOB,
  bits BIT(4)
);
INSERT INTO t VALUES (1, X'00FF41', X'00FF41', b'1010');

SELECT
  JSON_UNQUOTE(JSON_EXTRACT(JSON_ARRAY(vb, bl, bits), '$[0]')),
  JSON_UNQUOTE(JSON_EXTRACT(JSON_ARRAY(vb, bl, bits), '$[1]')),
  JSON_UNQUOTE(JSON_EXTRACT(JSON_ARRAY(vb, bl, bits), '$[2]'))
FROM t;

Actual behavior

MatrixOne returns:

AP9B | AP9B | Cg==

MySQL 8 returns:

base64:type15:AP9B | base64:type252:AP9B | base64:type16:Cg==

The same difference occurs through JSON_OBJECT and JSON_SET.

Expected behavior

For MySQL compatibility, JSON constructors should preserve the binary source type in the JSON text using MySQL's base64:type<field-type>: representation.

Stability and controls

  • Reproducer: 3/3 on MatrixOne main for JSON_ARRAY and JSON_SET.
  • JSON_OBJECT reproduces the same values for VARBINARY, BLOB, and BIT.
  • MySQL 8 control consistently distinguishes field types 15, 252, and 16 for the identical input bytes.
  • Printable text inputs are handled as ordinary JSON strings; this difference is specific to binary-like SQL types.

Code analysis

pkg/sql/plan/function/func_builtin_json.go routes BINARY, VARBINARY, and BLOB through a single TpCodeOpaque representation before JSON creation. This discards the source type needed for MySQL-compatible output; BIT follows its own typed path but also emits bare Base64.

Regression coverage

After a fix, add deterministic coverage for BINARY/VARBINARY, BLOB, and BIT through JSON_OBJECT, JSON_ARRAY, and JSON_SET, including a non-UTF-8 payload.

Activity

  1. added this to the MO-202609 milestone on Sep 3, 2026
  2. added
    kind/bug
    on Sep 3, 2026
  3. added theissue type on Sep 3, 2026
  4. added
    severity/s1
    and removed on Sep 8, 2026
  5. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    【QA 交接|PR #28093 已合并】

    关联合并:PR #28093(merge commit 8836fb4);当前 main=1cfec4c80134adc5640a3bbf1aef7aaa87a45282。

    本次范围:JSON 构造函数对 BINARY、VARBINARY、BLOB、BIT 的 MySQL binary type tag、prepared metadata/protocol 及 NULL/nonmatch/大数组行为;同时复验 binary MEMBER OF 的具体 subtype conversion。

    合并后证据:PR required checks 无失败;本地 exact-main CGo 自测因缺少 cgo/libmo.dylib 阻塞,mo-tester 未安装,未宣称本地 PASS。

    请在合并版本覆盖常量、预编译参数、重绑定、CAST/JSON 构造差异、单 CN 与多 CN、重启/读回。PASS 标准是 JSON 类型标签、字节值和 MySQL 8 一致;FAIL 时请保留 SQL、main SHA、重复轮次和实际/期望结果。

  6. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    补充 pin:远端 main 已推进到 9f87b62。请以该当前 main 复验;此前列出的合并提交、测试范围和 PASS/FAIL 标准保持不变。该更新不代表 QA PASS。

  7. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    再次补充 pin:远端 main 已推进到 9cedf6e。请以该当前 main 复验;此前列出的合并提交、测试范围和 PASS/FAIL 标准保持不变。该更新不代表 QA PASS。

  8. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    Automation checkpoint: merged PR #28093 is being validated against current upstream/main 6d44c50. This issue remains open in phase/testing; no terminal tester PASS has been recorded in the current handoff. Please report complete version, environment, scoped scenario results, and terminal PASS/FAIL evidence before any closure decision.

  9. Ariznawlll commented on Sep 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:a9d3b8b857c44f1249e682c91d4d62a914eb7d20
    • 环境:本地单机 MatrixOne,2026-09-09。

    原问题验证

    验证二进制值进入 JSON constructor 时保留二进制类型标记,而非被误当成普通字符串。

    Happy Path 覆盖

    • binary、blob、bit 三类输入在 JSON array/object/set 中均返回预期 tag;
    • MySQL protocol type 分别为 15、252、16,连续 3 轮一致。

    Unhappy Path 覆盖

    以三种不同物理二进制族交叉覆盖,确认修复不是只覆盖单一 binary 类型,且容器切换不改变 tag。

    白盒验证

    不适用:以 protocol 返回类型与 JSON 结果验证客户端可见类型契约。

    回归测试

    • 已加入 MOTR PR #152:suites/14_issue_regression/t/issue_28056_28057_28058_28060_json_constructor_types.test。
    • --record --repeat 3 和非 record --repeat 3 均通过;PR 共 21/21 用例、321/321 条语句成功。

    测试证据

    三种二进制族及 object/array/set 均重复 3 次。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugphase/testingseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions