Skip to content

Commit

Permalink
MDEV-31607 ER_DUP_KEY in mysql.innodb_table_stats upon RENAME on sequ…
Browse files Browse the repository at this point in the history
…ence

ha_innobase::delete_table(): Also on DROP SEQUENCE, do try to drop any
persistent statistics. They should really not be created for
SEQUENCE objects (which internally are 1-row no-rollback tables),
but that is how happened to always work.
  • Loading branch information
dr-m committed Jul 3, 2023
1 parent dc1bd18 commit f7b8a2c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
14 changes: 14 additions & 0 deletions mysql-test/suite/sql_sequence/alter.result
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,17 @@ SELECT NEXTVAL(s);
NEXTVAL(s)
1
DROP SEQUENCE s;
#
# MDEV-31607 ER_DUP_KEY in mysql.table_stats upon REANME on sequence
#
CREATE SEQUENCE s1 ENGINE=InnoDB;
CREATE SEQUENCE s2 ENGINE=InnoDB;
SHOW CREATE SEQUENCE s1;
Table Create Table
s1 CREATE SEQUENCE `s1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB
SHOW CREATE SEQUENCE s2;
Table Create Table
s2 CREATE SEQUENCE `s2` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB
DROP SEQUENCE s2;
RENAME TABLE s1 TO s2;
DROP SEQUENCE s2;
12 changes: 12 additions & 0 deletions mysql-test/suite/sql_sequence/alter.test
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,15 @@ CREATE SEQUENCE s;
ALTER TABLE s ORDER BY cache_size;
SELECT NEXTVAL(s);
DROP SEQUENCE s;

--echo #
--echo # MDEV-31607 ER_DUP_KEY in mysql.table_stats upon REANME on sequence
--echo #

CREATE SEQUENCE s1 ENGINE=InnoDB;
CREATE SEQUENCE s2 ENGINE=InnoDB;
SHOW CREATE SEQUENCE s1;
SHOW CREATE SEQUENCE s2;
DROP SEQUENCE s2;
RENAME TABLE s1 TO s2;
DROP SEQUENCE s2;
11 changes: 5 additions & 6 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13748,13 +13748,12 @@ int ha_innobase::delete_table(const char *name)
}

if (!table->no_rollback())
{
err= trx->drop_table_foreign(table->name);
if (err == DB_SUCCESS && table_stats && index_stats)
err= trx->drop_table_statistics(table->name);
if (err != DB_SUCCESS)
goto err_exit;
}

if (err == DB_SUCCESS && table_stats && index_stats)
err= trx->drop_table_statistics(table->name);
if (err != DB_SUCCESS)
goto err_exit;

err= trx->drop_table(*table);
if (err != DB_SUCCESS)
Expand Down

0 comments on commit f7b8a2c

Please sign in to comment.