问题
- Begin transaction Tx1
- Tx1 performs a
SELECT
- Commit Tx1
- Begin transaction Tx2 in a different session, using a different connection
- Tx2 performs a
SELECT
- Update rows in Tx2
- Commit Tx2
- Begin a new transaction, Tx1
- Perform select - get results from step 2(??)
- Commit Tx1
- Begin transaction Tx1
- Perform select - get CORRECT results, i.e. the committed updates from Tx2
Very confused... How can this happen? It is happening reliably and consistently.
回答1:
Turns out this can happen if the transaction isolation level is set to REPEATABLE READ
. Set the transaction isolation level to READ COMMITTED
and everything is hunky dory. Doesn't really explain why (must be some sort of BEGIN TRANSACTION hanging around?)
来源:https://stackoverflow.com/questions/21613500/innodb-mysql-new-transaction-uses-old-data-on-select-instead-of-returning-up