mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 02:05:57 +01:00
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.
This commit is contained in:
parent
f199dffe3b
commit
d28ac3f82d
3 changed files with 74 additions and 2 deletions
|
@ -82,4 +82,22 @@ WHERE database_name='test' AND table_name='t1' AND stat_name='size';
|
|||
TIMESTAMPDIFF(DAY,last_update,now())<=1
|
||||
1
|
||||
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
|
||||
|
|
|
@ -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';
|
||||
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
|
||||
|
|
|
@ -10597,6 +10597,16 @@ commit_try_norebuild(
|
|||
dict_index_t* index;
|
||||
const char *op = "rename index to add";
|
||||
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. */
|
||||
for (ulint i = 0; i < ctx->num_to_add_index; i++) {
|
||||
|
@ -10619,7 +10629,8 @@ commit_try_norebuild(
|
|||
}
|
||||
|
||||
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,
|
||||
db, sizeof db, table, sizeof table);
|
||||
}
|
||||
|
@ -10654,7 +10665,7 @@ commit_try_norebuild(
|
|||
goto handle_error;
|
||||
}
|
||||
|
||||
if (!statistics_exist) {
|
||||
if (!statistics_exist || statistics_drop) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -10670,6 +10681,25 @@ commit_try_norebuild(
|
|||
}
|
||||
|
||||
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()) {
|
||||
char tmp_name[5];
|
||||
char db[MAX_DB_UTF8_LEN], table[MAX_TABLE_UTF8_LEN];
|
||||
|
|
Loading…
Add table
Reference in a new issue