登录
2017-01-08 18:39:21 来自:云散月明 0 人回应

小弟有一SQL语句现在在多并发的情况下会出现死锁。希望各位大神帮忙给小弟分析一下。

UPDATE accountinfo SET usecnt = 20, version = version+1 WHERE usecnt > 0 AND accountid = 12 and version = 102

MySQL数据库,存储引擎为InnoDB,其中accountid为主键,usecnt和version没有任何索引。 当前事务使用的事务隔离级别为:READ_COMMITTED

 

发生死锁的日志如下:

*** (1) TRANSACTION:
TRANSACTION 1331664, ACTIVE 40 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 11 lock struct(s), heap size 2936, 6 row lock(s), undo log entries 9
MySQL thread id 106, OS thread handle 0x334c, query id 2285 192.168.25.85 root updating
UPDATE accountinfo SET usecnt = 20, version = version+1 
            WHERE usecnt > 0 AND accountid = 12 and version = 102
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 2151 page no 3 n bits 80 index `PRIMARY` of table `stamp_server_db`.`accountinfo` trx id 1331664 lock_mode X locks rec but not gap waiting
Record lock, heap no 10 PHYSICAL RECORD: n_fields 35; compact format; info bits 0

 

*** (2) TRANSACTION:
TRANSACTION 1331673, ACTIVE 39 sec starting index read
mysql tables in use 1, locked 1
11 lock struct(s), heap size 2936, 6 row lock(s), undo log entries 9
MySQL thread id 109, OS thread handle 0x3910, query id 2355 192.168.25.85 root updating
UPDATE accountinfo SET usecnt = 20, version = version+1 
            WHERE usecnt > 0 AND accountid = 12 and version = 102
 
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 2151 page no 3 n bits 80 index `PRIMARY` of table `stamp_server_db`.`accountinfo` trx id 1331673 lock mode S locks rec but not gap
Record lock, heap no 10 PHYSICAL RECORD: n_fields 35; compact format; info bits 0
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
 
RECORD LOCKS space id 2151 page no 3 n bits 80 index `PRIMARY` of table `stamp_server_db`.`accountinfo` trx id 1331673 lock_mode X locks rec but not gap waiting
Record lock, heap no 10 PHYSICAL RECORD: n_fields 35; compact format; info bits 0
 
*** WE ROLL BACK TRANSACTION (2)

 

 

还没有人回应!

您的回应

你还未登陆,不能回应!登陆