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

JSON Path computation doesn't do lax mode unboxing

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.3.2
    • None
    • JSON
    • None

    Description

      Filing this not because I expect we will fix this [soon], but rather to document this limitation.

      MariaDB supports "lax mode" for JSON Path evaluation. SQL Standard specifies that in this mode the JSON Path evaluator provides "boxing" and "unboxing" - ignoring one-element arrays when we don't expect them and pretending there is one when JSON document doesn't have it.

      Should we care about this here?
      It seems not: MariaDB follows MySQL and provides non-standard behavior!
      Example:

      SELECT JSON_VALUE('{"user": [{"name": "Alice"}]}', '$.user.name') AS extracted_name
      FROM DUAL;
      

      This returns NULL in both MariaDB and MySQL.
      In OracleDB, it returns "Alice" (https://sqlfiddle.com/oracle/online-compiler?id=df76eb6b-bb8d-46e8-a164-3ca92bfcd2f4)
      In PostgreSQL,

      SELECT jsonb_path_query('{"user": [{"name": "Alice"}]}', '$.user.name');
      

      also returns "Alice".

      This was also discussed, especially w.r.t. mongodb, in https://jira.mariadb.org/browse/MDEV-37288?focusedCommentId=310846&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-310846

      More specifically, the unboxing could happen anywhere along the path, as https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/create-multikey-index-embedded/#std-label-index-create-multikey-embedded shows. This means for

      set @j = '{
        "item": "t-shirt",
        "stock": [
          {
            "size": "small",
            "quantity": 8
          },
          {
            "size": "large",
            "quantity": 10
          }
         ]
      }';
      

      one could get something like json_extract(@j, '$.stock.quantity') = 8 to evaluate to true.

      Attachments

        Issue Links

          Activity

            People

              psergei Sergei Petrunia
              psergei Sergei Petrunia
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.