Repository navigation
add json_overlap - #25981
add json_overlap#25981
Conversation
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? |
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
Found two blocking compatibility/performance issues. GitHub CI is green; focused local tests were blocked because cgo/libmo.dylib is absent.
P1 - Accept all MySQL string storage types (pkg/sql/plan/function/func_builtin_json_overlap.go:89)
The checker accepts only JSON, CHAR, VARCHAR, and TEXT. MatrixOne's IsMySQLString(), used by sibling JSON functions, also includes BINARY, VARBINARY, and BLOB; MySQL likewise accepts these as JSON-text inputs. Consequently JSON_OVERLAPS over valid VARBINARY/BLOB JSON columns fails during function resolution instead of parsing and executing. Use the shared string-type predicate and cover these types.
P1 - Reuse constant-array indexes even when the constant is longer (pkg/sql/plan/function/func_builtin_json_overlap.go:332)
arraysOverlapViews first moves the shorter array to the left, then only reuses left.prepared. For JSON_OVERLAPS(, column_with_small_arrays), the constant is moved right and its cached index is ignored, so every row scans the entire constant. An 8192-element constant against 8192 one-element rows performs roughly 67 million comparisons instead of one index build plus one logarithmic probe per row. Select the prepared constant using batch-amortized cost before the size swap and add array-valued batch coverage.
XuPeng-SH
left a comment
There was a problem hiding this comment.
I found one meaningful issue before this should merge.
pkg/sql/plan/function/func_builtin_json_overlap.go has a performance regression in arraysOverlapViews(). The function swaps the operands so that left is always the smaller array, but after that swap it only checks left.prepared:
if left.document.GetElemCnt() > right.document.GetElemCnt() {
left, right = right, left
}
...
if left.prepared != nil {
left.prepared.ensure(left.document)
return jsonOverlapPreparedArrayOverlaps(left.document, left.prepared, right.document)
}
return w.arraysOverlap(left.document, right.document)For the common shape json_overlaps(<large const array>, <smaller row array>), the const side starts with a prepared index, but the size swap moves it to right, so this branch is missed and the code falls back to rebuilding a transient sorted workspace for every row. That defeats the prepared-array optimization exactly for the query shape where it matters most.
Please check right.prepared after the size swap as well, e.g. by probing the smaller array against the prepared larger const array, and add a regression test that covers the swapped-operand case.
Non-blocking follow-ups I would still recommend:
- add typed-JSON RHS / both-sides-typed coverage for
json_overlaps; - add SQL-visible too-deep JSON and NULL-short-circuit cases;
- add a partial-row skip unhappy-path test where skipped rows contain malformed/deep JSON.
aunjgr
left a comment
There was a problem hiding this comment.
I found two merge-blocking issues on the current head.
-
pkg/sql/plan/function/func_builtin_json_overlap.go:89: the overload checker accepts JSON/CHAR/VARCHAR/TEXT but rejects BINARY, VARBINARY, and BLOB. Those are included by the sharedIsMySQLString()contract used by the other JSON functions, so valid JSON text stored in those column types fails at function resolution. Useinput.Oid.IsMySQLString()and add typed cases. -
pkg/sql/plan/function/func_builtin_json_overlap.go:332:arraysOverlapViewsswaps by length and then only considersleft.prepared. Forjson_overlaps(<large constant array>, small_array_column), the prepared constant is moved to the right and ignored, forcing a full transient sort/scan for every row. The work grows to rows × constant size despite the constant index. Preserve/probe either prepared operand after the swap and add a batch regression where the constant is the larger array.
• 针对 reviewer comment 的修改:
|
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
One non-blocking MySQL wire-compatibility issue remains.
P2 - Return MySQL ER_INVALID_TYPE_FOR_JSON for rejected arguments (pkg/common/moerr/error.go:404)
The new checker correctly rejects JSON_OVERLAPS(1, '1'), but ErrInvalidTypeForJSON is mapped to ER_UNKNOWN_ERROR/HY000. The protocol therefore sends the internal error code 20316 (it falls back when the MySQL code is unknown), rather than MySQL's ER_INVALID_TYPE_FOR_JSON 3146 with SQLSTATE 22032, despite the exact 3146 definition already existing in mysql_error_define.go. Clients that branch on MySQL error codes or SQLSTATE receive an incompatible result. Map this error to ER_INVALID_TYPE_FOR_JSON and add a protocol-level code/state assertion.
Merge Queue Status
This pull request spent 1 hour 9 minutes 43 seconds in the queue, including 59 minutes 33 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #24738
What this PR does / why we need it:
• 此分支实现了 JSON_OVERLAPS,并补齐其性能、安全性和回归覆盖。