Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-40180

json_equals / json_overlaps (compare_nested_object) inefficient

    XMLWordPrintable

Details

    • 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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            danblack Daniel Black
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.