maybe you can shed light on something for me here:
DB = MySQL 5.7
Storage engine: InnoDB
Isolation level: Repeatable Read
Following table:
---------------
| MyTable |
---------------
| PK | Concur |
---------------
| 3 | 2 |
---------------
I have no transaction going at this point in time and I select this record like
SELECT * FROM MyTable WHERE PK = 3
and store the result in my program.
I start now a DB transaction.
An outside process increments Concur
for the record with PK
= 3 from 2 to 3 after my transaction has started.
I have not yet read again from that table inside my transaction.
I issue the following query from inside my transaction:
UPDATE MyTable SET Concur = 3 WHERE PK = 3 AND Concur = 2
This will succeed with 0 records affected
. So clearly, it evaluates against the data that has been altered AFTER my transaction has started.
Still in the transaction I subsequently query:
SELECT * FROM MyTable WHERE PK = 3
which will return me the record with PK = 3 and Concur = 2
which are the values from before the transaction.
Why do SELECT
and UPDATE ... WHERE
behave differently, what am I missing?
I would have expected that the UPDATE ... WHERE
statement either fails directly instead of succeeding with 0 records affected, or alternatively it succeeds there with 1 record affected and then blows at the COMMIT
afterwards, but not this mix and match.
Any insight here?