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

JSON function overflow error based on LONGTEXT field

Details

    Description

      Hi, I'm GSoC 2022 contributor, I'm working on the MCOL-785.
      Now I have a problem: The JSON Function result is truncated when the function is called based on LONGTEXT field.

      Take the JSON_ARRAY as an example:

      MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
      Query OK, 0 rows affected
      Time: 0.147s
      MariaDB root@(none):test> insert into t1 values('key1', 'key1');
      Query OK, 1 row affected
      Time: 0.179s
      MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
      +---------------+---------------+
      | json_array(t) | json_array(l) |
      +---------------+---------------+
      | ["key1"]      | ["key         |
      +---------------+---------------+
      1 row in set
      Time: 0.097s
      MariaDB root@(none):test>
      

      After debugging, I found that such difference is caused by overflow error.

      bool Item_func_json_array::fix_length_and_dec(THD *thd)
      {
        ulonglong char_length= 2;
      ...
        for (n_arg=0 ; n_arg < arg_count ; n_arg++)
          char_length+= args[n_arg]->max_char_length() + 4;
      ...
      }
      

      First, the return type of args[n_arg]- >max_char_length() is uint32, the max value of uint32 is 4,294,967,295.
      When called based on LONGTEXT, the result of args[n_arg]- >max_char_length() is 4,294,967,295(Maximum value of LONGTEXT). So args[n_arg]->max_char_length()+4 will be 3 due to overflow. And there is no overflow when calling based on TEXT.

      I will make a patch to this issue. I would be very grateful if you can handle it soon.

      same issues exist in JSON_OBJECT, JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)

      Attachments

        Activity

          lunar_land ziyitan created issue -
          lunar_land ziyitan made changes -
          Field Original Value New Value
          Description Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key1"] |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{ args[n_arg]->max_char_length() }} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{ args[n_arg]->max_char_length() }} is 4,294,967,295(Maximum value of LONGTEXT). So {{ args[n_arg]->max_char_length() + 4 }} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{ args[n_arg]->max_char_length() }} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{ args[n_arg]->max_char_length() }} is 4,294,967,295(Maximum value of LONGTEXT). So {{ args[n_arg]->max_char_length() + 4 }} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          lunar_land ziyitan made changes -
          Description Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{ args[n_arg]->max_char_length() }} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{ args[n_arg]->max_char_length() }} is 4,294,967,295(Maximum value of LONGTEXT). So {{ args[n_arg]->max_char_length() + 4 }} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{ args[n_arg]->max_char_length() }} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{ args[n_arg]->max_char_length() }} is 4,294,967,295(Maximum value of LONGTEXT). So {{ args[n_arg]->max_char_length() + 4 }} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          lunar_land ziyitan made changes -
          Description Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{ args[n_arg]->max_char_length() }} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{ args[n_arg]->max_char_length() }} is 4,294,967,295(Maximum value of LONGTEXT). So {{ args[n_arg]->max_char_length() + 4 }} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{args[n_arg]->max_char_length()}} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{args[n_arg]->max_char_length()}} is 4,294,967,295(Maximum value of LONGTEXT). So {{args[n_arg]->max_char_length()+4}} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          lunar_land ziyitan made changes -
          Description Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{args[n_arg]->max_char_length()}} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{args[n_arg]->max_char_length()}} is 4,294,967,295(Maximum value of LONGTEXT). So {{args[n_arg]->max_char_length()+4}} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{args[n_arg]->max_char_length()}} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{args[n_arg]->max_char_length()}} is 4,294,967,295(Maximum value of LONGTEXT). So {{args[n_arg]->max_char_length()+4}} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_OBJECT, JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          lunar_land ziyitan made changes -
          Description Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{args[n_arg]->max_char_length()}} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{args[n_arg]->max_char_length()}} is 4,294,967,295(Maximum value of LONGTEXT). So {{args[n_arg]->max_char_length()+4}} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_OBJECT, JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{args[n_arg]- >max_char_length()}} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{args[n_arg]- >max_char_length()}} is 4,294,967,295(Maximum value of LONGTEXT). So {{args[n_arg]->max_char_length()+4}} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_OBJECT, JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          lunar_land ziyitan made changes -
          Description Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{args[n_arg]- >max_char_length()}} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{args[n_arg]- >max_char_length()}} is 4,294,967,295(Maximum value of LONGTEXT). So {{args[n_arg]->max_char_length()+4}} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_OBJECT, JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_type.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          Hi, I'm GSoC 2022 contributor, I'm working on the [MCOL-785.|https://jira.mariadb.org/browse/MCOL-785]
          Now I have a problem: *The JSON Function result is truncated when the function is called based on LONGTEXT field.*

          Take the JSON_ARRAY as an example:
          {code:shell}
          MariaDB root@(none):test> create table t1(t TEXT, l LONGTEXT) engine=columnstore;
          Query OK, 0 rows affected
          Time: 0.147s
          MariaDB root@(none):test> insert into t1 values('key1', 'key1');
          Query OK, 1 row affected
          Time: 0.179s
          MariaDB root@(none):test> select json_array(t), json_array(l) from t1;
          +---------------+---------------+
          | json_array(t) | json_array(l) |
          +---------------+---------------+
          | ["key1"] | ["key |
          +---------------+---------------+
          1 row in set
          Time: 0.097s
          MariaDB root@(none):test>
          {code}

          After debugging, I found that such difference is caused by overflow error.
          {code:c++}
          bool Item_func_json_array::fix_length_and_dec(THD *thd)
          {
            ulonglong char_length= 2;
          ...
            for (n_arg=0 ; n_arg < arg_count ; n_arg++)
              char_length+= args[n_arg]->max_char_length() + 4;
          ...
          }
          {code}

          First, the return type of {{args[n_arg]- >max_char_length()}} is uint32, the max value of uint32 is 4,294,967,295.
          When called based on LONGTEXT, the result of {{args[n_arg]- >max_char_length()}} is 4,294,967,295(Maximum value of LONGTEXT). So {{args[n_arg]->max_char_length()+4}} will be 3 due to overflow. And there is no overflow when calling based on TEXT.

          I will make a patch to this issue. I would be very grateful if you can handle it soon.

          same issues exist in {{JSON_OBJECT, JSON_ARRAY_APPEND(INSERT), JSON_INSERT(REPLACE|SET)}}

          * My JSON_ARRAY implementation: [func_json_array.cpp|https://github.com/qggcs/mariadb-columnstore-engine/blob/MCOL-785-ziyi/utils/funcexp/func_json_array.cpp]
          * [Pull Request|https://github.com/mariadb-corporation/mariadb-columnstore-engine/pull/2425]: has been submitted and passed CI)
          alice Alice Sherepa made changes -
          Assignee Rucha Deodhar [ rucha174 ]
          rucha174 Rucha Deodhar made changes -
          Fix Version/s 10.6.9 [ 27507 ]
          Fix Version/s 10.7.5 [ 27505 ]
          Fix Version/s 10.8.4 [ 27503 ]
          Fix Version/s 10.9.2 [ 27115 ]
          Fix Version/s 10.10.1 [ 27913 ]
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]

          People

            rucha174 Rucha Deodhar
            lunar_land ziyitan
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.