[MDEV-32790] Output result in show create table for mysql_json type should be longtext Created: 2023-11-13  Updated: 2024-01-11  Resolved: 2024-01-11

Status: Closed
Project: MariaDB Server
Component/s: Data types, JSON
Affects Version/s: 10.5.22
Fix Version/s: 10.5.24, 10.6.17, 10.11.7, 11.0.5, 11.1.4, 11.2.3

Type: Bug Priority: Major
Reporter: Anel Husakovic Assignee: Anel Husakovic
Resolution: Fixed Votes: 0
Labels: None


 Description   

MariaDB [mysql_data_json]> CREATE TABLE testjson (t mysql_json NOT NULL);
ERROR 4161 (HY000): Unknown data type: 'mysql_json'
 
MariaDB [mysql_data_json]> install soname 'type_mysql_json';
Query OK, 0 rows affected (0.015 sec)
 
MariaDB [mysql_data_json]> CREATE TABLE testjson (t mysql_json NOT NULL);
Query OK, 0 rows affected (0.031 sec)
 
MariaDB [mysql_data_json]> show create table testjson;
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                                                                                                             |
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| testjson | CREATE TABLE `testjson` (
  `t` json /* MySQL 5.7 */ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci |
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

Using above query we will get an syntax error

CREATE TABLE `t2` (
    ->   `j` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`j`))
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`j`)...' at line 2

However, if instead of json, longtext is specified, than the result is good.

So, JSON datatype field shouldn't have any character set and collation, except of default utf8mb4|utf8mb4_bin.



 Comments   
Comment by Vicențiu Ciorbaru [ 2023-11-28 ]

As mentioned in the PR:

We shouldn't allow create table (c mysql_json) in the first place. The datatype comment change is ok.

Comment by Anel Husakovic [ 2023-12-01 ]

Hi cvicentiu,
in order to address this bug we have to create the table with `mysql_json` field type.
Using MySQL files from `std_data` will raise `ER_TABLE_NEEDS_REBUILD` and that's why we couldn't even catch this bug before.
So I'm suggesting to merge this PR to have logical sequence of changes in git history.
After merge, I will update PR #2839 (MDEV-32235: mysql_json cannot be used on newly created table) accordingly.

Comment by Anel Husakovic [ 2024-01-11 ]

Pushed to 10.5 with 9a5f85dcb

Generated at Thu Feb 08 10:34:02 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.