尝试多次插入时导致死锁的主键(Auto_Inc)和唯一键索引

时间:2015-05-19 07:01:37

标签: mysql transactions deadlock database-indexes multiple-insert

我在慢速测试服务器上面临MySQL事务死锁。我对SQL不太好,但我尝试在死锁的情况下重新执行查询,但结果保持不变。我在表上有两个索引 - "Primary key index"(单列auto-inc)和唯一键索引(3列)。我试图在循环中插入大约900条记录,表格大约有172000条记录。 InnoDB引擎状态为: -

------------------------\
150519  0:59:26\
*** (1) TRANSACTION:\
TRANSACTION B7486FB, ACTIVE 0 sec inserting\
mysql tables in use 3, locked 3\
LOCK WAIT 18 lock struct(s), heap size 3112, 8 row lock(s), undo log entries 3\
MySQL thread id 329364, OS thread handle 0x2e90, query id 30582437 executing\
INSERT INTO Table(Field 1, Field 2 ..... Field9)     
\
                                        SELECT 
\
                                        Field1Value,Field2Value.... Field9Value
\
                                        FROM DUAL WHERE (Condition1 ) AND Condition2

*** (1) WAITING FOR THIS LOCK TO BE GRANTED:\
RECORD LOCKS space id 0 page no 2281088 n bits 112 index `UniqueCodeAndSubCode` of table Database :Table1 trx id B7486FB lock_mode X insert intention waiting\
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0\
 0: len 8; hex 73757072656d756d; asc supremum;;\
\
*** (2) TRANSACTION:\
TRANSACTION B7486DD, ACTIVE 30 sec setting auto-inc lock\
mysql tables in use 3, locked 3\
29 lock struct(s), heap size 6960, 582 row lock(s), undo log entries 1718\
MySQL thread id 329359, OS thread handle 0x10d0, query id 30582440 executing\
INSERT INTO Table(Field 1, Field 2 ..... Field9)     
\
                                        SELECT 
\
                                        Field1Value,Field2Value.... Field9Value
\
                                        FROM DUAL WHERE (Condition1 ) AND Condition2
*** (2) HOLDS THE LOCK(S):\
RECORD LOCKS space id 0 page no 2281088 n bits 72 index `UniqueCodeAndSubCode` of table Database:Table1 trx id B7486DD lock mode S\
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0\
 0: len 8; hex 73757072656d756d; asc supremum;;\
\
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:\
TABLE LOCK table `Database1`.`Table1` trx id B7486DD lock mode AUTO-INC waiting\
*** WE ROLL BACK TRANSACTION (1)\

我想知道是否有任何可行的解决方法。

非常感谢这方面的任何帮助。

提前致谢!

0 个答案:

没有答案