summaryrefslogtreecommitdiff
path: root/sql/sql_table.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r--sql/sql_table.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index c4b07ad2035..b4cbc936fa1 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -5561,6 +5561,24 @@ int mysql_discard_or_import_tablespace(THD *thd,
DBUG_RETURN(-1);
}
+ /*
+ Under LOCK TABLES we need to upgrade SNRW metadata lock to X lock
+ before doing discard or import of tablespace.
+
+ Skip this step for temporary tables as metadata locks are not
+ applicable for them.
+ */
+ if (table_list->table->s->tmp_table == NO_TMP_TABLE &&
+ (thd->locked_tables_mode == LTM_LOCK_TABLES ||
+ thd->locked_tables_mode == LTM_PRELOCKED_UNDER_LOCK_TABLES) &&
+ thd->mdl_context.upgrade_shared_lock(table_list->table->mdl_ticket,
+ MDL_EXCLUSIVE,
+ thd->variables.lock_wait_timeout))
+ {
+ thd->tablespace_op= FALSE;
+ DBUG_RETURN(-1);
+ }
+
error= table_list->table->file->ha_discard_or_import_tablespace(discard);
THD_STAGE_INFO(thd, stage_end);
@@ -5583,6 +5601,13 @@ int mysql_discard_or_import_tablespace(THD *thd,
error= write_bin_log(thd, FALSE, thd->query(), thd->query_length());
err:
+ if (table_list->table->s->tmp_table == NO_TMP_TABLE &&
+ (thd->locked_tables_mode == LTM_LOCK_TABLES ||
+ thd->locked_tables_mode == LTM_PRELOCKED_UNDER_LOCK_TABLES))
+ {
+ table_list->table->mdl_ticket->downgrade_lock(MDL_SHARED_NO_READ_WRITE);
+ }
+
thd->tablespace_op=FALSE;
if (error == 0)