Commit f807a9f8 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-31523 Using two temporary tables in OPTIMIZE TABLE lead to crash

Fixed typo in mysql_admin_table which cused call of
close_unused_temporary_table_instances alwas for the first table
instead of the current table.

Added ASSERT that close_unused_temporary_table_instances should not
remove all instances of user created temporary table.
parent 88c46aba
......@@ -602,3 +602,19 @@ DROP TEMPORARY TABLE t1;
#
# End of 10.2 tests
#
#
# MDEV-31523: Using two temporary tables in OPTIMIZE TABLE lead to crash
#
CREATE TEMPORARY TABLE t1 (c INT) ENGINE=MyISAM;
CREATE TEMPORARY TABLE t2 (c INT) ENGINE=MyISAM;
optimize TABLE t1,t2;
Table Op Msg_type Msg_text
test.t1 optimize status Table is already up to date
test.t2 optimize status Table is already up to date
SHOW TABLES;
Tables_in_test
# in 11.2 and above here should be listed above used temporary tables
DROP TEMPORARY TABLE t1, t2;
#
# End of 10.4 tests
#
......@@ -661,3 +661,19 @@ DROP TEMPORARY TABLE t1;
--echo #
--echo # End of 10.2 tests
--echo #
--echo #
--echo # MDEV-31523: Using two temporary tables in OPTIMIZE TABLE lead to crash
--echo #
CREATE TEMPORARY TABLE t1 (c INT) ENGINE=MyISAM;
CREATE TEMPORARY TABLE t2 (c INT) ENGINE=MyISAM;
optimize TABLE t1,t2;
SHOW TABLES;
--echo # in 11.2 and above here should be listed above used temporary tables
DROP TEMPORARY TABLE t1, t2;
--echo #
--echo # End of 10.4 tests
--echo #
......@@ -776,7 +776,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
if (lock_type == TL_WRITE && table->mdl_request.type > MDL_SHARED_WRITE)
{
if (table->table->s->tmp_table)
thd->close_unused_temporary_table_instances(tables);
thd->close_unused_temporary_table_instances(table);
else
{
if (wait_while_table_is_used(thd, table->table, HA_EXTRA_NOT_USED))
......
......@@ -1577,6 +1577,11 @@ void THD::close_unused_temporary_table_instances(const TABLE_LIST *tl)
{
/* Note: removing current list element doesn't invalidate iterator. */
share->all_tmp_tables.remove(table);
/*
At least one instance should be left (guaratead by calling this
function for table which is opened and the table is under processing)
*/
DBUG_ASSERT(share->all_tmp_tables.front());
free_temporary_table(table);
}
}
......
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