mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Backport of revno: 2617.71.1
Bug#42546 Backup: RESTORE fails, thinking it finds an existing table The problem occured when a MDL locking conflict happened for a non-existent table between a CREATE and a INSERT statement. The code for CREATE interpreted this lock conflict to mean that the table existed, which meant that the statement failed when it should not have. The problem could occur for CREATE TABLE, CREATE TABLE LIKE and ALTER TABLE RENAME. This patch fixes the problem for CREATE TABLE and CREATE TABLE LIKE. It is based on code backported from the mysql-6.1-fk tree written by Dmitry Lenev. CREATE now uses normal open_and_lock_tables() code to acquire exclusive locks. This means that for the test case in the bug description, CREATE will wait until INSERT completes so that it can get the exclusive lock. This resolves the reported bug. The patch also prohibits CREATE TABLE and CREATE TABLE LIKE under LOCK TABLES. Note that this is an incompatible change and must be reflected in the documentation. Affected test cases have been updated. mdl_sync.test contains tests for CREATE TABLE and CREATE TABLE LIKE. Fixing the issue for ALTER TABLE RENAME is beyond the scope of this patch. ALTER TABLE cannot be prohibited from working under LOCK TABLES as this could seriously impact customers and a proper fix would require a significant rewrite.
This commit is contained in:
@ -1660,39 +1660,35 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
|
||||
LEX *lex= stmt->lex;
|
||||
SELECT_LEX *select_lex= &lex->select_lex;
|
||||
bool res= FALSE;
|
||||
/* Skip first table, which is the table we are creating */
|
||||
bool link_to_local;
|
||||
TABLE_LIST *create_table= lex->unlink_first_table(&link_to_local);
|
||||
TABLE_LIST *tables= lex->query_tables;
|
||||
TABLE_LIST *create_table= lex->query_tables;
|
||||
TABLE_LIST *tables= lex->create_last_non_select_table->next_global;
|
||||
|
||||
if (create_table_precheck(thd, tables, create_table))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
/*
|
||||
The open and lock strategies will be set again once the
|
||||
statement is executed. These values are only meaningful
|
||||
for the prepare phase.
|
||||
*/
|
||||
create_table->open_strategy= TABLE_LIST::OPEN_IF_EXISTS;
|
||||
create_table->lock_strategy= TABLE_LIST::SHARED_MDL;
|
||||
|
||||
if (select_lex->item_list.elements)
|
||||
{
|
||||
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
|
||||
{
|
||||
lex->link_first_table_back(create_table, link_to_local);
|
||||
/*
|
||||
The open and lock strategies will be set again once the
|
||||
statement is executed. These values are only meaningful
|
||||
for the prepare phase.
|
||||
*/
|
||||
create_table->open_strategy= TABLE_LIST::OPEN_IF_EXISTS;
|
||||
create_table->lock_strategy= TABLE_LIST::SHARED_MDL;
|
||||
}
|
||||
|
||||
if (open_normal_and_derived_tables(stmt->thd, lex->query_tables, 0))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
|
||||
create_table= lex->unlink_first_table(&link_to_local);
|
||||
|
||||
select_lex->context.resolve_in_select_list= TRUE;
|
||||
|
||||
lex->unlink_first_table(&link_to_local);
|
||||
|
||||
res= select_like_stmt_test(stmt, 0, 0);
|
||||
|
||||
lex->link_first_table_back(create_table, &link_to_local);
|
||||
}
|
||||
else if (lex->create_info.options & HA_LEX_CREATE_TABLE_LIKE)
|
||||
else
|
||||
{
|
||||
/*
|
||||
Check that the source table exist, and also record
|
||||
@ -1704,8 +1700,6 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
/* put tables back for PS rexecuting */
|
||||
lex->link_first_table_back(create_table, link_to_local);
|
||||
DBUG_RETURN(res);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user