Skip to content

Commit 8a763c0

Browse files
an3labarkov
authored andcommitted
MDEV-32235: mysql_json cannot be used on newly created table
- Closes PR #2839 - Usage of `Column_definition_fix_attributes()` suggested by Alexandar Barkov - thanks bar, that is better than hook in server code (reverted 22f3ebe) - This method is called after parsing the data type: * in `CREATE/ALTER TABLE` * in SP: return data type, parameter data type, variable data type - We want to disallow all these use cases of MYSQL_JSON. - Reviewer: bar@mariadb.com cvicentiu@mariadb.org
1 parent 8b5c1d5 commit 8a763c0

File tree

3 files changed

+76
-8
lines changed

3 files changed

+76
-8
lines changed

mysql-test/main/mysql_json_table_recreate.result

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ show create table mysql_json_test;
3030
ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.mysql_json_test` FORCE" or dump/reload to fix it!
3131
select * from mysql_json_test;
3232
ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.mysql_json_test` FORCE" or dump/reload to fix it!
33+
CREATE TABLE t2 AS SELECT * FROM mysql_json_test;
34+
ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.mysql_json_test` FORCE" or dump/reload to fix it!
35+
CREATE TABLE t2 (a mysql_json /*new column*/) AS SELECT * FROM mysql_json_test;
36+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
37+
CREATE TABLE t2 (actual mysql_json /*existing column*/) AS SELECT * FROM mysql_json_test;
38+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
3339
LOCK TABLES mysql_json_test WRITE;
3440
ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.mysql_json_test` FORCE" or dump/reload to fix it!
3541
alter table mysql_json_test force;
@@ -181,12 +187,7 @@ t1 CREATE TABLE `t1` (
181187
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
182188
drop table t1;
183189
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+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
190191
create table `testjson` (
191192
`t` json /* JSON from MySQL 5.7*/ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
192193
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
@@ -211,5 +212,30 @@ testjson CREATE TABLE `testjson` (
211212
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
212213
drop table testjson;
213214
#
215+
# MDEV-32235: mysql_json cannot be used on newly created table
216+
#
217+
CREATE TABLE t(j mysql_json);
218+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
219+
CREATE TABLE IF NOT EXISTS t(j mysql_json);
220+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
221+
CREATE OR REPLACE TABLE t(j mysql_json);
222+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
223+
CREATE TEMPORARY TABLE t(j mysql_json);
224+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
225+
CREATE TABLE t1 (a TEXT);
226+
ALTER TABLE t1 MODIFY a mysql_json;
227+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
228+
DROP TABLE t1;
229+
CREATE FUNCTION f1() RETURNS mysql_json RETURN NULL;
230+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
231+
CREATE FUNCTION f1(a mysql_json) RETURNS INT RETURN 0;
232+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
233+
CREATE PROCEDURE p1()
234+
BEGIN
235+
DECLARE a mysql_json;
236+
END;
237+
$$
238+
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
239+
#
214240
# End of 10.5 tests
215241
#

mysql-test/main/mysql_json_table_recreate.test

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ show create table mysql_json_test;
5151
--error ER_TABLE_NEEDS_REBUILD
5252
select * from mysql_json_test;
5353

54+
--error ER_TABLE_NEEDS_REBUILD
55+
CREATE TABLE t2 AS SELECT * FROM mysql_json_test;
56+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
57+
CREATE TABLE t2 (a mysql_json /*new column*/) AS SELECT * FROM mysql_json_test;
58+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
59+
CREATE TABLE t2 (actual mysql_json /*existing column*/) AS SELECT * FROM mysql_json_test;
60+
5461
--error ER_TABLE_NEEDS_REBUILD
5562
LOCK TABLES mysql_json_test WRITE;
5663

@@ -97,9 +104,8 @@ drop table mysql_json_test_big;
97104
create table t1(j json);
98105
show create table t1;
99106
drop table t1;
107+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
100108
create table t1(j mysql_json);
101-
show create table t1;
102-
drop table t1;
103109
# `json` type should not have character set and collation other than utf8mb4_bin
104110
--error ER_PARSE_ERROR
105111
create table `testjson` (
@@ -121,6 +127,37 @@ create table `testjson` (
121127
show create table testjson;
122128
drop table testjson;
123129

130+
--echo #
131+
--echo # MDEV-32235: mysql_json cannot be used on newly created table
132+
--echo #
133+
134+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
135+
CREATE TABLE t(j mysql_json);
136+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
137+
CREATE TABLE IF NOT EXISTS t(j mysql_json);
138+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
139+
CREATE OR REPLACE TABLE t(j mysql_json);
140+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
141+
CREATE TEMPORARY TABLE t(j mysql_json);
142+
143+
CREATE TABLE t1 (a TEXT);
144+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
145+
ALTER TABLE t1 MODIFY a mysql_json;
146+
DROP TABLE t1;
147+
148+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
149+
CREATE FUNCTION f1() RETURNS mysql_json RETURN NULL;
150+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
151+
CREATE FUNCTION f1(a mysql_json) RETURNS INT RETURN 0;
152+
DELIMITER $$;
153+
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
154+
CREATE PROCEDURE p1()
155+
BEGIN
156+
DECLARE a mysql_json;
157+
END;
158+
$$
159+
DELIMITER ;$$
160+
124161
--echo #
125162
--echo # End of 10.5 tests
126163
--echo #

plugin/type_mysql_json/type.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class Type_handler_mysql_json: public Type_handler_blob
3737
Field *make_table_field(MEM_ROOT *, const LEX_CSTRING *,
3838
const Record_addr &, const Type_all_attributes &,
3939
TABLE_SHARE *) const override;
40+
bool Column_definition_fix_attributes(Column_definition *c) const override
41+
{
42+
my_error(ER_NOT_ALLOWED_IN_THIS_CONTEXT, MYF(0), "MYSQL_JSON");
43+
return true;
44+
}
4045
void Column_definition_reuse_fix_attributes(THD *thd,
4146
Column_definition *def,
4247
const Field *field) const override;

0 commit comments

Comments
 (0)