Commit d28ac3f8 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-34207: ALTER TABLE...STATS_PERSISTENT=0 fails to drop statistics

commit_try_norebuild(): If the STATS_PERSISTENT attribute of the table
is being changed to disabled, drop the persistent statistics of the table.
parent f199dffe
...@@ -82,4 +82,22 @@ WHERE database_name='test' AND table_name='t1' AND stat_name='size'; ...@@ -82,4 +82,22 @@ WHERE database_name='test' AND table_name='t1' AND stat_name='size';
TIMESTAMPDIFF(DAY,last_update,now())<=1 TIMESTAMPDIFF(DAY,last_update,now())<=1
1 1
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-34207: ALTER TABLE...STATS_PERSISTENT=0 fails to drop statistics
#
CREATE TABLE t1 (c1 INT) ENGINE=InnoDB STATS_PERSISTENT 1;
ALTER TABLE t1 STATS_PERSISTENT 0;
DROP TABLE t1;
SET @save_persistent=@@GLOBAL.innodb_stats_persistent;
SET GLOBAL innodb_stats_persistent=1;
CREATE TABLE t2 (c1 INT) ENGINE=InnoDB;
RENAME TABLE t2 TO t1;
DROP TABLE t1;
SET GLOBAL innodb_stats_persistent=0;
CREATE TABLE t2 (c1 INT) ENGINE=InnoDB STATS_PERSISTENT 1;
RENAME TABLE t2 TO t1;
SET GLOBAL innodb_stats_persistent=@save_persistent;
DROP TABLE t1;
CREATE TABLE t1 (c1 INT) ENGINE=InnoDB STATS_PERSISTENT 1;
DROP TABLE t1;
# End of 10.6 tests # End of 10.6 tests
...@@ -80,5 +80,29 @@ SELECT TIMESTAMPDIFF(DAY,last_update,now())<=1 FROM mysql.innodb_index_stats ...@@ -80,5 +80,29 @@ SELECT TIMESTAMPDIFF(DAY,last_update,now())<=1 FROM mysql.innodb_index_stats
WHERE database_name='test' AND table_name='t1' AND stat_name='size'; WHERE database_name='test' AND table_name='t1' AND stat_name='size';
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-34207: ALTER TABLE...STATS_PERSISTENT=0 fails to drop statistics
--echo #
CREATE TABLE t1 (c1 INT) ENGINE=InnoDB STATS_PERSISTENT 1;
ALTER TABLE t1 STATS_PERSISTENT 0;
DROP TABLE t1;
SET @save_persistent=@@GLOBAL.innodb_stats_persistent;
SET GLOBAL innodb_stats_persistent=1;
CREATE TABLE t2 (c1 INT) ENGINE=InnoDB;
RENAME TABLE t2 TO t1;
DROP TABLE t1;
SET GLOBAL innodb_stats_persistent=0;
CREATE TABLE t2 (c1 INT) ENGINE=InnoDB STATS_PERSISTENT 1;
RENAME TABLE t2 TO t1;
SET GLOBAL innodb_stats_persistent=@save_persistent;
DROP TABLE t1;
CREATE TABLE t1 (c1 INT) ENGINE=InnoDB STATS_PERSISTENT 1;
DROP TABLE t1;
--echo # End of 10.6 tests --echo # End of 10.6 tests
...@@ -10597,6 +10597,16 @@ commit_try_norebuild( ...@@ -10597,6 +10597,16 @@ commit_try_norebuild(
dict_index_t* index; dict_index_t* index;
const char *op = "rename index to add"; const char *op = "rename index to add";
ulint num_fts_index = 0; ulint num_fts_index = 0;
const bool statistics_drop = statistics_exist
&& ((HA_OPTION_NO_STATS_PERSISTENT |
HA_OPTION_STATS_PERSISTENT)
& (old_table->s->db_create_options
^ altered_table->s->db_create_options))
&& ((altered_table->s->db_create_options
& HA_OPTION_NO_STATS_PERSISTENT)
|| (!(altered_table->s->db_create_options
& HA_OPTION_STATS_PERSISTENT)
&& !srv_stats_persistent));
/* We altered the table in place. Mark the indexes as committed. */ /* We altered the table in place. Mark the indexes as committed. */
for (ulint i = 0; i < ctx->num_to_add_index; i++) { for (ulint i = 0; i < ctx->num_to_add_index; i++) {
...@@ -10619,7 +10629,8 @@ commit_try_norebuild( ...@@ -10619,7 +10629,8 @@ commit_try_norebuild(
} }
char db[MAX_DB_UTF8_LEN], table[MAX_TABLE_UTF8_LEN]; char db[MAX_DB_UTF8_LEN], table[MAX_TABLE_UTF8_LEN];
if (ctx->num_to_drop_index) {
if (statistics_exist && (statistics_drop || ctx->num_to_drop_index)) {
dict_fs2utf8(ctx->old_table->name.m_name, dict_fs2utf8(ctx->old_table->name.m_name,
db, sizeof db, table, sizeof table); db, sizeof db, table, sizeof table);
} }
...@@ -10654,7 +10665,7 @@ commit_try_norebuild( ...@@ -10654,7 +10665,7 @@ commit_try_norebuild(
goto handle_error; goto handle_error;
} }
if (!statistics_exist) { if (!statistics_exist || statistics_drop) {
continue; continue;
} }
...@@ -10670,6 +10681,25 @@ commit_try_norebuild( ...@@ -10670,6 +10681,25 @@ commit_try_norebuild(
} }
if (!statistics_exist) { if (!statistics_exist) {
} else if (statistics_drop) {
error = dict_stats_delete_from_table_stats(db, table, trx);
switch (error) {
case DB_SUCCESS:
case DB_STATS_DO_NOT_EXIST:
break;
default:
goto handle_error;
}
error = dict_stats_delete_from_index_stats(db, table, trx);
switch (error) {
case DB_STATS_DO_NOT_EXIST:
error = DB_SUCCESS;
/* fall through */
case DB_SUCCESS:
break;
default:
goto handle_error;
}
} else if (const size_t size = ha_alter_info->rename_keys.size()) { } else if (const size_t size = ha_alter_info->rename_keys.size()) {
char tmp_name[5]; char tmp_name[5];
char db[MAX_DB_UTF8_LEN], table[MAX_TABLE_UTF8_LEN]; char db[MAX_DB_UTF8_LEN], table[MAX_TABLE_UTF8_LEN];
......
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