Skip to content

Commit 9a5f85d

Browse files
committed
MDEV-32790: Output result in show create table for mysql_json type should be longtext
- We don't test `json` MySQL tables from `std_data` since the error `ER_TABLE_NEEDS_REBUILD ` is invoked. However MDEV-32235 will override this test after merge, but leave it to show behavior and historical changes. - Closes PR #2833 Reviewer: <cvicentiu@mariadb.org> <serg@mariadb.com>
1 parent 9e9e0b9 commit 9a5f85d

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

mysql-test/main/mysql_json_table_recreate.result

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,47 @@ Total_Number_of_Tests Succesful_Tests String_is_valid_JSON
169169
drop table tempty;
170170
drop table mysql_json_test;
171171
drop table mysql_json_test_big;
172+
#
173+
# MDEV-32790: Output result in show create table
174+
# for mysql_json type should be longtext
175+
#
176+
create table t1(j json);
177+
show create table t1;
178+
Table Create Table
179+
t1 CREATE TABLE `t1` (
180+
`j` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`j`))
181+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
182+
drop table t1;
183+
create table t1(j mysql_json);
184+
show create table t1;
185+
Table Create Table
186+
t1 CREATE TABLE `t1` (
187+
`j` mysql_json /* JSON from MySQL 5.7 */ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
188+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
189+
drop table t1;
190+
create table `testjson` (
191+
`t` json /* JSON from MySQL 5.7*/ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
192+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
193+
ERROR 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 NOT NULL
194+
) ENGINE=InnoDB DEFAULT CH...' at line 2
195+
create table `testjson` (
196+
`t` json /* JSON from MySQL 5.7*/ COLLATE utf8mb4_bin NOT NULL
197+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
198+
show create table testjson;
199+
Table Create Table
200+
testjson CREATE TABLE `testjson` (
201+
`t` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`t`))
202+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
203+
drop table testjson;
204+
create table `testjson` (
205+
`t` longtext /* JSON from MySQL 5.7 */ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
206+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
207+
show create table testjson;
208+
Table Create Table
209+
testjson CREATE TABLE `testjson` (
210+
`t` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
211+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
212+
drop table testjson;
213+
#
214+
# End of 10.5 tests
215+
#

mysql-test/main/mysql_json_table_recreate.test

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,39 @@ from mysql_json_test_big;
8888
drop table tempty;
8989
drop table mysql_json_test;
9090
drop table mysql_json_test_big;
91+
92+
--echo #
93+
--echo # MDEV-32790: Output result in show create table
94+
--echo # for mysql_json type should be longtext
95+
--echo #
96+
97+
create table t1(j json);
98+
show create table t1;
99+
drop table t1;
100+
create table t1(j mysql_json);
101+
show create table t1;
102+
drop table t1;
103+
# `json` type should not have character set and collation other than utf8mb4_bin
104+
--error ER_PARSE_ERROR
105+
create table `testjson` (
106+
`t` json /* JSON from MySQL 5.7*/ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
107+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
108+
109+
# By removing character set from `json` field query should work and
110+
# expand to `longtext` with characterset
111+
create table `testjson` (
112+
`t` json /* JSON from MySQL 5.7*/ COLLATE utf8mb4_bin NOT NULL
113+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
114+
show create table testjson;
115+
drop table testjson;
116+
117+
# `longtext` that is alias can have character set
118+
create table `testjson` (
119+
`t` longtext /* JSON from MySQL 5.7 */ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
120+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
121+
show create table testjson;
122+
drop table testjson;
123+
124+
--echo #
125+
--echo # End of 10.5 tests
126+
--echo #

plugin/type_mysql_json/type.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Field_mysql_json: public Field_blob
6262
bool parse_mysql(String *dest, const char *data, size_t length) const;
6363
bool send(Protocol *protocol) { return Field::send(protocol); }
6464
void sql_type(String &s) const
65-
{ s.set_ascii(STRING_WITH_LEN("json /* MySQL 5.7 */")); }
65+
{ s.set_ascii(STRING_WITH_LEN("mysql_json /* JSON from MySQL 5.7 */")); }
6666
/* this will make ALTER TABLE to consider it different from built-in field */
6767
Compression_method *compression_method() const { return (Compression_method*)1; }
6868
};

0 commit comments

Comments
 (0)