InnoDB / MySQL - new transaction uses old data on SELECT instead of returning updated data

别来无恙 提交于 2021-02-11 17:57:13

问题


  1. Begin transaction Tx1
  2. Tx1 performs a SELECT
  3. Commit Tx1
  4. Begin transaction Tx2 in a different session, using a different connection
  5. Tx2 performs a SELECT
  6. Update rows in Tx2
  7. Commit Tx2
  8. Begin a new transaction, Tx1
  9. Perform select - get results from step 2(??)
  10. Commit Tx1
  11. Begin transaction Tx1
  12. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!