From d5150d644c4801bf367cbf3bb091a35249b6b1a8 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Tue, 17 Oct 2023 15:41:52 +0200 Subject: [PATCH] MDEV-32462: mysql_upgrade -s still checks for non system tables - Prevent opening of any user tables in case `upgrade-system-table` option is used. - Still there may be uninstalled data types in `mysql` system table so allow it to perform. - Closes PR #2790 - Reviewer: , --- client/mysql_upgrade.c | 2 + ...ql_json_mysql_upgrade_system_tables.result | 93 +++++++++++++++++++ ...ysql_json_mysql_upgrade_system_tables.test | 52 +++++++++++ 3 files changed, 147 insertions(+) create mode 100644 mysql-test/main/mysql_json_mysql_upgrade_system_tables.result create mode 100644 mysql-test/main/mysql_json_mysql_upgrade_system_tables.test diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index 60eb61938d432..617d5464e34f3 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -1155,6 +1155,8 @@ static int install_used_plugin_data_types(void) DYNAMIC_STRING ds_result; const char *query = "SELECT table_comment FROM information_schema.tables" " WHERE table_comment LIKE 'Unknown data type: %'"; + if (opt_systables_only) + return 0; if (init_dynamic_string(&ds_result, "", 512, 512)) die("Out of memory"); run_query(query, &ds_result, TRUE); diff --git a/mysql-test/main/mysql_json_mysql_upgrade_system_tables.result b/mysql-test/main/mysql_json_mysql_upgrade_system_tables.result new file mode 100644 index 0000000000000..95ca68f43a65a --- /dev/null +++ b/mysql-test/main/mysql_json_mysql_upgrade_system_tables.result @@ -0,0 +1,93 @@ +# +# MDEV-32462: mysql_upgrade -s still checks for non system tables +# +call mtr.add_suppression("Table rebuild required"); +SET NAMES utf8; +# mariadb_upgrade on system and user table +show tables from mysql like '%json%'; +Tables_in_mysql (%json%) +mysql_json_test +use mysql; +show create table mysql.mysql_json_test; +ERROR HY000: Unknown data type: 'MYSQL_JSON' +show create table test.mysql_json_test; +ERROR HY000: Unknown data type: 'MYSQL_JSON' +SET @old_general_log= @@global.general_log; +SET @old_log_output= @@global.log_output; +SET @@global.general_log = ON; +SET @@global.log_output = "TABLE"; +The --upgrade-system-tables option was used, user tables won't be touched. +Phase 1/7: Checking and upgrading mysql database +Processing databases +mysql +mysql.column_stats OK +mysql.columns_priv OK +mysql.db OK +mysql.event OK +mysql.func OK +mysql.global_priv OK +mysql.gtid_slave_pos OK +mysql.help_category OK +mysql.help_keyword OK +mysql.help_relation OK +mysql.help_topic OK +mysql.index_stats OK +mysql.innodb_index_stats +Error : Unknown storage engine 'InnoDB' +error : Corrupt +mysql.innodb_table_stats +Error : Unknown storage engine 'InnoDB' +error : Corrupt +mysql.mysql_json_test +Error : Unknown data type: 'MYSQL_JSON' +error : Corrupt +mysql.plugin OK +mysql.proc OK +mysql.procs_priv OK +mysql.proxies_priv OK +mysql.roles_mapping OK +mysql.servers OK +mysql.table_stats OK +mysql.tables_priv OK +mysql.time_zone OK +mysql.time_zone_leap_second OK +mysql.time_zone_name OK +mysql.time_zone_transition OK +mysql.time_zone_transition_type OK +mysql.transaction_registry +Error : Unknown storage engine 'InnoDB' +error : Corrupt + +Repairing tables +mysql.innodb_index_stats +Error : Unknown storage engine 'InnoDB' +error : Corrupt +mysql.innodb_table_stats +Error : Unknown storage engine 'InnoDB' +error : Corrupt +mysql.mysql_json_test +Error : Unknown data type: 'MYSQL_JSON' +error : Corrupt +mysql.transaction_registry +Error : Unknown storage engine 'InnoDB' +error : Corrupt +Phase 2/7: Installing used storage engines... Skipped +Phase 3/7: Fixing views... Skipped +Phase 4/7: Running 'mysql_fix_privilege_tables' +Phase 5/7: Fixing table and database names ... Skipped +Phase 6/7: Checking and upgrading tables... Skipped +Phase 7/7: Running 'FLUSH PRIVILEGES' +OK +SET @@global.general_log = @old_general_log; +SET @@global.log_output = @old_log_output; +select command_type, argument from mysql.general_log where argument like "%SELECT table_comment FROM information_schema.tables%"; +command_type argument +show create table mysql.mysql_json_test; +ERROR HY000: Unknown data type: 'MYSQL_JSON' +show create table test.mysql_json_test; +ERROR HY000: Unknown data type: 'MYSQL_JSON' +drop table mysql.mysql_json_test; +drop table test.mysql_json_test; +# +# End of 10.5 tests +# diff --git a/mysql-test/main/mysql_json_mysql_upgrade_system_tables.test b/mysql-test/main/mysql_json_mysql_upgrade_system_tables.test new file mode 100644 index 0000000000000..6ae3e8ddea1f4 --- /dev/null +++ b/mysql-test/main/mysql_json_mysql_upgrade_system_tables.test @@ -0,0 +1,52 @@ +--echo # +--echo # MDEV-32462: mysql_upgrade -s still checks for non system tables +--echo # + +# Let's now load plugin first +--source include/have_utf8.inc +--source include/not_embedded.inc + +--source include/mysql_upgrade_preparation.inc +call mtr.add_suppression("Table rebuild required"); + +SET NAMES utf8; + +let $MYSQLD_DATADIR= `select @@datadir`; + +--echo # mariadb_upgrade on system and user table +--copy_file std_data/mysql_json/mysql_json_test.frm $MYSQLD_DATADIR/mysql/mysql_json_test.frm +--copy_file std_data/mysql_json/mysql_json_test.MYI $MYSQLD_DATADIR/mysql/mysql_json_test.MYI +--copy_file std_data/mysql_json/mysql_json_test.MYD $MYSQLD_DATADIR/mysql/mysql_json_test.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 + +show tables from mysql like '%json%'; +use mysql; +--error ER_UNKNOWN_DATA_TYPE +show create table mysql.mysql_json_test; +--error ER_UNKNOWN_DATA_TYPE +show create table test.mysql_json_test; + +SET @old_general_log= @@global.general_log; +SET @old_log_output= @@global.log_output; +SET @@global.general_log = ON; +SET @@global.log_output = "TABLE"; +--exec $MYSQL_UPGRADE -s --force 2>&1 +--remove_file $MYSQLD_DATADIR/mysql_upgrade_info +SET @@global.general_log = @old_general_log; +SET @@global.log_output = @old_log_output; + +select command_type, argument from mysql.general_log where argument like "%SELECT table_comment FROM information_schema.tables%"; + +# User table is not upgraded in `mysql\test` DB, so we cannot see it. +--error ER_UNKNOWN_DATA_TYPE +show create table mysql.mysql_json_test; +--error ER_UNKNOWN_DATA_TYPE +show create table test.mysql_json_test; +drop table mysql.mysql_json_test; +drop table test.mysql_json_test; + +--echo # +--echo # End of 10.5 tests +--echo #