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

JSON_UNQUOTE produces utf8mb3 output while JSON can be utf8mb4

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Duplicate
    • 10.5, 11.7(EOL)
    • 10.11.12, 11.4.6, 11.8.2
    • JSON
    • None

    Description

      JSON functions seem be fine with processing UTF8MB4 characters. The only exception is JSON_UNQUOTE which tries to produce UTF8MB3 and so destroys any non-mb3 characters.

      Testcase: (the smiley is this character: https://www.compart.com/en/unicode/U+1F60A)

      set names utf8mb4;
      set @v='{ "color":"😊" }';
      select @v, collation(@v);
      select json_valid(@v);
      select json_extract(@v,'$.color'), collation(json_extract(@v,'$.color'));
      select json_unquote(json_extract(@v,'$.color')), collation(json_unquote(json_extract(@v,'$.color')));
      

      Run it and:

      MariaDB [test]> set names utf8mb4;
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [test]> set @v='{ "color":"😊" }';
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [test]> select @v, collation(@v);
      +--------------------+-----------------------+
      | @v                 | collation(@v)         |
      +--------------------+-----------------------+
      | { "color":"😊" }     | utf8mb4_uca1400_ai_ci |
      +--------------------+-----------------------+
      1 row in set (0.001 sec)
      

      Note that JSON_VALID and JSON_EXTRACT work:

      MariaDB [test]> select json_valid(@v);
      +----------------+
      | json_valid(@v) |
      +----------------+
      |              1 |
      +----------------+
      1 row in set (0.001 sec)
       
      MariaDB [test]> select json_extract(@v,'$.color'), collation(json_extract(@v,'$.color'));
      +----------------------------+---------------------------------------+
      | json_extract(@v,'$.color') | collation(json_extract(@v,'$.color')) |
      +----------------------------+---------------------------------------+
      | "😊"                         | utf8mb4_uca1400_ai_ci                 |
      +----------------------------+---------------------------------------+
      1 row in set (0.001 sec)
      

      But try removing the quotes and the smiley is lost:

      MariaDB [test]> select json_unquote(json_extract(@v,'$.color')), collation(json_unquote(json_extract(@v,'$.color')));
      +------------------------------------------+-----------------------------------------------------+
      | json_unquote(json_extract(@v,'$.color')) | collation(json_unquote(json_extract(@v,'$.color'))) |
      +------------------------------------------+-----------------------------------------------------+
      | ?                                        | utf8mb3_general_ci                                  |
      +------------------------------------------+-----------------------------------------------------+
      1 row in set (0.001 sec)
      

      Attachments

        Issue Links

          Activity

            psergei Sergei Petrunia created issue -
            serg Sergei Golubchik made changes -
            Field Original Value New Value
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.11 [ 27614 ]
            Fix Version/s 11.4 [ 29301 ]
            Fix Version/s 11.7 [ 29815 ]
            serg Sergei Golubchik made changes -
            Assignee Rucha Deodhar [ rucha174 ]
            serg Sergei Golubchik made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]
            danblack Daniel Black made changes -
            Affects Version/s 10.5 [ 23123 ]
            danblack Daniel Black made changes -
            Fix Version/s 10.5 [ 23123 ]
            psergei Sergei Petrunia made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            psergei Sergei Petrunia made changes -

            This function is needed if one has a JSON field, a virtual column that extracts some value from the JSON, and an index on that value. It's the primary usecase of MDEV-35616.

            psergei Sergei Petrunia added a comment - This function is needed if one has a JSON field, a virtual column that extracts some value from the JSON, and an index on that value. It's the primary usecase of MDEV-35616 .
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 11.7(EOL) [ 29815 ]
            rucha174 Rucha Deodhar made changes -
            Status Confirmed [ 10101 ] In Progress [ 3 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.11.12 [ 29998 ]
            Fix Version/s 11.4.6 [ 29999 ]
            Fix Version/s 11.8.2 [ 30001 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.11 [ 27614 ]
            Fix Version/s 11.4 [ 29301 ]
            Assignee Rucha Deodhar [ rucha174 ] Daniel Black [ danblack ]
            Resolution Duplicate [ 3 ]
            Status In Progress [ 3 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -

            People

              danblack Daniel Black
              psergei Sergei Petrunia
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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