Repository navigation
[Feature] Support MySQL MEMBER OF JSON operator - #28096
Conversation
d07440d to
f598f3b
Compare
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
iamlinjunhong
left a comment
There was a problem hiding this comment.
审查基于当前 head d2f4c58(base 4f90107)。已确认 28/28 checks 结束且通过;也已读取我上轮 review、全部 review threads 与 PR conversation:上轮 binary-RHS 和 YEAR 的 P1 都有作者逐项回复,且当前实现已修复。以下是当前仍存在的独立阻塞问题。
- P1 — RHS 直接 prepared parameter 的非文本协议类型会被当作 JSON 文本接受。
- 位置:pkg/sql/plan/base_binder.go:6579-6589、pkg/sql/plan/utils.go:4627-4630、pkg/frontend/computation_wrapper.go:1455-1462,结果在 pkg/sql/plan/function/func_builtin_json_member_of.go:114-116,242-245 生效。
- 触发:二进制协议执行 SELECT 1 MEMBER OF (?),参数 0 绑定为 MYSQL_TYPE_LONGLONG(同样适用于 FLOAT/DOUBLE/boolean)。binder 只给左侧 marker 加 JSON comparison adapter;collector 也只登记 Args[0],因此 RHS concrete type 没有写入 vector metadata。它先被 cast 成 varchar,随后按字节解析 "1" 为 JSON,而不是依据 RHS “JSON 或 text only” 契约拒绝。RFC 的 docs/rfcs/20260906_mysql_member_of_operator.md:42-45,93-97 明确要求此边界。
- 请保留并在执行前验证 RHS runtime SQL domain,拒绝 numeric/float/bool/binary 绑定;补充完整 COM_STMT_PREPARE/EXECUTE 的 text 接受、上述拒绝以及 text→numeric→text 同 statement 重绑定覆盖。
- P1 — 每次普通 binary prepared execute 都新增一次 O(paramCount) 分配。
- 位置:pkg/frontend/computation_wrapper.go:916-930,1478-1487。
- 触发:任意含参数的二进制 prepared execution,例如 64 个 MYSQL_TYPE_LONG 参数。调用点无条件调用 helper,helper 在检查是否存在 BLOB-family 参数前就执行 make([]bool, paramCount);即使最终返回 nil,分配已经发生。它绕开已有 prepareStmt.paramMetadata 的复用,并把与 MEMBER OF 无关的常规 OLTP prepared statements 全部带入热路径。
- 请先无分配地检测是否需要 binary-string metadata,并复用 statement-owned sidecar;添加 no-BLOB 的 allocation 回归测试,以及 BLOB → non-BLOB → BLOB 重用/reset 测试。
|
Addressed the current-head CR findings in
Exact-head validation:
The full required CI matrix is running for this new head. Please re-review this exact commit. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head b0035c1ed7aaa46f5f215e79067c35ac1a8220af found two remaining correctness blockers and one avoidable hot-path cost. The previous RHS-runtime-domain and no-BLOB-allocation findings are fixed on this head; the committed focused tests for those fixes pass.
[P1] Preserve the complete COM_STMT type domain for the left operand
The new exact-type path is still lossy. binaryProtocolPrepareParamDomains maps unhandled protocol types to T_text, while initExecuteStmtParamWithResolverInSession only publishes a concrete type when PrepareParamKindForType recognizes it and agrees with the coarse kind. That makes the payload heuristic override the actual wire type and drops JSON and temporal domains.
I reproduced these through the production packet decoder, prepared-plan setup, and expression executor:
- signed
MYSQL_TYPE_TINY(1) MEMBER OF ('[1]')returns0, and the same value against'[true]'returns1. MySQL 8.4 returns1and0: the classic protocol has no Boolean parameter type, and MySQL handlesMYSQL_TYPE_TINYwith the integer path. HerebinaryProtocolPrepareParamKindguesses Boolean from the payload, then theT_int8exact type is discarded because the two disagree. - a
MYSQL_TYPE_JSONpayload[1] MEMBER OF ('[[1]]')returns0because the JSON document is demoted to the SQL string"[1]". - a
MYSQL_TYPE_DATEvalue2024-01-02 MEMBER OF (JSON_ARRAY(DATE '2024-01-02'))returns0; MySQL returns1because the temporal JSON scalar domain is retained.
Please make concrete protocol metadata authoritative for every direct MEMBER OF left parameter, with the coarse conversion kind used only as a fallback for genuinely untyped/non-protocol values. In particular, do not infer JSON Boolean from signed TINY 0/1, preserve MYSQL_TYPE_JSON as a document, and preserve DATE/TIME/DATETIME/TIMESTAMP (plus the other accepted scalar protocol domains) through scalar conversion. Add full COM_STMT packet tests for numeric 0/1 versus JSON number/Boolean, JSON arrays/objects, temporal values, and repeated executions that change domains.
[P1] A NULL left operand must suppress RHS validation and parsing
jsonMemberOf checks jsonMemberOfRightIsBinary and jsonMemberOfRightHasInvalidRuntimeType before it calls left.documentAt. Thus a prepared NULL MEMBER OF (?) reports 3146 for a numeric binding and 3144 for a BLOB binding instead of returning SQL NULL.
This contradicts both the RFC's “if either operand is SQL NULL, return SQL NULL” contract and MySQL 8.4. I independently verified that all of the following return NULL in MySQL:
SELECT NULL MEMBER OF (1);
SELECT NULL MEMBER OF (CAST('[1]' AS BINARY));
SELECT NULL MEMBER OF ('not-json');
PREPARE s FROM 'SELECT NULL MEMBER OF (?)'; -- numeric and binary executionsMoving the two runtime checks below the left-NULL branch fixes prepared execution, but the static checker also rejects numeric/binary RHS types before execution, so static and all-NULL-column cases need to be covered by the design rather than patched only for direct parameters. Please add static, prepared, malformed-JSON, and nullable-column regressions proving that RHS type/parse work is skipped for NULL left rows while non-NULL rows still produce the correct 3144/3146/invalid-JSON errors.
[P2] Avoid the unconditional second batch scan
The evaluableRows loop at the start of jsonMemberOf scans every row and reads both operands before the real evaluation loop. That count is only useful when the RHS is a constant array large enough to be eligible for the prepared-array index. It is pure duplicate work for non-constant RHS values, scalar RHS documents, and arrays at or below jsonOverlapLinearCompareBudget, including the common one-element predicate.
Please decode/classify a constant RHS first and count evaluable rows only for an index-eligible constant array; otherwise use the single evaluation pass. Add a small benchmark or counter-based regression covering scalar/small constant and non-constant RHS batches.
The RFC design gate also remains open: its alternatives section still does not address the explicitly requested jq architecture option, despite the issue's maintainer guidance. A concise rejection is sufficient if the native bytejson path is selected, but it should compare semantic fidelity, prepared-parameter conversion, cancellation/bounds, and the reusable exact-array index rather than leaving the decision undocumented.
Validation performed on the exact head:
- exact-head required CI: all terminal and green (neutral/skipped orchestration checks excluded)
- committed parser/planner/function/frontend focused tests: PASS using the repository CGo wrapper where required
- forced parser regeneration: byte-identical
git diff --check: PASS- six review-only COM_STMT counterexamples: all fail with the mismatches above; the review-only test file was not committed
- independent MySQL 8.4 differential checks and MySQL source inspection (
Item_func_member_of, protocol parameter handling)
|
Automation checkpoint for exact head This update addresses the latest review blockers:
Local exact-head evidence: the clean Fresh required CI is currently in progress (5 checks); the independent design approval and reviewer re-review remain pending. No CI rerun or re-review request was issued in this update. |
|
Exact-head repair update Pushed commit 2296f72 to codex/issue-23008-json-member-of. The PR head, source repository/branch, base 4f90107, and Ready state were re-verified before push. Diagnosis of exact-head run 34063704795:
The repair adds a separate MEMBER OF parameter-position collector, limits exact concrete protocol metadata to MEMBER OF, and preserves generic JSON Boolean/Decimal/text compatibility for both binary protocol and EXECUTE USING paths. Local evidence for the pushed exact diff:
Fresh CI is running at 34068329035: CHECK PR VALID and Plan complementary BVT groups passed; SCA 101580968112 and UT 101580968128 are in progress, UT Coverage 101580989518 is queued, and no terminal result is available yet. No blind rerun was performed. Live review recheck found two formal threads, both resolved; one is outdated and the other is resolved on the current line. No review thread or issue lifecycle state was mutated. QA handoff remains pending fresh CI and reviewer re-review. |
aunjgr
left a comment
There was a problem hiding this comment.
Review of commit 2296f72a95166dc1a3e9e18e975b17038ac556f5.
[design gate] The new docs/rfcs/20260906_mysql_member_of_operator.md supplies the previously missing versioned design, but its header explicitly records 'Design-review decision: pending independent approval'. MEMBER OF crosses parser, binding, JSON execution, and prepared-parameter domain handling, so that approval is required before implementation approval. Resolve and record the independent decision on this exact design revision; an 'in-progress' label alone does not close the explicit pending decision. This review stops at that gate and does not claim an additional runtime defect.
Evidence: source review and existing passing CI for this commit; no new local test run was performed for this review.
|
Exact-head conflict repair update
|
aptend
left a comment
There was a problem hiding this comment.
Deep re-review of exact head d4cae2d57ed00c3384b573b371baef233ba47579 (base 74668fc075c965c462b30f10ae24a1c19c289cfd). I read the full review/comment/thread history and verified the prior binary-RHS, YEAR, prepared-RHS-domain, NULL-short-circuit, allocation, concrete-protocol-domain, and extra-scan findings against the current full diff; those earlier implementation findings are closed. The current RFC revision is not approvable yet because the three independent scalar/runtime-domain blockers below remain.
Validation on the exact head: parser regeneration was byte-identical apart from the generated output-path header; focused owning-package tests passed for parser/tree/plan/function/frontend/process/vector/moerr; focused race tests and go vet passed. Three review-only counterexamples failed as described and were removed afterward. MySQL's authoritative scalar-to-JSON path treats BIT as opaque, ENUM as its string label, and GEOMETRY as a GeoJSON object; the current implementation diverges on each relevant path.
Please extend the RFC/acceptance matrix to cover every admitted left scalar and unsupported runtime domains, fix the cases below, and add public SQL plus prepared-execution regressions. The design header also still records pending independent approval; this review does not grant that approval while these contracts remain open.
aptend
left a comment
There was a problem hiding this comment.
Deep re-review of exact head 3f162ba021b9a4e20113ca88725d96e201f2e1b6 against base 74668fc075c965c462b30f10ae24a1c19c289cfd. I read the complete review/comment/thread history and author replies, reviewed both the increment since my previous reviewed head d4cae2d57ed00c3384b573b371baef233ba47579 and the full diff, and verified the earlier three findings are now closed: prepared vector domains are retained and rejected, prepared BIT is explicitly rejected while static BIT stays width-aware/opaque, and ENUM/GEOMETRY conversions preserve their intended domains. I also independently reviewed the RFC; its parser/binder/executor ownership, type/error matrix, jq alternative rejection, bounds, and validation plan are acceptable, so the design gate is closed from my side.
Two exact-head blockers remain:
- A SQL NULL RHS does not short-circuit an unsupported prepared left domain, contrary to the RFC and normal SQL NULL propagation. The inline counterexample reproduces this.
- The newly added embedded regression leaks its prepared statement on any assertion failure before the final Close, and the required SCA job is failing on exactly this line.
Validation on the exact head: git diff --check; make thirdparties && make -C cgo; normal tests for pkg/container/vector, pkg/vm/process, pkg/sql/plan/function, pkg/sql/plan, pkg/frontend, and the MySQL parser; focused race tests for MEMBER OF function paths (-count=20) and frontend prepared/binary-protocol paths (-count=10). All passed. A review-only prepared-BIT-plus-NULL-RHS regression failed with Invalid data type ... argument 1; it was removed afterward and the worktree is clean. The exact-head GitHub SCA job fails with issue_23008_test.go:99:32: Close should use defer (sqlclosecheck).
|
Exact-head CI repair for
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 1557691cf490fb1a6529c0f325c048b6a4f7d62c. The increment from the previously reviewed 3f162ba021b9a4e20113ca88725d96e201f2e1b6 only adds the deferred prepared-statement Close. That fixes the test cleanup/SCA finding, but the production correctness blocker is unchanged.
[P1] Check either operand's SQL NULL before validating or converting the left value
In func_builtin_json_member_of.go:311-334, the loop invokes jsonMemberOfLeftHasInvalidRuntimeType and left.documentAt before parameters[1].IsNull(row).
Trigger: prepare SELECT ? MEMBER OF (?), then bind a non-NULL BIT left parameter and SQL NULL on the right. The concrete BIT OID reaches the left runtime validator, which rejects it and returns the argument-1 JSON type error. Execution never reaches the right-NULL branch. Unsupported native-vector left bindings have the same ordering problem; a left conversion error can also precede the RHS NULL check.
The RFC explicitly promises SQL NULL if either operand is SQL NULL, including the prepared BIT limitation. Thus this produces an error for a query that should produce NULL. The prior review independently reproduced the prepared-BIT/NULL case; the entire production implementation is byte-for-byte unchanged since that reproduction, and the current source still has the same failing order. This is not merely missing test evidence.
After the selection-mask check, inspect both operands' null flags and append NULL/continue before either side's domain validation, decoding or scalar conversion. Keep JSON null separate: it is a value, not an SQL null flag. Add selected-row and mixed-row tests, prepared BIT/vector + SQL NULL RHS, and error-then-valid rebind cases; retain rejection for the same unsupported operands when both SQL operands are non-NULL.
The previous independent design approval remains applicable; I am not reopening a design gate solely because the RFC header still says pending. The defer change itself is appropriate. Evidence in this round: complete increment comparison, current evaluator/type-check paths and RFC review, and reuse of the prior unchanged-production reproduction. I did not rerun a fresh native cluster/race suite or wait for CI.
aptend
left a comment
There was a problem hiding this comment.
Deep re-reviewed exact head 1557691 against base 74668fc. I read the complete review/comment/reply/thread history, compared the increment from my last reviewed head 3f162ba, and rechecked the full diff. The increment only defers statement cleanup, which closes the SCA finding; the earlier binary/YEAR/vector/BIT/ENUM/GEOMETRY fixes remain sound, and the design is acceptable from my side. One production blocker remains at pkg/sql/plan/function/func_builtin_json_member_of.go:323: each selected row validates and converts the left operand before checking parameters[1].IsNull(row). Trigger PREPARE SELECT ? MEMBER OF (?) and bind a non-NULL MYSQL_TYPE_BIT (or unsupported native vector) on the left and SQL NULL on the right. The RFC and SQL NULL contract require NULL, but this exact head returns the argument-1 invalid-JSON-type error. A review-only exact-head test expected a NULL result and failed with that error; it was removed afterward. Check both operands' SQL-null flags immediately after the selection-mask branch, before either domain validation, decoding, or conversion; retain JSON null as a value and add BIT/vector plus NULL, selected/mixed-row, and error-then-valid-rebind coverage. Validation: thirdparties/CGo build; normal function, plan, parser and embedded issue tests; focused MEMBER OF race tests; diff check and current-main merge-tree all passed; exact-head required CI is green.
iamlinjunhong
left a comment
There was a problem hiding this comment.
审查基于当前 head 1557691cf490fb1a6529c0f325c048b6a4f7d62c,合并基线 74668fc075c965c462b30f10ae24a1c19c289cfd。完整 diff、MEMBER OF 的 binder → prepared-metadata → vector → executor 调用链,以及新增 parser/function/frontend/embedded 测试均已复核。
- P1 — 右操作数 SQL NULL 没有在拒绝 prepared 左操作数域之前短路。
- 位置:
pkg/sql/plan/function/func_builtin_json_member_of.go:323(左侧 runtime-domain 校验)与:336(右侧 SQL NULL 分支)。 - 触发:直接 prepared 执行
SELECT ? MEMBER OF (NULL),左参数以MYSQL_TYPE_BIT绑定(或以原生 vector/array 域绑定),右操作数为 SQL NULL。第 323 行先使jsonMemberOfLeftHasInvalidRuntimeType返回 true,因而返回 argument 1 的 InvalidType 错误;第 336 行永远不可达。契约要求任一 SQL NULL 返回 nullable BIGINT NULL,RFC 也明确 prepared BIT/vector 的限制不影响 NULL short-circuit。 - 请将右侧 SQL NULL 短路置于所有左右 prepared-domain 校验之前(但在已掩码行之后),并增加 BIT/vector 左参数 + NULL RHS 的函数级与真实 PREPARE/EXECUTE 回归用例。
- 位置:
此前我提出的 binary-RHS 与 YEAR 两项 P1 已有作者对应回复且当前实现/覆盖已修复;本轮未发现独立 P0。由于上述 P1 在当前 head 仍存在,本 review 请求修改。
|
Addressed in
Validation on the exact committed head:
Requesting re-review; the new required CI run is still pending. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Astra(GPT-6)按当前 head fd89379 完成复核,结论 APPROVE。
- 本轮增量将左右两侧 SQL NULL 判断统一前置到 runtime domain 校验/JSON 解析之前,修复 prepared BIT/vector 左值 + NULL RHS 被错误报类型错误的问题。
- 新增回归用例覆盖 prepared BIT + NULL RHS,同时保留非 NULL 非法域拒绝路径;未改变非 NULL 比较语义。
- 复核 prepared 参数 OID/provenance、重绑定、binder 参数位置和 WHERE 消费路径,未发现新的正确性或兼容性 blocker。
- NULL/被过滤行不会触发 RHS 解析或准备;既有清理逻辑保留。增量无协议/存储结构变化,也未引入额外 RPC、后台任务或无界内存。
- 当前 head 的 UT、SCA、Coverage、BVT/Proxy 等实质 CI 均成功(允许的 skipped 除外)。
What type of PR is this?
Which issue(s) this PR fixes:
issue #23008
Related duplicate report: #28035. Both issue lifecycle decisions remain separate from merging this PR.
What this PR does / why we need it:
Implement the MySQL
MEMBER OFJSON operator (including optionalOF) through parser, AST formatter, binder, function registry, vector executor and prepared execution.The result is nullable
BIGINT(1/0/NULL). Membership compares complete direct elements, not recursive containment, and does not coerce strings to numbers. A non-array RHS is compared as a complete JSON value. SQL NULL and excluded rows short-circuit RHS validation; JSON null remains a value. Binary-charset RHS uses error 3144; other invalid RHS domains use the argument-2 JSON-type error. YEAR is numeric for this operator without changing JSON_ARRAY/JSON_SET behavior.Current CR repair:
Validation of
3f162ba021b9a4e20113ca88725d96e201f2e1b6:74668fc075c965c462b30f10ae24a1c19c289cfd.d4cae2d57ed00c3384b573b371baef233ba47579fails the added special-domain regressions; repaired content passes.pkg/container/vector,pkg/vm/process,pkg/sql/plan/function,pkg/sql/plan,pkg/frontendPASS. Frontend rerun after final protocol fixture correction PASS.-race -count=10: function, frontend, process PASS, including final BIT-error/rebind protocol path.TestIssue23008MemberOfScalarDomains).func_json_member_of: 43/43 PASS against the exact-source embedded CN. This is local canonical comparison, not a multi-CN Compose run.go list/build/vet -mod=readonlyandgit diff --checkPASS.c8d9faf2ff1b787b798fd67a0138e2a0fd43caec9a866c7a04b229179bd381bb.QA required: yes
BVT: added; canonical local comparator PASS.
Design gate remains open:
docs/rfcs/20260906_mysql_member_of_operator.mdrequires independent approval. Ready-for-review does not mean approved or ready to merge. The prior formal design CR is not self-dismissed by this code repair.No public API/configuration change or issue closure is part of this update.