PS:本文已收录到1.1K+ Star数开源项目《面试指北》,如果想要了解更多MySQL相关的技术总结,可以看一看,项目地址:https://github.com/NotFound9/interviewGuide
问题分析
首先幻读是什么?
根据MySQL文档上面的定义
The so-called phantom problem occurs within a transaction when the same query produces different sets of rows at different times. For example, if a SELECT is executed twice, but returns a row the second time that was not returned the first time, the row is a “phantom” row.
幻读指的是在一个事务内,同一SELECT语句在不同时间执行,得到不同的结果集时,就会发生所谓的幻读问题。
可以看看下面的例子:
这是网上找的一张图(事务的务字写错了,不过不影响我们理解)