commit 2c313c8f88e39916cd477cf5fa3c842ec35911bd Author: Laurynas Biveinis Date: Tue Sep 27 13:01:54 2016 +0300 Fix bug 71761 / 1626441 (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 786eda39922..d7b3ca64286 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -16028,6 +16028,18 @@ ha_innobase::info_low( 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