Comment 4 for bug 1240098

Revision history for this message
Raghavendra D Prabhu (raghavendra-prabhu) wrote : Re: Deadlock when dropping and creating temporary table on Percona XtraDB Cluster 5.5.33

As error indicates, the DML is skipping but DDL goes ahead and temporary table is created.

Also, following succeeds (also a workaround).

MySQL [test]> commit;
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction
MySQL [test]> show create table test_bug;
+----------+------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------+------------------------------------------------------------------------------------------------------+
| test_bug | CREATE TEMPORARY TABLE `test_bug` (
  `id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+----------+------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MySQL [test]> start transaction;
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> insert into test_bug select * from test_bug_source;
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0

MySQL [test]> commit;
Query OK, 0 rows affected (0.00 sec)

========================================

So the problem seems to occur when:

a) there is an explicit TEMPORARY TABLE

b) DML and DDL occur in same statement

Hence, following succeeds as well
========================================
MySQL [(none)]> drop database test;
Query OK, 1 row affected (0.01 sec)

MySQL [(none)]> create database test;
Query OK, 1 row affected (0.00 sec)

MySQL [(none)]> use test;
Database changed
MySQL [test]> DROP TABLE IF EXISTS test_bug_source;
Query OK, 0 rows affected, 1 warning (0.00 sec)

MySQL [test]> CREATE TABLE test_bug_source(`id` int);
Query OK, 0 rows affected (0.01 sec)

MySQL [test]>
MySQL [test]> INSERT INTO
    -> test_bug_source
    -> VALUES
    -> (1)
    -> ;
Query OK, 1 row affected (0.00 sec)

MySQL [test]> COMMIT;
Query OK, 0 rows affected (0.00 sec)

MySQL [test]> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)

MySQL [test]> DROP TEMPORARY TABLE IF EXISTS test_bug;
Query OK, 0 rows affected, 1 warning (0.00 sec)

MySQL [test]> CREATE TEMPORARY TABLE test_bug like test_bug_source;
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> commit;
Query OK, 0 rows affected (0.00 sec)

MySQL [test]> show create table test_bug;
+----------+------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------+------------------------------------------------------------------------------------------------------+
| test_bug | CREATE TEMPORARY TABLE `test_bug` (
  `id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+----------+------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MySQL [test]> start transaction;
Query OK, 0 rows affected (0.00 sec)

MySQL [test]> insert into test_bug select * from test_bug_source;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0

MySQL [test]> commit;
Query OK, 0 rows affected (0.00 sec)
==============================================================