Skip to content

[Compatibility]: JSON-to-character CAST unquotes JSON strings instead of serializing them #29471

Closed

Description

@XuPeng-SH

Existing issue check

Searched existing MatrixOne issues before filing.

Branch / commit

main history; reproduced using the clean direct-parent benchmark binary for 1575e70c3db676d3ed00abc080aadc029b0e1435, fresh copy of its data snapshot, Linux amd64, local single CN on NVMe. Discovered while reviewing #29462; these ordinary SQL failures do not require prepared execution.

Actual behavior / reproduction

select cast(cast('"abc"' as json) as varchar);

Observed character value: abc. Expected serialized JSON character value: "abc".

MySQL JSON conversion rules specify serialization for JSON-to-character conversion; unquoting belongs to JSON_UNQUOTE.

Root cause / scope

jsonToStr special-cases a JSON string with Unquote(), while other JSON categories use MarshalJSON(). Existing CAST-width and DML assignment tests rely on the unquoted payload, including truncation/trailing-space behavior, so changing this shared function requires an explicit CAST-versus-assignment compatibility review and updated independent SQL controls.

Related: #29462 (source binding review) and #28907 (JSON CONCAT). #29462 preserves the existing CAST/assignment behavior and implements CONCAT serialization at CONCAT's shared consumer boundary. This issue tracks the separate shared CAST/assignment contract; it is not claimed fixed by the performance PR.

Activity

  1. added
    kind/bug
    on Sep 29, 2026
  2. self-assigned this
    on Sep 29, 2026
  3. added a commit that references this issue on Sep 30, 2026
    3d22228
  4. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • Commit:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 部署方式:本地全新单 CN mo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE
    • 测试日期:2026-10-02

    原问题验证

    按 issue 原始语义在上述 commit 重新执行并重复 3 次。JSON string 在结果中保留 JSON 引号,number/bool/null 仍保持各自 JSON 类别。

    Happy Path 覆盖

    覆盖标量 JSON 各类别和 CTAS/查询投影。

    Unhappy Path 覆盖

    覆盖 SQL NULL、JSON null、嵌套值与非法 JSON;无类型串化混淆。

    白盒验证

    关联修复 #29508、#29462 已进入当前 main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。

    回归测试

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 当前结果:JSON string 在结果中保留 JSON 引号,number/bool/null 仍保持各自 JSON 类别。
    • 回归代码与 golden result 已提交到 MOTR #209;本地全量 14_issue_regression 中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。

    测试结论

    测试通过。

  5. MatrixAdventurer commented on Oct 6, 2026

    @MatrixAdventurer
    Contributor

    Additional release-version reproduction from a local test-owned instance (2026-10-07 Asia/Shanghai).

    • Official release: v4.2.5, binary-reported commit 1a44f3d, Linux x86_64.
    • Binary SHA-256: 5d136df6fab5e7a5bdf4ba3e678470d898c8d681f3fdae99095ecd9c4205d2ed.
    • Real MySQL text protocol; no mock database.
    select cast(cast('"abc"' as json) as char);
    -- actual character value: abc
    select cast(cast('"中文🙂"' as json) as char);
    -- actual character value: 中文🙂
    select cast(cast('{"x":1}' as json) as char);
    -- actual: {"x": 1}

    A broader 487-case boundary suite had 3 failures, all JSON-string serialization cases attributable to this existing issue. Object/numeric round-trips, JSON paths and Unicode extraction controls passed.

    This is not a claim of regression on current main. The inspected main snapshot d9eb0e0ce88bec403dce4cd6c7fbdf15f19e1b03 has the explicit-CAST serialization branch and issue_29471_json_character_cast regression case. I have not run a main-built full server to revalidate that SQL fix. Leaving this issue closed; no duplicate issue created.

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions