插入和更新时出现死锁

时间:2016-01-11 14:01:39

标签: mysql deadlock database-deadlocks

我找不到任何合理的理由,为什么我会因为查询这个数据而陷入僵局:

------------------------
LATEST DETECTED DEADLOCK
------------------------
2016-01-11 13:32:09 7fe28a771700
*** (1) TRANSACTION:
TRANSACTION 5216710392, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1184, 2 row lock(s), undo log entries 1
MySQL thread id 17386541, OS thread handle 0x7fe289bd5700, query id 373004647 54.72.98.210 root update
INSERT INTO testable (amount, closedAt, lastClick, maxTime, createdAt, status, amz, cid, related_id, user_id) VALUES (50, NULL, '2016-01-11 15:32:17', 50, '2016-01-11 15:32:17', 0, 'europe-west1-b', NULL, 16141965, 608617)
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 48 page no 112341 n bits 352 index `UNIQ_47510E734162C001` of table `zenGaming`.`testable` trx id 5216710392 lock mode S waiting
Record lock, heap no 285 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
 0: len 4; hex 80f64e8d; asc   N ;;
 1: len 4; hex 80f64e8e; asc   N ;;

*** (2) TRANSACTION:
TRANSACTION 5216710370, ACTIVE 0 sec starting index read
mysql tables in use 1, locked 1
6 lock struct(s), heap size 1184, 4 row lock(s), undo log entries 1
MySQL thread id 17386549, OS thread handle 0x7fe28a771700, query id 373004651 54.72.98.210 root updating
UPDATE testable SET related_id = 16141966 WHERE id = 16141965
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 48 page no 112341 n bits 352 index `UNIQ_47510E734162C001` of table `zenGaming`.`testable` trx id 5216710370 lock_mode X locks rec but not gap
Record lock, heap no 285 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
 0: len 4; hex 80f64e8d; asc   N ;;
 1: len 4; hex 80f64e8e; asc   N ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 48 page no 66493 n bits 216 index `PRIMARY` of table `zenGaming`.`testable` trx id 5216710370 lock_mode X locks rec but not gap waiting
Record lock, heap no 129 PHYSICAL RECORD: n_fields 13; compact format; info bits 0
 0: len 4; hex 80f64e8d; asc   N ;;
 1: len 6; hex 000136f0aa8f; asc   6   ;;
 2: len 7; hex e1000002300084; asc     0  ;;
 3: SQL NULL;
 4: SQL NULL;
 5: len 4; hex 8004188e; asc     ;;
 6: len 4; hex 80000032; asc    2;;
 7: SQL NULL;
 8: len 5; hex 999856f810; asc   V  ;;
 9: len 4; hex 80000032; asc    2;;
 10: len 5; hex 999856f810; asc   V  ;;
 11: len 4; hex 80000000; asc     ;;
 12: len 14; hex 6575726f70652d77657374312d62; asc europe-west1-b;;

*** WE ROLL BACK TRANSACTION (1)

表创建查询 -

'CREATE TABLE `testable` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cid` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `amount` int(11) NOT NULL,
  `closedAt` datetime DEFAULT NULL,
  `lastClick` datetime DEFAULT NULL,
  `size` int(11) NOT NULL,
  `maxTime` int(11) NOT NULL,
  `createdAt` datetime NOT NULL,
  `status` int(11) NOT NULL,
  `amz` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  KEY `IDX_FC939F5698A21AC6` (`challenge_id`),
  KEY `IDX_FC939F56A76ED395` (`user_id`),
  KEY `status_idx` (`status`),
  CONSTRAINT `FK_FC939F5698A21AC6` FOREIGN KEY (`cid`) REFERENCES `ci` (`id`),
  CONSTRAINT `FK_FC939F56A76ED395` FOREIGN KEY (`user_id`) REFERENCES `fos_user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci'

我看不出这种僵局的原因..如果缺少任何数据,请告诉我,谢谢。

0 个答案:

没有答案