Repository navigation
feat(json): implement JSON_SEARCH compatibility - #30833
VioletQwQ-0 wants to merge 32 commits into
Conversation
Signed-off-by: XuPeng-SH <[email protected]>
Signed-off-by: XuPeng-SH <[email protected]>
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 038c2c4db43df000afd1c4babbebd8fceeb23506
Assessment: request_changes
JSON_SEARCH has a substantial matcher-memory amplification, and its shared parser change can alter the meaning of existing JSON paths. The location-aware traversal and reuse of LIKE semantics are otherwise justified; the specific issues raised in the prior reviews are addressed.
Model: gpt-6.1-terra / max
Session: 01a237df-a073-7910-ac2c-836d2d273b8a · slot 1 · generation 43
-
P1
pkg/sql/plan/function/func_builtin_json_search.go:465: A search uses a large non-binary literal pattern, for example JSON_SEARCH('{}', 'one', REPEAT(_utf8mb4'a', 3400000) COLLATE utf8mb4_bin).
Impact: The function compiles a regexp before discovering that the document has no string leaves. Its Go-heap allocations bypass the result account’s path reservations, so a few valid searches can exhaust CN memory.
Evidence: The row loop calls prepareMatcher before traversal, and the default matcher always calls prepareLikeRegexp. An isolated probe of the checkout’s regexp engine increased peak RSS from about 16 MiB after an equality control to about 724 MiB while compiling the 3.4 MB literal; it used Go 1.26.6 rather than the required Go 1.27.1 and did not run a SQL service. Ordinary LIKE already has a no-wildcard comparison fast path. Reuse an appropriate LIKE fast path or otherwise bound and account matcher memory while preserving wildcard behavior. -
P2
pkg/container/bytejson/path.go:350: An existing JSON_EXTRACT or JSON_SET path consists of$.afollowed by U+00A0, and the document contains keysafollowed by U+FFFD andafollowed by U+00A0.
Impact: The merge-base parser selects the U+FFFD key, while this change selects the U+00A0 key. Existing generated expressions can consequently produce different values on later writes from values or indexes created before an upgrade.
Evidence: The old parser treats byte 0xA0 as whitespace and strconv.Unquote replaces the truncated UTF-8 sequence; the new scanner consumes the complete UTF-8 key. A retained parser model demonstrates both results with an unchanged ASCII control. The published v4.2.8 release and its 20261114 hotfix use the old parser, and the stopped-upgrade contract keeps older 4.2 data in scope. Preserve existing ParseJsonPath semantics or provide a compatibility-preserving migration, while retaining the new search grammar and usable returned locations.
Validation:
-
Isolation preflight and merge-base-to-head git diff --check passed; receipts are checks/1796282173973177288-3.json and checks/1796282885118972967-5.json.
-
The parser model and regexp component probe are retained with their outputs and receipts: checks/1796282737237202539-4.json and checks/1796283262084832324-4.json.
-
The frozen head’s CI snapshot reports successful x86 unit, shared-build, coverage, and two multi-CN BVT jobs. Earlier focused review tests remain relevant to unchanged traversal and executor patch sections.
-
The review plan, validation record, and assessment of all 23 discussion keys are saved in the assigned diagnostic directory.
Limitations:
-
The Go 1.27.1 toolchain download timed out on both attempted proxies, so no fresh full-package or public SQL-service test ran locally. The regexp measurement used the checkout’s engine with Go 1.26.6.
-
The supplied snapshot does not include the umbrella issue body or an independently identifiable v4.2.9 release artifact.
What type of PR is this?
Which issue(s) this PR fixes:
Partial implementation for
issue #28033. This PR implementsJSON_SEARCH;JSON_MERGE,JSON_DEPTH, andJSON_ARRAY_INSERTwere delivered by merged PRs #28329, #28962, and #29519. This PR does not close the umbrella issue.What this PR does / why we need it:
Implementation
JSON_SEARCH(doc, one_or_all, search_str[, escape[, path ...]])with append-only function ID 641.JSON_EXTRACT. Array selectors such aslastresolve to numeric locations in the result. Return quoted member names when the search grammar or the legacy path lexer requires quotes, so the returned path keeps the original key.0and1. Convert scalar paths to text only when their row reaches path parsing. Search only JSON string leaves. Explicit escapes must be constant. Convert numeric and Boolean escapes to text before checking their length. The omitted escape follows the execution SQL mode.Current validation at
2525574b7a00038c2c4db43d. Single-weight text matching uses a constant-scratch LIKE matcher with bounded retries. The standalone matcher is proposed in feat(collation): add a constant-space rune LIKE matcher #33758 and the same matcher source is included here for integration testing. The legacy JSON path parser keeps its earlier whitespace and unquoting rules while JSON_SEARCH accepts its own path syntax.git diff --checkpassed. Local preflight found no protected contract changes and a clean merge against main461c848d7f8e. GitHub CI and formal rereview are pending.Previous validation at
038c2c4db43dedd86400a89a. The patch against main is byte-for-byte identical to the previous patch.git diff --checkpassed.TestManualMergeRetryChecksRecoveredHeadroomBeforeDeadline. The test can check the reservation before the scheduler finishes admitting the task. This PR does not change the merge scheduler or that test.Previous validation at
7276acc657420xFF. Text escapes still accept one Unicode character.90eb902a97e3and passed on this revision. Focused JSON_SEARCH tests passed in ByteJSON, function, planner, and colexec on Ubuntu.test/distributed/cases/function/func_json_search.sqlpassed 170/170 through MySQL protocol in an isolated Ubuntu single-CN cluster with JDBC metadata comparison disabled. The new case proves that a computed0xFFescape matches a literal percent sign and returns"$[0]".Previous validation at
90eb902a97e3Previous validation at
c4e70a48383c-raceon personal Ubuntu. The unchanged production sources and BVT cases preserve the two successful BVT results from the preceding head.Previous validation at
876c54b56fefc13851c20654after the ARM64 runner disconnected and a coverage worker failed admission before checking out the PR. The previous commit passed the x86 unit tests and both scheduled BVT jobs. Previous workflowgit diff --checkpassed. The updated base includes dependency changes. Required CI and formal rereview for the new head are pending.Previous validation at
493d0a14a3ce6041bc364219. JSON_SEARCH reserves matched-path scratch and retained paths through the result's allocation owner. A JSON-typed path is converted only when reached, preserving SQL NULL and path-error ordering. Unquoted paths accept the additional ECMAScript identifier characters, and both document validation and search select the document parser once per batch.test/distributed/cases/function/func_json_search.sqlpassed 169/169 through the MySQL protocol in an isolated Ubuntu single-CN cluster with JDBC metadata comparison disabled. The new SQL cases cover JSON-typed SQL NULL paths, short-circuiting, invalid converted paths, and Unicode member names.git diff --checkpassed. Required GitHub CI and formal rereview are pending.Previous validation at
6041bc364219bd6def6ff754received no MatrixOne ALL CI run. The tracked file tree is identical to that head, which includes the upstream CHECK fixture correction from test(sql): align ODKU CHECK cases with input validation #33691.git diff --checkpassed.Previous validation at
bd6def6ff754faafdf4fef03to include test(sql): align ODKU CHECK cases with input validation #33691, which corrects the CHECK constraint fixture implicated in the previous proxy BVT failure. The rebase matches the mechanical integration tree. The PR diff against its target is byte-for-byte identical, andgit diff --checkpassed.0c5dd8db89d2are upstreamcheck_constraint.testandcheck_constraint.result. The prior focused race tests, service build, and 164/164 JSON_SEARCH SQL checks apply to the unchanged production and feature test files.Previous validation at
0c5dd8db89d2d96cdf0c26fdafter the arm64 static-analysis runner lost communication with GitHub. The rebased tree matches the merge of the previous PR head and this target. Only the upstream Iceberg test differs from2a76b3bf6d91. No JSON_SEARCH production or test files changed. The previous focused race, service build, and 164/164 SQL evidence therefore applies to the unchanged JSON_SEARCH files.2a76b3bf6d91reported three failures in the CHECK constraint fixture. Plain maind96cdf0c26fdreproduced the same three failures after the duplicate-key INSERT validation change in fix(sql): validate offered rows before ODKU arbitration #33687. Coverage could not produce a verdict from the failed run.Previous validation at
2a76b3bf6d91f0c32a66b1ccafter the previous arm64 static-analysis runner lost communication with GitHub. The upstream registry keepsMO_IVF_EXACT_RANKABLEat 638 andNOT_NULL_ASSERTat 639.JSON_SEARCHuses 640, with the registry end marker at 641.test/distributed/cases/function/func_json_search.sqlpassed 164/164 on this head using mo-tester in an isolated Ubuntu cluster with JDBC metadata comparison disabled.Previous validation at
8f7f3766485179aa769b3c93. JSON_SEARCH validates the constant escape in its source character set before passing it to the binary or text matcher. Traversal retains borrowed member names and indices and renders a location only after a string matches. The rendered scratch buffer is reserved before allocation when the query has an allocation account. NULL scalar mode/path rows skip the cast window and result allocation.79aa769b3c93and passed on this head. BVT:test/distributed/cases/function/func_json_search.sqlpassed 164/164 on the personal Ubuntu host using an isolated cluster and mo-tester with JDBC metadata comparison disabled.Previous validation at
79aa769b3c936302cd4e33f0. Its newMO_IVF_EXACT_RANKABLEkeeps ID 638.JSON_SEARCHmoves to the next available ID (639), and the registry end marker advances to 640.test/distributed/cases/function/func_json_search.sqlpassed 162/162 against an isolated Ubuntu MatrixOne cluster via mo-tester. JDBC metadata comparison was disabled.Previous validation at
8487c763572c42c571ecd29c. Recursive filters keep reachable path positions only for the current document depth. Match admission uses the encoded byte limit, with temporary match storage charged to the query account when present. Binary JSON is written directly to the result vector.acbd597a268e. Preflight and diff checks passed.test/distributed/cases/function/func_json_search.sqlpassed 162/162 through the MySQL protocol against an isolated Ubuntu MatrixOne cluster using mo-tester with JDBC metadata comparison disabled. The new cases cover skipped computed paths, preceding invalid path errors, and width-preserving BIT matching.Previous validation at
42c571ecd29c42c571ecd29cc60a4b93e69e69cadd3d2d5b948arebases the publishedc7cbccbd1497branch onto target main85c458ac7b94d7f512087a93ff476e2a9486b49fafter a CMake download timeout prevented its Ubuntu CI job from starting tests. The rebased file tree matches the clean integration of the prior PR head with that main revision.test/distributed/cases/function/func_json_search.sqlpassed 155/155 with mo-tester against the integrated service. The tester used the existing setting with JDBC metadata comparison disabled. A binary-protocol probe also verified temporal patterns and prepared path reuse.Previous validation at
c7cbccbd1497pkg/sql/plan/function,pkg/sql/plan, andpkg/sql/colexec. The candidate's distributed SQL fixture passed 155/155 with JDBC metadata comparison disabled. Prepared statements retained the expected collation behavior and remained reusable after an execution error.Previous validation at
b636b4771b65b636b4771b65844a6740765f44693239ffc20353addresses both findings in the latest review. An isolated Ubuntu service reproduced the DATE-pattern rejection and both NULL-row numeric-path rejections on572abdfec79f.test/distributed/cases/function/func_json_search.sqlpassed 137/137 with mo-tester on Ubuntu. The tester used the existing setting with JDBC metadata comparison disabled.-raceinpkg/sql/plan/functionandpkg/sql/plan. The service build and focused tests passed after a local merge with main atf9d52a3a39ed. Preflight and diff checks passed.Previous validation at 572abdf
572abdfec79f6f1dc97c53130a37747d2ed129a8addresses the latest review. An isolated Ubuntu service reproduced the reported SQL outcomes on78ee2aada540.test/distributed/cases/function/func_json_search.sqlpassed 130/130 with mo-tester against the candidate service on Ubuntu. The tester used the existing setting with JDBC metadata comparison disabled.-raceinpkg/sql/plan/functionandpkg/sql/plan. The service build and focused tests passed after a local merge with main at32ffdd4ac272. The preflight and diff checks passed.Previous validation at 78ee2aa
78ee2aada5404862a3024124e84ee01355bd6197addresses the binary-pattern, Boolean-pattern, and numeric-escape findings in the latest review. An isolated Ubuntu service reproduced all three failures on25c62f68ecc6.pkg/sql/plan/functionandpkg/sql/planon the candidate and on the local merge with main atcb2309da97c3. The preflight and diff checks passed.test/distributed/cases/function/func_json_search.sqlpassed 121/121 with mo-tester against the candidate service on Ubuntu. The tester used the existing metadata comparison setting with JDBC metadata disabled. A separate SQL driver probe checked the expected column names, rows, and errors for all 121 statements and reused one binary-protocol prepared statement across binary patterns and NULL.Previous validation at 25c62f6
25c62f68ecc6f4a749bf543e235673adf3ec47e8addresses the pattern collation and numeric pattern findings.JSONSearchtests passed inpkg/sql/plan/functionandpkg/sql/planon Ubuntu. The merge-tree check against main andgit diff --checkpassed.test/distributed/cases/function/func_json_search.sqlagainst the expected column names, rows, and SQL errors. The direct SQL check did not compare JDBC metadata. An additional binary-protocol probe verified numeric argument binding and statement reuse with text.Previous validation at b89fda9
b89fda934e0fd6ad12035975960ecdcf72060667with target baseline6674873fdfde80667c96970cefac94bca444de17. Independent Astra High re-review passed on this candidate.pkg/container/bytejson,pkg/pb/plan,pkg/sql/plan/function,pkg/sql/plan, andpkg/sql/compilepackage tests passed with vet enabled. The exact-head service build and PR diff check passed.test/distributed/cases/function/func_json_search.sqlpassed 98/98 in each of two runs against the exact binary. The tester retained the historical JDBC metadata comparison setting. The case checks concrete path results, legacy key updates, rejected DDL with zero catalog rows, and prepared reuse across SQL mode changes.SHOW WARNINGS. A stored VIEW returned its expected path after restart. Catalog residue checks and isolated service shutdown passed.QA required: yes
The automated checks exercise SQL, the binary protocol, and retained VIEW readback. Broader client and deployment QA remains applicable to this partial umbrella issue implementation.
Earlier draft evidence
Historical validation (bound to the revisions listed below):
a13f9246b9(merge of mainb01e952ad1into the feature branch, resolving the function-id and MORPC-version collisions described above with focused re-validation).6cbe375b49696021d72778baa292a66287f080bd:JSON_SEARCHfailed withERROR 20105: not supported;JSON_DEPTHandSELECT 1controls passed.make buildon heada13f9246b9(embedded CommitID matches), Go1.27.1-X:simd.test/distributed/cases/function/func_json_search.sqlpassed 56/56 twice on the head binary (0 failed, ignored, or abnormal).pkg/container/bytejson,pkg/pb/plan,pkg/sql/plan/function, andpkg/sql/planpassed.protocol version 136and admission at v136, and generated-column rejection;pkg/pb/planfull package PASS including the function-identity scan renumbered to 620; function-id registry consistency PASS.go vet, configured incrementalgolangci-lint,gofmt, andgit diff --checkpassed.SQL semantic and main-integration repair at 5a94a5b
oneandall. Multiple matches remain a deduplicated JSON array. MySQL 8.0.45 source is the independent oracle.27829c66f9with focused tests; the integrated repair passes 79 selected tests/subtests across five affected packages. Fullpkg/container/bytejson,pkg/pb/plan,pkg/sql/plan/function,pkg/sql/planandpkg/sql/compilepackage tests passed.5a94a5b812358487e7768ed2932a582f3ca84650passed the canonicalfunc_json_search.sqlmo-tester BVT twice, 60/60 each time, with catalog cleanup checked between runs. The tester ignored JDBC metadata as in the existing harness.go vet, incremental golangci-lint, gofmt and diff check passed.35202093259793e48dcd7abc8ff418f07190f746; later maind24f446e1e94a58c329d422519f7aad621cdcd05contains LIKE-prefix statistics work and merges cleanly without changes to the JSON_SEARCH identity or implementation. This local evidence does not claim exact-head CI, mixed-binary validation, deployment or QA.Remote-protocol repair at 27829c6
pkg/sql/compilepackage,go vet, incremental lint andgit diff --checkpassed.27829c66f9. The canonicalfunc_json_search.sqlBVT passed 56/56 twice on one owned service, with the table/view cleanup checked between runs. The tester could not parse a result path inside a hidden-directory checkout on its first attempt; the successful runs used byte-identical case/result copies in an isolated non-hidden path. The prior BVT evidence below remains historical. Separately built old/new processes and a mixed-version cluster are NOT_RUN.Main integration and protocol admission at 7804185
d2e71035dbae7471052ca5c0034d05827b926249. Adopted the current LIKE matcher API with exact case-sensitive matching. Kept JSON_SEARCH identifiable through binder and optimizer folding, and gated executor entry before planner metadata inference can evaluate it.mo-cgo-test -race -count=1 -timeout=240s -vet=allpassed 295 selected tests and subtests inpkg/container/bytejson,pkg/pb/plan,pkg/sql/plan/function,pkg/sql/plan,pkg/sql/plan/rule, andpkg/sql/compile. Incremental golangci-lint, gofmt and diff checks passed. Independent read-only review verified the local, destination, receiver and VIEW protocol paths.make buildusing Go 1.27.1 produced a service that reported commit7804185038eb. mo-tester executed the canonicalfunc_json_search.sqltwice against that service, 60/60 each time with zero failed, ignored or abnormal cases. JDBC metadata comparison followed the historical harness setting. The test tables and view were absent after each run, and the isolated service stopped.