summaryrefslogtreecommitdiff
path: root/sql/sql_trigger.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2021-05-12 07:47:51 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2021-05-12 07:47:51 +0300
commit370b310b1d67ad42df96b75c3876fdcf67a8694f (patch)
tree9a236c842b6b252bcf1aef198ed4ba8df8512bd5 /sql/sql_trigger.cc
parentb6cfb2961ec72f827468d6d2f7583ce7d1127f6e (diff)
parent4d53a7585c532c2cfcea184259e3153f95b35683 (diff)
downloadmariadb-git-370b310b1d67ad42df96b75c3876fdcf67a8694f.tar.gz
Merge 10.5 into 10.6
Diffstat (limited to 'sql/sql_trigger.cc')
-rw-r--r--sql/sql_trigger.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index fd9095ea659..6993bb4183c 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -396,7 +396,9 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
bool result= TRUE;
String stmt_query;
bool lock_upgrade_done= FALSE;
+ bool backup_of_table_list_done= 0;;
MDL_ticket *mdl_ticket= NULL;
+ MDL_request mdl_request_for_trn;
Query_tables_list backup;
DBUG_ENTER("mysql_create_or_drop_trigger");
@@ -446,6 +448,16 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
DBUG_RETURN(TRUE);
}
+ /* Protect against concurrent create/drop */
+ MDL_REQUEST_INIT(&mdl_request_for_trn, MDL_key::TABLE,
+ create ? tables->db.str : thd->lex->spname->m_db.str,
+ thd->lex->spname->m_name.str,
+ MDL_EXCLUSIVE, MDL_EXPLICIT);
+ if (thd->mdl_context.acquire_lock(&mdl_request_for_trn,
+ thd->variables.lock_wait_timeout))
+ goto end;
+
+
if (!create)
{
bool if_exists= thd->lex->if_exists();
@@ -454,6 +466,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
Protect the query table list from the temporary and potentially
destructive changes necessary to open the trigger's table.
*/
+ backup_of_table_list_done= 1;
thd->lex->reset_n_backup_query_tables_list(&backup);
/*
Restore Query_tables_list::sql_command, which was
@@ -623,7 +636,7 @@ end:
mdl_ticket->downgrade_lock(MDL_SHARED_NO_READ_WRITE);
/* Restore the query table list. Used only for drop trigger. */
- if (!create)
+ if (backup_of_table_list_done)
thd->lex->restore_backup_query_tables_list(&backup);
if (!result)
@@ -635,6 +648,9 @@ end:
thd->lex->spname->m_name.str, static_cast<uint>(thd->lex->spname->m_name.length));
}
+ if (mdl_request_for_trn.ticket)
+ thd->mdl_context.release_lock(mdl_request_for_trn.ticket);
+
DBUG_RETURN(result);
#ifdef WITH_WSREP
wsrep_error_label: