commit 229b98dd5a2d31c23bcc5c8fcf6cf127ef66c47b Author: Laurynas Biveinis Date: Fri May 25 14:27:12 2018 +0300 Fix bug 71761 / PS-1749 (ANALYZE TABLE should remove its table from background stat processing queue) If not under InnoDB read only mode, make InnoDB ANALYZE TABLE remove its table from the background stat processing queue, if it's there. Add a testcase for ANALYZE TABLE under InnoDB read only mode. diff --git a/mysql-test/suite/innodb/r/innodb_read_only_analyze.result b/mysql-test/suite/innodb/r/innodb_read_only_analyze.result new file mode 100644 index 00000000000..cda18cf8361 --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb_read_only_analyze.result @@ -0,0 +1,13 @@ +call mtr.add_suppression("Skip re-populating collations and character sets tables in InnoDB read-only mode."); +CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +SET GLOBAL innodb_fast_shutdown = 0; +# restart: --innodb-read-only +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze Warning InnoDB: Running in read-only mode +test.t1 analyze Error Table 'table_stats' is read only +test.t1 analyze Error Unable to store dynamic table statistics into data dictionary. +test.t1 analyze status Unable to write table statistics to DD tables +# restart +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/innodb_read_only_analyze.test b/mysql-test/suite/innodb/t/innodb_read_only_analyze.test new file mode 100644 index 00000000000..2a4e3adab3d --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb_read_only_analyze.test @@ -0,0 +1,12 @@ +call mtr.add_suppression("Skip re-populating collations and character sets tables in InnoDB read-only mode."); + +CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); + +--source include/restart_innodb_read_only.inc + +ANALYZE TABLE t1; + +--source include/restart_mysqld.inc + +DROP TABLE t1; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index fed9254f104..dc9a3b6a8e2 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -14300,6 +14300,13 @@ int ha_innobase::info_low(uint flag, bool is_analyze) { if (dict_stats_is_persistent_enabled(ib_table)) { if (is_analyze) { + /* If this table is already queued for background analyze, remove it + from the queue as we are about to do the same */ + if (!srv_read_only_mode) { + dict_mutex_enter_for_mysql(); + dict_stats_recalc_pool_del(ib_table); + dict_mutex_exit_for_mysql(); + } opt = DICT_STATS_RECALC_PERSISTENT; } else { /* This is e.g. 'SHOW INDEXES', fetch