Quantcast
Channel: MySQL Forums - InnoDB
Viewing all articles
Browse latest Browse all 1956

Deadlock between two transactions just inserting (4 replies)

$
0
0
Hi

I have an "operation" in my system where I insert some rows into a table ArchivedId. Before inserting there has been no selecting (or anything else) from ArchivedId - the first thing the "operation" needs to do against table ArchivedId is to do the inserts.

Sometimes two transactions running this operation (inserting completely different rows into ArchivedId) get into a deadlock. See deadlock detection from "SHOW INNODB STATUS" below. I cannot understand why? It seems like one of the transactions already hold a S (shared) lock, while they are both trying to get a X lock. I dont understand why one of the transactions already hold the S lock, since no reading has been done from the ArchivedId table in the transactions.

On http://dev.mysql.com/doc/refman/5.1/en/innodb-deadlocks.html there is a line saying "You can get deadlocks even in the case of transactions that just insert or delete a single row". Maybe this is what happens to me?

Can someone please explain to me how I can get into this deadlock when two transactions just want to insert completely different new rows into the same table "at the same time"? And more important, what to do about it?

Regards, Per Steffensen

------ below relevant output from SHOW INNODB STATUS ----------

------------------------
LATEST DETECTED DEADLOCK
------------------------
110110 16:56:35
*** (1) TRANSACTION:
TRANSACTION 9012, ACTIVE 33 sec, process no 10416, OS thread id 140227825432336 inserting
mysql tables in use 1, locked 1
LOCK WAIT 6 lock struct(s), heap size 1216, 2 row lock(s), undo log entries 2
MySQL thread id 68, query id 845608 ubuntu104template-6.local 192.168.99.146 root update
/* */ insert into ArchivedId (id, version, createDate, description, a, name, reference, b, c, archivedIS_pid) values ('678a4f3e-9948-43de-b6da-1630123ec1d6', 0, '2011-01-10', 'Description8c449339-cf72-4bd5-aba8-bddca1ad4bd1', 'Ad4ebbabb-13a0-4251-8976-d247bdc2d9da', 'Id55703108-8090-4fe6-9317-853a35759bfa', 'Reference11060ce8-3416-4ddb-9cf6-1bebc492a138', 'B', 'C', 13)
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 50 page no 4 n bits 72 index `id` of table `tlt`.`archivedid` trx id 9012 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 901F, ACTIVE 33 sec, process no 10416, OS thread id 140227827439376 inserting
mysql tables in use 1, locked 1
6 lock struct(s), heap size 1216, 2 row lock(s), undo log entries 2
MySQL thread id 57, query id 845593 ubuntu104template-4.local 192.168.99.144 root update
/* */ insert into ArchivedId (id, version, createDate, description, a, name, reference, b, c, archivedIS_pid) values ('2f3f46c3-04b8-46f6-ae2f-83bf80365337', 0, '2011-01-10', 'Description35fdc38e-e470-4ee3-bbe7-3b8a39dff516', 'Afc1d901a-8837-4ffa-83b6-da577775d6bd', 'Id9e28b96-ea2f-4795-95a5-1a508cf21070', 'Reference0dcf1812-f576-4958-aad7-43119346d83c', 'B', 'C', 12)
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 50 page no 4 n bits 72 index `id` of table `tlt`.`archivedid` trx id 901F 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:
RECORD LOCKS space id 50 page no 4 n bits 72 index `id` of table `tlt`.`archivedid` trx id 901F 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;;

*** WE ROLL BACK TRANSACTION (2)

Viewing all articles
Browse latest Browse all 1956

Trending Articles