Mysql – How to find who holds the lock based on the hex-dumped

innodblockingMySQL

I've been reading the Diagnosing MySQL InnoDB Locks article. Karl E. Jørgensen writes on 2008 so I'm consfusing it is in effect.

I would like to supply a snippet of the SHOW ENGINE INNODB STATUS:

---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

The query is cut off apart so I get it from the SHOW FULL PROCESSLIST output:

*************************** 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

According to the above article, TRANSACTION 20532F16 is waiting for a lock. But as you can see, there are a few hex-dumped here. Which one can be used to determine the transaction that holds the lock? Moreover, I see the transaction number is already in hexadecimal (ex: 20532EE8)

This article doesn't explain enough details about the hex.

PS: I've tried all of the above hex-dumped (both in hex and decimal) but no luck.


Reply to RolandoMySQLDBA:

I wrote a recent post about how 44KB is needed to lock 100,000 rows
on a table

11457529 row lock(s) just take over… 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
innodb_buffer_pool_size.

Here's my buffer pool and memory:

----------------------
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]

As you can see, I have a lot of pages free (704307). Do you have any other ideas?

PS: innotop shows the empty result about InnoDB Locks:

_________________________________ InnoDB Locks __________________________________
CXN  ID  Type  Waiting  Wait  Active  Mode  DB  Table  Index  Ins Intent  Special

UPDATE Tue Mar 6 00:16:41 ICT 2012

PS: I've tried all of the above hex-dumped (both in hex and decimal)
but no luck.

There's no transaction with the above hex in my SHOW ENGINE INNODB STATUS;:

$ 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;;

Best Answer

This is really easy now. Don't use SHOW ENGINE INNODB STATUS, use information_schema.innodb_locks. Here's an example I wrote a blog post on with foreign keys:

http://www.mysqlperformanceblog.com/2010/09/20/instrumentation-and-the-cost-of-foreign-keys/