mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
MDEV-18323 Convert MySQL JSON type to MariaDB TEXT in mysql_upgrade
This patch solves two key problems. 1. There is a type number clash between MySQL and MariaDB. The number 245, used for MariaDB Virtual Fields is the same as MySQL's JSON. This leads to corrupt FRM errors if unhandled. The code properly checks frm table version number and if it matches 5.7+ (until 10.0+) it will assume it is dealing with a MySQL table with the JSON datatype. 2. MySQL JSON datatype uses a proprietary format to pack JSON data. The patch introduces a datatype plugin which parses the format and convers it to its string representation. The intended conversion path is to only use the JSON datatype within ALTER TABLE <table> FORCE, to force a table recreate. This happens during mysql_upgrade or via a direct ALTER TABLE <table> FORCE.
This commit is contained in:
89
mysql-test/main/mysql_json_table_recreate.test
Normal file
89
mysql-test/main/mysql_json_table_recreate.test
Normal file
@ -0,0 +1,89 @@
|
||||
--source include/have_utf8.inc
|
||||
|
||||
--echo #
|
||||
--echo # The following test takes 2 tables containing a JSON column and attempts
|
||||
--echo # to repair them.
|
||||
--echo #
|
||||
--echo # The tables header is (Description, Expected, Actual), where description
|
||||
--echo # shows a brief description what the JSON value is testing in the MariaDB
|
||||
--echo # implementation. Expected is the longtext string and actual is the JSON
|
||||
--echo # column that needs to be converted to MariaDB's representation of
|
||||
--echo # LONGTEXT.
|
||||
--echo #
|
||||
|
||||
|
||||
call mtr.add_suppression("Table rebuild required");
|
||||
call mtr.add_suppression("is marked as crashed");
|
||||
call mtr.add_suppression("Checking");
|
||||
|
||||
let $MYSQLD_DATADIR= `select @@datadir`;
|
||||
|
||||
SET NAMES utf8;
|
||||
|
||||
--copy_file std_data/mysql_json/tempty.frm $MYSQLD_DATADIR/test/tempty.frm
|
||||
--copy_file std_data/mysql_json/tempty.MYI $MYSQLD_DATADIR/test/tempty.MYI
|
||||
--copy_file std_data/mysql_json/tempty.MYD $MYSQLD_DATADIR/test/tempty.MYD
|
||||
|
||||
--copy_file std_data/mysql_json/mysql_json_test.frm $MYSQLD_DATADIR/test/mysql_json_test.frm
|
||||
--copy_file std_data/mysql_json/mysql_json_test.MYI $MYSQLD_DATADIR/test/mysql_json_test.MYI
|
||||
--copy_file std_data/mysql_json/mysql_json_test.MYD $MYSQLD_DATADIR/test/mysql_json_test.MYD
|
||||
|
||||
--copy_file std_data/mysql_json/mysql_json_test_big.frm $MYSQLD_DATADIR/test/mysql_json_test_big.frm
|
||||
--copy_file std_data/mysql_json/mysql_json_test_big.MYI $MYSQLD_DATADIR/test/mysql_json_test_big.MYI
|
||||
--copy_file std_data/mysql_json/mysql_json_test_big.MYD $MYSQLD_DATADIR/test/mysql_json_test_big.MYD
|
||||
|
||||
--echo #
|
||||
--echo # Check that only ALTER TABLE ... FORCE is allowed on a MySQL 5.7 table
|
||||
--echo # with a JSON column.
|
||||
--echo #
|
||||
|
||||
--error ER_TABLE_NEEDS_REBUILD
|
||||
show create table tempty;
|
||||
--error ER_TABLE_NEEDS_REBUILD
|
||||
select * from tempty;
|
||||
|
||||
alter table tempty force;
|
||||
show create table tempty;
|
||||
|
||||
--error ER_TABLE_NEEDS_REBUILD
|
||||
show create table mysql_json_test;
|
||||
--error ER_TABLE_NEEDS_REBUILD
|
||||
select * from mysql_json_test;
|
||||
|
||||
--error ER_TABLE_NEEDS_REBUILD
|
||||
LOCK TABLES mysql_json_test WRITE;
|
||||
|
||||
alter table mysql_json_test force;
|
||||
|
||||
--sorted_result
|
||||
select description, expected, actual, expected = actual from mysql_json_test;
|
||||
|
||||
--echo #
|
||||
--echo # A quick check that all rows match from the original MySQL Table.
|
||||
--echo #
|
||||
select count(*) as 'Total_Number_of_Tests',
|
||||
sum(expected = actual) as 'Succesful_Tests'
|
||||
from mysql_json_test;
|
||||
|
||||
show create table mysql_json_test;
|
||||
|
||||
--error ER_TABLE_NEEDS_REBUILD
|
||||
show create table mysql_json_test_big;
|
||||
--error ER_TABLE_NEEDS_REBUILD
|
||||
select * from mysql_json_test_big;
|
||||
|
||||
--echo #
|
||||
--echo # This test checks the long format implementation of MySQL's JSON
|
||||
--echo # Not printing the actual contents as they are not readable by a human,
|
||||
--echo # just compare the strings, make sure they match.
|
||||
--echo #
|
||||
alter table mysql_json_test_big force;
|
||||
|
||||
select count(*) as 'Total_Number_of_Tests',
|
||||
sum(expected = actual) as 'Succesful_Tests',
|
||||
sum(JSON_VALID(actual)) as 'String_is_valid_JSON'
|
||||
from mysql_json_test_big;
|
||||
|
||||
drop table tempty;
|
||||
drop table mysql_json_test;
|
||||
drop table mysql_json_test_big;
|
Reference in New Issue
Block a user