Skip to content

[Bug]: JSON_CONTAINS unsupported — breaks Prisma JSON where-filters at runtime (v3.0.11 & 4.0-dev) #24732

Closed

Description

@dengn

Summary

JSON_CONTAINS is not implemented. Prisma's MySQL connector compiles JSON where filters ({ path, equals }, array_contains, string_contains) into JSON_CONTAINS, so those filters fail at runtime. JSON storage/retrieval, JSON_EXTRACT, and JSON_SET all work fine — only JSON_CONTAINS is missing.

Steps to Reproduce

SELECT JSON_CONTAINS('{"tags":["x","y"]}', '"x"', '$.tags');
-- ERROR 20105 (HY000): not supported: function or operator 'json_contains'

Prisma impact

A JSON path filter such as

prisma.page.findMany({ where: { content: { path: '$.type', equals: 'doc' } } })

fails at runtime on both versions:

ConnectorError(... MysqlError { code: 20105,
  message: "not supported: function or operator 'json_contains'", state: "HY000" })

Note

Related JSON functions JSON_ARRAY / JSON_OBJECT are also unsupported on v3.0.11 (they DO work on the 4.0-dev line). JSON_CONTAINS is unsupported on both v3.0.11 and 4.0-dev.

Expected Behavior

MySQL implements JSON_CONTAINS.


Test context — Found while testing Prisma ORM (v5.22) compatibility against MatrixOne. Reproduced on both:

  • Prod cloud — 8.0.30-MatrixOne-v3.0.11
  • 4.0 dev line — nightly-0bfda604 (select version() → 8.0.30-MatrixOne-v)

(Results on the older v3.0.5 are intentionally omitted.)

Activity

  1. added
    kind/bug
    on May 31, 2026
  2. added
    severity/s0
    on Jun 2, 2026
  3. added theissue type on Jun 2, 2026
  4. added this to the MO-202606 milestone on Jun 2, 2026
  5. modified the milestones: MO-202606, MO-202607 on Jun 30, 2026
  6. added
    ai-light
    on Jul 1, 2026
  7. assigned and unassigned on Jul 9, 2026
  8. daviszhen commented on Jul 9, 2026

    @daviszhen
    Contributor

    fixed

  9. Repository owner unassigned on Jul 13, 2026
  10. Ariznawlll commented on Jul 13, 2026

    @Ariznawlll
    Collaborator

    已在最新 main 完成函数白盒、原始复现和 Prisma 风格 protocol prepared 详细验证,结果通过。

    验证环境

    • MatrixOne commit:2865ed6cc8a39727b8b274bb52b88fe441d0b30c
    • select git_version() 已核对一致
    • 对应实现:2037cc82a / add json_contains #25478
    • 客户端:Go database/sql + go-sql-driver/mysql v1.8.1
    • interpolateParams=false、单物理连接,参数查询实际走 COM_STMT_PREPARE / COM_STMT_EXECUTE

    白盒测试

    执行:

    go test -race ./pkg/sql/plan/function ./pkg/container/bytejson \
      -run '^(TestJsonContains.*|TestQuerySimpleContainPath)$' \
      -count=10
    

    两个 package 均通过,未发现 race。矩阵覆盖:

    • 2 参数与 3 参数函数签名、JSON/varchar 输入
    • object subset、array subset、嵌套 object/array、scalar containment
    • 有 path / 无 path、missing path、scalar autowrap path
    • SQL NULL、JSON null、空 array/object
    • string/number/bool 严格类型区别
    • integer/decimal/float 数值比较,包括 9007199254740993、uint64 max 精度边界
    • typed JSON input
    • invalid candidate JSON、wildcard path 的错误路径
    • select-list 跳过行/全 NULL 行,不对被过滤行错误求值

    原始 SQL

    select json_contains('{"tags":["x","y"]}', '"x"', '$.tags');

    预期:1;实际:1。不再返回 not supported。

    Prisma 风格 protocol prepared 矩阵

    测试表:

    1: {"type":"doc","tags":["x","y"],"nested":{"a":1}}
    2: {"type":"page","tags":["y"]}
    3: SQL NULL
    

    同一个 prepared SQL:

    select id from page
    where json_contains(content, ?, ?)
    order by id;

    逐次参数与结果:

    1. candidate="doc", path=$.type → [1]
    2. candidate="x", path=$.tags → [1]
    3. candidate=["y"], path=$.tags → [1,2]
    4. candidate={"a":1}, path=$.nested → [1]
    5. candidate="missing", path=$.tags → []
    6. candidate=1, path=$.missing → []

    六次均在 5 秒 deadline 内正常返回,statement 可连续复用;SQL NULL 行未被误判为 contains。

    结论:原始不支持问题已修复,Prisma { path, equals } / array containment 依赖的 protocol prepared 参数路径也可正常执行。

  11. removed
    ai-light
    on Jul 13, 2026
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