Commit f53321cb authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-20471 Assertion during cleanup of failed CREATE TABLE LIKE <sequence>

While cleaning up a failed CREATE TABLE LIKE <sequence>, `mysql_rm_table_no_locks`
erroneously attempted to remove all tables involved in the query, including
the source table (sequence).

Fix to temporarily modify `table_list` to ensure that only the intended
table is removed during the cleanup.
parent 699cfee5
#
# MDEV-20471 Assertion during cleanup of failed CREATE TABLE LIKE <sequence>
#
CREATE SEQUENCE s;
set @save_debug_dbug=@@debug_dbug;
set debug_dbug='+d,kill_query_on_sequence_insert';
CREATE TABLE t LIKE s;
ERROR 70100: Query execution was interrupted
DROP TABLE t;
ERROR 42S02: Unknown table 'test.t'
DROP SEQUENCE s;
set debug_dbug=@save_debug_dbug;
--source include/have_debug.inc
--echo #
--echo # MDEV-20471 Assertion during cleanup of failed CREATE TABLE LIKE <sequence>
--echo #
CREATE SEQUENCE s;
set @save_debug_dbug=@@debug_dbug;
set debug_dbug='+d,kill_query_on_sequence_insert';
--error ER_QUERY_INTERRUPTED
CREATE TABLE t LIKE s;
--error ER_BAD_TABLE_ERROR
DROP TABLE t;
DROP SEQUENCE s;
set debug_dbug=@save_debug_dbug;
...@@ -300,7 +300,8 @@ bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *org_table_list) ...@@ -300,7 +300,8 @@ bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *org_table_list)
Query_tables_list query_tables_list_backup; Query_tables_list query_tables_list_backup;
TABLE_LIST table_list; // For sequence table TABLE_LIST table_list; // For sequence table
DBUG_ENTER("sequence_insert"); DBUG_ENTER("sequence_insert");
DBUG_EXECUTE_IF("kill_query_on_sequence_insert",
thd->set_killed(KILL_QUERY););
/* /*
seq is 0 if sequence was created with CREATE TABLE instead of seq is 0 if sequence was created with CREATE TABLE instead of
CREATE SEQUENCE CREATE SEQUENCE
......
...@@ -5306,7 +5306,14 @@ int mysql_create_table_no_lock(THD *thd, const LEX_CSTRING *db, ...@@ -5306,7 +5306,14 @@ int mysql_create_table_no_lock(THD *thd, const LEX_CSTRING *db,
if (res) if (res)
{ {
DBUG_ASSERT(thd->is_error()); DBUG_ASSERT(thd->is_error());
/* Drop the table as it wasn't completely done */ /*
Drop the new table, we were not completely done.
Temporarily modify table_list to avoid dropping source sequence
in CREATE TABLE LIKE <SEQUENCE>.
*/
TABLE_LIST *tail= table_list->next_local;
table_list->next_local= NULL;
if (!mysql_rm_table_no_locks(thd, table_list, 1, if (!mysql_rm_table_no_locks(thd, table_list, 1,
create_info->tmp_table(), create_info->tmp_table(),
false, true /* Sequence*/, false, true /* Sequence*/,
...@@ -5320,6 +5327,7 @@ int mysql_create_table_no_lock(THD *thd, const LEX_CSTRING *db, ...@@ -5320,6 +5327,7 @@ int mysql_create_table_no_lock(THD *thd, const LEX_CSTRING *db,
*/ */
res= 2; res= 2;
} }
table_list->next_local= tail;
} }
} }
......
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