Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
InnoDB中的mysql死锁_Mysql_Innodb_Deadlock - Fatal编程技术网

InnoDB中的mysql死锁

InnoDB中的mysql死锁,mysql,innodb,deadlock,Mysql,Innodb,Deadlock,我有几个正在运行的进程正在更新和删除一个表中的行。最重要的是,使用这两个查询: UPDATE `prices_queue` SET `rand` = '$rand' WHERE `rand` = 0 ORDER BY priority DESC, pq_id ASC LIMIT 1 紧接着是一个select以获取此行:从价格队列中选择pq_id、asin、shop_id,其中rand='$rand' 及 然而,我运行的这些进程越多,我遇到的死锁就越多 有关最新死锁的信息: LATEST DET

我有几个正在运行的进程正在更新和删除一个表中的行。最重要的是,使用这两个查询:

UPDATE `prices_queue` SET `rand` = '$rand' WHERE `rand` = 0 ORDER BY priority DESC, pq_id ASC LIMIT 1
紧接着是一个select以获取此行:从价格队列中选择pq_id、asin、shop_id,其中rand='$rand'

然而,我运行的这些进程越多,我遇到的死锁就越多

有关最新死锁的信息:

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
但是为什么呢

有人能帮忙吗


谢谢

你有兰德的索引吗?有。这是好是坏?这是好的,实际上非常重要。为了以防万一,请尝试使用rand和priority的复合索引。请给我们2个查询的解释输出,替换更新。。。用selectrand设置
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