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

JSON_TYPE result is turncated, charset max length should be considered

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.8.2, 10.8.3, 10.9.1, 10.10.1
    • 10.8.4
    • JSON
    •  Arch Linux x86_64

    Description

      Hi, I'm gsoc-2022 contributor,I'm working on the MCOL-785.
      Now I have a problem: My JSON_TYPE implementation return only the first 4 characters:

      MariaDB root@(none):test> create table jt_test(i longtext) engine=columnstore;
      Query OK, 0 rows affected
      Time: 0.288s
      MariaDB root@(none):test> insert into jt_test values('{}');
      Query OK, 1 row affected
      Time: 0.179s
      MariaDB root@(none):test> insert into jt_test values("[]");
      Query OK, 1 row affected
      Time: 0.134s
      MariaDB root@(none):test> insert into jt_test values(42);
      Query OK, 1 row affected
      Time: 0.116s
      MariaDB root@(none):test> select json_type(i) from jt_test;
      +--------------+
      | json_type(i) |
      +--------------+
      | OBJE         |
      | ARRA         |
      | INTE         |
      +--------------+
      

      The charset used by json_type() Field is utf8_mb3. When the copy into the Field buffer takes place there is a copy length calculation that divides the length 12 bytes(strange but this is what it is) by 3(max byte per char length for utf8_mb3).So finally the result return 4 characters.

      I found here that the max length and collation are set:

      bool Item_func_json_type::fix_length_and_dec()
      {
        collation.set(&my_charset_utf8mb3_general_ci);
        max_length= 12;
        set_maybe_null();
        return FALSE;
      }
      

      So I think the max_length should be set 12*collation.collation->mbmaxlen to make json_type in columnstore behave correctly.

      • My JSON_TYPE implementation: func_json_type.cpp
      • Pull Request: has been submitted and passed CI)
      • The Callstack that might be useful (the #0、#1、#2、#3 from_length=6, nchars=4).

      Attachments

        Issue Links

          Activity

            People

              rucha174 Rucha Deodhar
              lunar_land ziyitan
              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.