I am facing a MySQL Transaction Deadlock on a slow test server. I am not much good with SQL but i have tried re-executing the query in case of Deadlock but the result remains the same. I have two indexes on the table - "Primary key index"
(Single column auto-inc) and Unique key Index (3 columns). I am trying to insert about 900 records in a loop and table has approximately 172000 records. InnoDB engine status is :-
------------------------\
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)\
I want to know if there is any possible workaround.
Any help in this regard is much appreciated.
Thanks in advance !