我一直在阅读Diagnosing MySQL InnoDB Locks文章.卡尔·约根森(KarlE.Jørgensen)在2008年写道,所以我对它的影响是有效的.
我想提供SHOW ENGINE INNODB状态的片段:
---TRANSACTION 20532F16, ACTIVE 386 sec starting index read
mysql tables in use 6, locked 6
LOCK WAIT 2 lock struct(s), heap size 1248, 1 row lock(s)
MySQL thread id 96238, query id 81681916 192.168.6.31 thanhnt updating
DELETE FROM `v3_zone_date`
WHERE `dt` = NAME_CONST('_currDate',_latin1'2012-03-02' COLLATE 'latin1_swedish_ci')
------- TRX HAS BEEN WAITING 8 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 482988 page no 6 n bits 360 index `GEN_CLUST_INDEX` of table `reportingdb`.`v3_zone_date` /* Partition `pcurrent_201232` */ trx id 20532F16 lock_mode X waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 13; compact format; info bits 0
0: len 6; hex 000237440e77; asc 7D w;;
1: len 6; hex 0000204f2acb; asc O* ;;
2: len 7; hex e6000480120110; asc ;;
3: len 3; hex 8f5340; asc S@;;
4: len 2; hex 83d4; asc ;;
5: len 3; hex 814f42; asc OB;;
6: len 3; hex 000000; asc ;;
7: len 3; hex 000000; asc ;;
8: len 3; hex 800000; asc ;;
9: len 3; hex 000001; asc ;;
10: len 3; hex 000000; asc ;;
11: len 3; hex 8fb862; asc b;;
12: len 2; hex 0000; asc ;;
------------------
---TRANSACTION 20532EE8, ACTIVE 437 sec fetching rows, thread declared inside InnoDB 236
mysql tables in use 22, locked 22
24944 lock struct(s), heap size 3586488, 11457529 row lock(s)
MySQL thread id 97447, query id 81504647 event_scheduler Copying to tmp table
查询被切断,所以我从SHOW FULL PROCESSLIST输出中得到它:
*************************** 18. row ***************************
Id: 97447
User: thanhnt
Host: 192.168.6.31
db: reportingdb
Command: Connect
Time: 423
State: Copying to tmp table
Info: UPDATE `selfserving_banner_zone` A,( SELECT B.`bannerid`,C.`zoneid`,ROUND(SUM(C.`realclick`)*100/SUM(C.`totalview`),5) CTR
FROM `ox_campaigns` A
INNER JOIN `ox_banners` B ON B.`campaignid`= A.`campaignid`
INNER JOIN `v3_zone_date` C ON C.`campaignid` = B.`campaignid` AND B.`bannerid` = C.bannerid
WHERE A.`revenue_type` = 5 AND C.`dt` BETWEEN DATE_SUB( NAME_CONST('_currdate',_latin1'2012-03-02' COLLATE 'latin1_swedish_ci'),INTERVAL 1 DAY) AND NAME_CONST('_currdate',_latin1'2012-03-02' COLLATE 'latin1_swedish_ci') AND C.totalview >0 AND A.isExpired NOT IN (1,2)
AND A.deleted = 0 AND B.deleted = 0 AND CURRENT_DATE BETWEEN B.`activate` AND B.`expire` AND A.status = 1 AND B.status = 1 AND C.`realclick` > 0
GROUP BY B.`bannerid`,C.`zoneid`) B
SET A.`ctr` = B.CTR WHERE A.`bannerid` = B.bannerid AND A.`zoneid` = B.zoneid
根据上面的文章,TRANSACTION 20532F16正在等待锁定.但正如你所看到的,这里有一些十六进制转储.哪一个可以用来确定持有锁的交易?此外,我看到交易号码已经是十六进制(例如:20532EE8)
This文章没有解释关于十六进制的足够细节.
PS:我已经尝试了所有上面的十六进制转储(十六进制和十进制)但没有运气.
回复RolandoMySQLDBA:
I wrote a 07002
11457529行锁只接管… 5MB.
If your InnoDB buffer pool is not large enough, you may not have
enough resource for defining as many row locks as needed. Therefore, I
would recommend increasing your
07003.
这是我的缓冲池和内存:
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 21978152960; in additional pool allocated 0
Dictionary memory allocated 2636907
Buffer pool size 1310712
Free buffers 704307
Database pages 589697
Old database pages 217517
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 361757, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 365924, created 666845, written 1151187
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s
LRU len: 589697, unzip_LRU len: 0
I/O sum[32]:cur[0], unzip sum[0]:cur[0]
如你所见,我有很多页面免费(704307).你还有其他建议吗?
PS:innotop显示关于InnoDB Locks的空结果:
_________________________________ InnoDB Locks __________________________________
CXN ID Type Waiting Wait Active Mode DB Table Index Ins Intent Special
更新于3月6日星期二00:16:41 ICT 2012
PS: I’ve tried all of the above hex-dumped (both in hex and decimal)
but no luck.
我的SHOW ENGINE INNODB状态中没有上述十六进制的交易;:
$egrep -i '8f5340|814f42|8fb862' innodb.status_2012-03-02
3: len 3; hex 8f5340; asc S@;;
5: len 3; hex 814f42; asc OB;;
11: len 3; hex 8fb862; asc b;;
解决方法:
这真的很容易.不要使用SHOW ENGINE INNODB STATUS,请使用information_schema.innodb_locks.这是我用外键写一篇博文的例子:
http://www.mysqlperformanceblog.com/2010/09/20/instrumentation-and-the-cost-of-foreign-keys/