I am trying to understand how transactions work, and I have ran into a scenario which does not make a lot of sense to me. I was hoping somebody could help me understand it.
I have two transactions
Transaction 1
BEGIN; update data set val = val + 1 where id = 1
Transaction 2
BEGIN; select * from data
I have two terminals open, I begin the first transaction and run the update query. This supposedly gives the exclusive lock to transaction 1 on tuple with id 1.
Following that, I run the second query in another terminal before committing the first transaction. I was expecting it to stall, since the first transaction has the exclusive lock which will prevent this transaction from acquiring the read lock on tuple with id 1.
However, mysql runs the select query and returns the "un-dirty" data.
Can somebody give me the explanation behind this behavior of mysql?