一条简单SQL语句出现死锁情况,请帮忙各位大神帮忙分析一下。
小弟有一SQL语句现在在多并发的情况下会出现死锁。希望各位大神帮忙给小弟分析一下。
UPDATE accountinfo SET usecnt = 20, version = version+1 WHERE usecnt > 0 AND accountid = 12 and version = 102
其中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)
请各位大神,帮小弟看一下。怎么破。
补充:
explain UPDATE accountinfo SET usecnt = 1999, version = version+1 WHERE usecnt > 0 AND accountid = 12 and version = 102
回答:
看日志事务2获得了一个共享锁(读锁),然后这个事务要修改同样的记录时,由于前面给记录上了共享锁,没办法再加排他锁(写锁),一个事务中不是只有update操作吧。
以上是 一条简单SQL语句出现死锁情况,请帮忙各位大神帮忙分析一下。 的全部内容, 来源链接: utcz.com/p/176283.html