summaryrefslogtreecommitdiff
path: root/sql/sql_truncate.cc
diff options
context:
space:
mode:
authorsjaakola <seppo.jaakola@iki.fi>2020-11-04 13:42:18 +0200
committerJan Lindström <jan.lindstrom@mariadb.com>2020-11-11 17:46:50 +0200
commitad432ef4c0b81cf796f9b1f66848a3cde6becf77 (patch)
tree0bf96ebee710d3de2dfe105de7fad6a92c313e95 /sql/sql_truncate.cc
parent99a9774754ea8c4e309589a2dbc7847e16e1fbde (diff)
downloadmariadb-git-ad432ef4c0b81cf796f9b1f66848a3cde6becf77.tar.gz
MDEV-24119 MDL BF-BF Conflict caused by TRUNCATE TABLE
This PR fixes same issue as MDEV-21577 for TRUNCATE TABLE. MDEV-21577 fixed TOI replication for OPTIMIZE, REPAIR and ALTER TABLE operating on FK child table. It was later found out that also TRUNCATE has similar problem and needs a fix. The actual fix is to do FK parent table lookup before TRUNCATE TOI isolation and append found FK parent table names in certification key list for the write set. PR contains also new test scenario in galera_ddl_fk_conflict test where FK child has two FK parent tables and there are two DML transactions operating on both parent tables. For development convenience, new TO isolation macro was added: WSREP_TO_ISOLATION_BEGIN_IF and WSREP_TO_ISOLATION_BEGIN_ALTER macro was changed to skip the goto statement. Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
Diffstat (limited to 'sql/sql_truncate.cc')
-rw-r--r--sql/sql_truncate.cc20
1 files changed, 17 insertions, 3 deletions
diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc
index bfcdda6e0e9..c3d347307a2 100644
--- a/sql/sql_truncate.cc
+++ b/sql/sql_truncate.cc
@@ -416,9 +416,23 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref)
bool hton_can_recreate;
#ifdef WITH_WSREP
- if (WSREP(thd) &&
- wsrep_to_isolation_begin(thd, table_ref->db.str, table_ref->table_name.str, 0))
- DBUG_RETURN(TRUE);
+ if (WSREP(thd))
+ {
+ wsrep::key_array keys;
+ wsrep_append_fk_parent_table(thd, table_ref, &keys);
+ if (keys.empty())
+ {
+ WSREP_TO_ISOLATION_BEGIN_IF(table_ref->db.str, table_ref->table_name.str, NULL)
+ {
+ DBUG_RETURN(TRUE);
+ }
+ } else {
+ WSREP_TO_ISOLATION_BEGIN_FK_TABLES(NULL, NULL, table_ref, &keys)
+ {
+ DBUG_RETURN(TRUE);
+ }
+ }
+ }
#endif /* WITH_WSREP */
if (lock_table(thd, table_ref, &hton_can_recreate))
DBUG_RETURN(TRUE);