Commit 8a763c01 authored by Anel Husakovic's avatar Anel Husakovic Committed by Alexander Barkov

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 22f3ebe4)
  - 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
parent 8b5c1d5a
......@@ -30,6 +30,12 @@ show create table mysql_json_test;
ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.mysql_json_test` FORCE" or dump/reload to fix it!
select * from mysql_json_test;
ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.mysql_json_test` FORCE" or dump/reload to fix it!
CREATE TABLE t2 AS SELECT * FROM mysql_json_test;
ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.mysql_json_test` FORCE" or dump/reload to fix it!
CREATE TABLE t2 (a mysql_json /*new column*/) AS SELECT * FROM mysql_json_test;
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
CREATE TABLE t2 (actual mysql_json /*existing column*/) AS SELECT * FROM mysql_json_test;
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
LOCK TABLES mysql_json_test WRITE;
ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.mysql_json_test` FORCE" or dump/reload to fix it!
alter table mysql_json_test force;
......@@ -181,12 +187,7 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t1;
create table t1(j mysql_json);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`j` mysql_json /* JSON from MySQL 5.7 */ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t1;
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
create table `testjson` (
`t` json /* JSON from MySQL 5.7*/ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
......@@ -211,5 +212,30 @@ testjson CREATE TABLE `testjson` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table testjson;
#
# MDEV-32235: mysql_json cannot be used on newly created table
#
CREATE TABLE t(j mysql_json);
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
CREATE TABLE IF NOT EXISTS t(j mysql_json);
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
CREATE OR REPLACE TABLE t(j mysql_json);
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
CREATE TEMPORARY TABLE t(j mysql_json);
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
CREATE TABLE t1 (a TEXT);
ALTER TABLE t1 MODIFY a mysql_json;
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
DROP TABLE t1;
CREATE FUNCTION f1() RETURNS mysql_json RETURN NULL;
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
CREATE FUNCTION f1(a mysql_json) RETURNS INT RETURN 0;
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
CREATE PROCEDURE p1()
BEGIN
DECLARE a mysql_json;
END;
$$
ERROR HY000: 'MYSQL_JSON' is not allowed in this context
#
# End of 10.5 tests
#
......@@ -51,6 +51,13 @@ show create table mysql_json_test;
--error ER_TABLE_NEEDS_REBUILD
select * from mysql_json_test;
--error ER_TABLE_NEEDS_REBUILD
CREATE TABLE t2 AS SELECT * FROM mysql_json_test;
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
CREATE TABLE t2 (a mysql_json /*new column*/) AS SELECT * FROM mysql_json_test;
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
CREATE TABLE t2 (actual mysql_json /*existing column*/) AS SELECT * FROM mysql_json_test;
--error ER_TABLE_NEEDS_REBUILD
LOCK TABLES mysql_json_test WRITE;
......@@ -97,9 +104,8 @@ drop table mysql_json_test_big;
create table t1(j json);
show create table t1;
drop table t1;
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
create table t1(j mysql_json);
show create table t1;
drop table t1;
# `json` type should not have character set and collation other than utf8mb4_bin
--error ER_PARSE_ERROR
create table `testjson` (
......@@ -121,6 +127,37 @@ create table `testjson` (
show create table testjson;
drop table testjson;
--echo #
--echo # MDEV-32235: mysql_json cannot be used on newly created table
--echo #
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
CREATE TABLE t(j mysql_json);
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
CREATE TABLE IF NOT EXISTS t(j mysql_json);
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
CREATE OR REPLACE TABLE t(j mysql_json);
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
CREATE TEMPORARY TABLE t(j mysql_json);
CREATE TABLE t1 (a TEXT);
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
ALTER TABLE t1 MODIFY a mysql_json;
DROP TABLE t1;
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
CREATE FUNCTION f1() RETURNS mysql_json RETURN NULL;
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
CREATE FUNCTION f1(a mysql_json) RETURNS INT RETURN 0;
DELIMITER $$;
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
CREATE PROCEDURE p1()
BEGIN
DECLARE a mysql_json;
END;
$$
DELIMITER ;$$
--echo #
--echo # End of 10.5 tests
--echo #
......@@ -37,6 +37,11 @@ class Type_handler_mysql_json: public Type_handler_blob
Field *make_table_field(MEM_ROOT *, const LEX_CSTRING *,
const Record_addr &, const Type_all_attributes &,
TABLE_SHARE *) const override;
bool Column_definition_fix_attributes(Column_definition *c) const override
{
my_error(ER_NOT_ALLOWED_IN_THIS_CONTEXT, MYF(0), "MYSQL_JSON");
return true;
}
void Column_definition_reuse_fix_attributes(THD *thd,
Column_definition *def,
const Field *field) const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment