Skip to content

[Bug]: JSON_VALUE 非简单 JSON 路径与 MySQL 语义不一致 #27481

Closed

Description

@Ariznawlll

Description

JSON_VALUE 目前拒绝带通配符或递归下降的合法 JSON 路径;MySQL 8 对相同输入会按 JSON_VALUE 的标量结果规则返回 NULL 或标量。该差异会使使用通用 JSON 路径的 MySQL SQL 在 MO 上直接报错。

Environment

  • Branch: main
  • Commit: 399cbaa0046e3d051a3c1460690df574c9386783
  • Deployment: local single-CN fixture
  • Client: MySQL Connector/J 8.0.33
  • Control: MySQL 8.0.46
  • Date: 2026-08-22

Steps to reproduce

Execute each statement independently:

SELECT JSON_VALUE('{"a":1,"b":2}', '$.*');
SELECT JSON_VALUE('{"a":1,"b":2}', '$[*]');
SELECT JSON_VALUE('{"a":1,"b":2}', '$**.a');

Actual behavior

MO returns HY000 / 20203 for all three statements (invalid path expression).

Expected behavior

MySQL 8.0.46 returns:

Path Result
$.* NULL (multiple scalar matches cannot form one JSON_VALUE)
$[*] NULL (no match in this document)
$**.a 1 (one scalar match)

MO should align with the corresponding scalar/NULL outcome instead of rejecting the path solely because it is non-simple.

Stability and controls

  • Reproducer: 3/3 on MO, identical HY000 / 20203 result for all three paths.
  • Connection reuse: after every rejected statement, SELECT 1 succeeded on the same JDBC connection.
  • Normal control: simple paths such as JSON_VALUE('{"a":1}', '$.a') return 1 on both MO and MySQL.
  • Error controls: malformed JSON, malformed path, invalid modifying paths, odd JSON_OBJECT arguments, and insufficient JSON_MERGE_PATCH arguments are rejected on both sides.
  • Data mutation check: the JSON mutation failure matrix left all rows unchanged after each rejected update.

Code analysis

The current implementation intentionally applies a simple-path restriction. The distributed case test/distributed/cases/function/func_json_value.test contains a case that expects an error for $.*. This explains the deterministic result but does not match the MySQL control behavior above.

Regression coverage

After the behavior is aligned, add BVT coverage for $.*, $[*], and $**.a, including scalar, no-match, and multiple-match outcomes.

Related

Activity

  1. added this to the MO-202608 milestone on Aug 22, 2026
  2. added
    kind/bug
    on Aug 22, 2026
  3. added theissue type on Aug 22, 2026
  4. added
    severity/s0
    and removed on Aug 22, 2026
  5. Ariznawlll commented on Aug 24, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:ba8954d543af0bdfb1948a8b89f77f5235ac9259
    • 部署方式:隔离本地单 LOG/TN/CN
    • 测试日期:2026-08-24

    原问题验证

    连续 3 轮执行 JSON_VALUE 路径矩阵:$.*(多匹配)和 $[*](无匹配)均返回 NULL,$**.a 返回标量 1;简单路径 $.a 作为对照也返回 1。

    Happy Path 覆盖

    1. 多匹配路径 $.* 返回 NULL。
    2. 无匹配路径 $[*] 返回 NULL。
    3. 递归路径 $**.a 返回唯一标量;简单路径对照正确。

    Unhappy Path 覆盖

    1. 非法读取路径被拒绝后,同一连接仍可读取 $.a。
    2. 非法修改路径被拒绝后,JSON 行内容未改变。

    白盒验证

    不适用:公开 SQL 覆盖了标量、无匹配、多匹配、非法读取与非法修改的结果和状态。

    回归测试

    测试证据

    • 每轮均验证路径结果、错误后的可继续读取和修改失败原子性。
    • 回归提交:a6a562a1。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions