Skip to content

Commit 1639873

Browse files
committed
MDEV-18154 Deadlock and assertion upon no-op ALTER under LOCK TABLES
1. Revert incorrect treatment of m_needs_reopen; 2. Close single instance of TABLE instead of all instances since reopened only those that are marked for reopen.
1 parent 395e1dc commit 1639873

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

sql/sql_base.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,9 +2488,16 @@ Locked_tables_list::reopen_tables(THD *thd, bool need_reopen)
24882488
{
24892489
if (!table_list->table || !table_list->table->needs_reopen())
24902490
continue;
2491-
/* no need to remove the table from the TDC here, thus (TABLE*)1 */
2492-
close_all_tables_for_name(thd, table_list->table->s,
2493-
HA_EXTRA_NOT_USED, (TABLE*)1);
2491+
for (TABLE **prev= &thd->open_tables; *prev; prev= &(*prev)->next)
2492+
{
2493+
if (*prev == table_list->table)
2494+
{
2495+
thd->locked_tables_list.unlink_from_list(thd, table_list, false);
2496+
mysql_lock_remove(thd, thd->lock, *prev);
2497+
close_thread_table(thd, prev);
2498+
break;
2499+
}
2500+
}
24942501
DBUG_ASSERT(table_list->table == NULL);
24952502
}
24962503
else

sql/sql_table.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7831,7 +7831,6 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
78317831
Create_field *def;
78327832
Field **f_ptr,*field;
78337833
MY_BITMAP *dropped_fields= NULL; // if it's NULL - no dropped fields
7834-
bool save_reopen= table->m_needs_reopen;
78357834
DBUG_ENTER("mysql_prepare_alter_table");
78367835

78377836
/*
@@ -8511,9 +8510,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
85118510
alter_info->create_list.swap(new_create_list);
85128511
alter_info->key_list.swap(new_key_list);
85138512
alter_info->check_constraint_list.swap(new_constraint_list);
8514-
DBUG_RETURN(rc);
85158513
err:
8516-
table->m_needs_reopen= save_reopen;
85178514
DBUG_RETURN(rc);
85188515
}
85198516

0 commit comments

Comments
 (0)