# throw light on Innodb locking scenario

**URL:** <https://forums.percona.com/t/throw-light-on-innodb-locking-scenario/4865>\
**Category:** Other MySQL® Questions\
**Created:** [April 30, 2016, 11:16am UTC](https://forums.percona.com/t/throw-light-on-innodb-locking-scenario/4865 "2016-04-30T11:16:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![madhuramanna](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/madhuramanna/32/1117_2.png) [@madhuramanna](https://forums.percona.com/u/madhuramanna)\
**Post date:** [April 30, 2016, 11:16am UTC](https://forums.percona.com/t/throw-light-on-innodb-locking-scenario/4865/1 "2016-04-30T11:16:55Z")

</div>

Hello,

Say, I have a table

CREATE TABLE `numbers` (  
`id` int(10) unsigned NOT NULL,  
`f1` int(11) NOT NULL,  
`f2` int(11) NOT NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

And populate this table with 2097152 or so entries.

Start Transaction T1 in one terminal, \>\> delete from numbers where id \< 2097119;

do not commit yet.  
Start Transaction T2 in another terminal \>\> insert into numbers (f1, f2) values (100,200);  
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

The second transaction times out.

The question is why is the second transaction needing to wait for a lock ?

Both transactions are in repeatable-read isolation level.

In another terminal, running

> > show engine innodb status

reveals  
–TRANSACTION 11DF9B, ACTIVE 931 sec  
4205 lock struct(s), heap size 620984, 2101322 row lock(s), undo log entries 2097118

Noticing that undo log entries match the number of rows, but there are more row locks.

Hoping some can help with this

---

<div class="post-metadata">

**Author:** ![madhuramanna](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/madhuramanna/32/1117_2.png) [@madhuramanna](https://forums.percona.com/u/madhuramanna)\
**Post date:** [April 30, 2016, 11:27am UTC](https://forums.percona.com/t/throw-light-on-innodb-locking-scenario/4865/2 "2016-04-30T11:27:00Z")

</div>

Noting that

1. id is not auto increment
2. when you specify id in the insert cmd, the row gets inserted right away  
\>\> insert into numbers (id, f1, f2) values (2097153, 100,200);
