Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3
-
Related to performance
Description
JSON_EQUALS (Item_func_json_equals::val_bool) and JSON_OVERLAPS (compare_nested_object) perform a complete normalisation (json_normalize) on both arguments to validate a comparison. On large documents this is an expensive operation in CPU and memory as a complete copy of the document is needed.
It is possible to implement a function that parses and walks both arguments at each level element/ or common object performs a comparison allowing inequality (json_equals) or commonality (json_overlaps) to short cut the processing of the document and return early.
For JSON_OVERLAPS we might want to continue processing to ensure that both arguments are valid json documents but that's simple (below) compared to a json_normalization.
while (json_scan_next(&je1) == 0 && json_scan_next(&je2) == 0) /* no-op */ ; |
Note the other function json_normalize does is it convert the document to utf8mb4 first before walking the document. In an alternate implementation for this perhaps this could be done element by element but noting there are other existing bugs about character sets with JSON that may impede this.