Repository navigation
add json_merge_patch, json_merge_preserve - #25728
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? |
本次修改主要解决两个性能问题:
同时新增:
效果:256 KiB、depth-100 场景从约 27–54 MB/op 降至约 70–340 KB/op。相关包全量测试和 focused race 均通过。 |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed current head 6f933aaf51bf99f597fa8366b281a19bba3afe40. The two previous Q3 blockers are fixed: the mutable plan encodes once, the PRESERVE depth overflow is rejected before output construction, and parameter accessors are now batch-scoped. One correctness blocker remains.
[P1] Validate every non-NULL JSON argument before the merge state machine can discard it.
MergeBuilder.Reset deliberately skips depth validation (pkg/container/bytejson/bytejson_merge_plan.go:132-141), and the SQL loops also bypass Merge for a PATCH object while the target is unknown and return early for PRESERVE on SQL NULL (pkg/sql/plan/function/func_builtin_json.go:1574-1593,1649-1657). Therefore current head accepts inputs that violate the new 100-level contract:
JSON_MERGE_PATCH(depth_101_object, '1')returns1.JSON_MERGE_PATCH(NULL, depth_101_object)returns SQL NULL.JSON_MERGE_PRESERVE(depth_101_object, NULL)returns SQL NULL.
MySQL parses each argument through get_json_wrapper with JsonDocumentDefaultDepthHandler before applying either the PATCH unknown-target skip or the PRESERVE NULL return, so all three cases raise the nesting-depth error. See the upstream parse path and merge loops: https://github.com/mysql/mysql-server/blob/8.0/sql/item_json_func.cc#L315-L349, https://github.com/mysql/mysql-server/blob/8.0/sql/item_json_func.cc#L3133-L3160, https://github.com/mysql/mysql-server/blob/8.0/sql/item_json_func.cc#L3431-L3477.
Please validate every non-SQL-NULL document immediately after parsing, independently of whether it will later be merged, skipped, replaced, or followed by NULL. Add the three regressions above; retaining a separate final-result depth check is still necessary for PRESERVE autowrap.
Local verification otherwise passes: affected package tests, focused -race -count=10, and go vet. The depth-100/256 KiB benchmark is now about 340 KB/op for PATCH and 71 KB/op for the early PRESERVE error, versus the previous 27-54 MB/op.
• 修改记录:
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed current head 99bb9fa after the depth-validation fix. The previous blocker is closed.
- Every non-SQL-NULL input is now depth-validated before Reset, scalar replacement, an unknown PATCH state, or a PRESERVE NULL short-circuit can discard it.
- Reset records the validated root, so Merge does not rescan it; the final materialized result remains validated.
- The fixed 100-frame traversal rejects depth 101 before exceeding its bound and keeps validation allocation-free.
- Q1: builder cleanup and sink rollback retain a single owner. Q2: this path introduces no waits. Q3: nesting, encoded size, and row-scoped memory remain bounded.
Verified locally:
- full tests for bytejson, vector, and SQL plan/function
- focused race tests, 10 repetitions
- go vet for all affected packages
- deep/wide merge benchmark
The added regressions directly cover all three previously reported discard/short-circuit cases. No remaining correctness, lifecycle, or performance blocker found.
Merge Queue Status
This pull request spent 1 hour 50 minutes 12 seconds in the queue, including 1 hour 20 minutes 12 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_merge_patch, json_merge_preserve