我有几个正在运行的进程正在更新和删除一个表中的行。最重要的是,使用了这两个查询:
UPDATE `prices_queue` SET `rand` = '$rand' WHERE `rand` = 0 ORDER BY priority DESC, pq_id ASC LIMIT 1
(紧随其后的是选择以获取此行:“SELECT pq_id, asin, shop_id FROM prices_queue
WHERE rand
= '$rand')
和
DELETE FROM prices_queue WHERE pq_id IN ($idlist) ORDER BY priority DESC, pq_id ASC
但是,我运行的这些进程越多,遇到的死锁就越多。
最新死锁的相关资料:
LATEST DETECTED DEADLOCK
------------------------
130903 3:38:09
*** (1) TRANSACTION:
TRANSACTION 8DAF188, ACTIVE 0 sec fetching rows
mysql tables in use 1, locked 1
LOCK WAIT 5 lock struct(s), heap size 1248, 508 row lock(s)
MySQL thread id 133740, OS thread handle 0x41462940, query id 23177920 SERVERNAME init
UPDATE `prices_queue` SET `rand` = '631351' WHERE `rand` = 0 AND shop_id <> 1 ORDER BY priority DESC, pq_id ASC LIMIT 1
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 681 page no 62 n bits 480 index `PRIMARY` of table `prices_queue` trx id 8DAF188 lock_mode X locks rec but not gap waiting
Record lock, heap no 311 PHYSICAL RECORD: n_fields 7; compact format; info bits 0
0: len 4; hex 8003d370; asc p;;
1: len 6; hex 000008da9806; asc ;;
2: len 7; hex 290000019703f5; asc ) ;;
3: len 10; hex 30373932323833323532; asc 0792283252;;
4: len 1; hex 07; asc ;;
5: len 1; hex 32; asc 2;;
6: len 4; hex 000cadd7; asc ;;
*** (2) TRANSACTION:
TRANSACTION 8DAF187, ACTIVE 0 sec fetching rows
mysql tables in use 1, locked 1
3 lock struct(s), heap size 1248, 2 row lock(s)
MySQL thread id 133727, OS thread handle 0x41f33940, query id 23177919 SERVERNAME init
UPDATE `prices_queue` SET `rand` = '844973' WHERE `rand` = 0 ORDER BY priority DESC, pq_id ASC LIMIT 1
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 681 page no 62 n bits 480 index `PRIMARY` of table `prices_queue` trx id 8DAF187 lock_mode X
Record lock, heap no 311 PHYSICAL RECORD: n_fields 7; compact format; info bits 0
0: len 4; hex 8003d370; asc p;;
1: len 6; hex 000008da9806; asc ;;
2: len 7; hex 290000019703f5; asc ) ;;
3: len 10; hex 30373932323833323532; asc 0792283252;;
4: len 1; hex 07; asc ;;
5: len 1; hex 32; asc 2;;
6: len 4; hex 000cadd7; asc ;;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 681 page no 62 n bits 480 index `PRIMARY` of table `prices_queue` trx id 8DAF187 lock_mode X waiting
Record lock, heap no 312 PHYSICAL RECORD: n_fields 7; compact format; info bits 0
0: len 4; hex 8003d3c4; asc ;;
1: len 6; hex 000008da99a9; asc ;;
2: len 7; hex 68000002670ea4; asc h g ;;
3: len 10; hex 30303731343538323731; asc 0071458271;;
4: len 1; hex 03; asc ;;
5: len 1; hex 32; asc 2;;
6: len 4; hex 00002a98; asc * ;;
*** WE ROLL BACK TRANSACTION (2)
我知道这两个查询会互相阻塞:
UPDATE `prices_queue` SET `rand` = '631351' WHERE `rand` = 0 AND shop_id <> 1 ORDER BY priority DESC, pq_id ASC LIMIT 1
UPDATE `prices_queue` SET `rand` = '844973' WHERE `rand` = 0 ORDER BY priority DESC, pq_id ASC LIMIT 1
但为什么?
有人可以帮忙吗?
谢谢!