I am not sure about how the row level lock work but here is my problem I have a table T (id int , balance int ) ( engine = InnoDB ) that I want to lock rows having ID = 1, so i start a transaction like this :
start transaction ;
select * from T where ID = 1 FOR UPDATE ;
Before sending commit, I wanted to try if really the rows are LOCKED. So I started an other session and I typed :
UPDATE T set balance = balance + 100 where ID = 1 ;
Here I clearly see that I waiting for the lock (timeout after 30 sec).
But when I type :
UPDATE T set balance = balance + 8500 where ID = 2 ;
I am also waiting for the lock, so how can I just lock the ID = 1 rows and not the table entirely?