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 执行两次,第二次的查询结果返回了一行第一次查询所没有返回的结果,就说这行数据是一行「幻影」。
Suppose that there is an index on the
id
column of thechild
table and that you want to read and lock all rows from the table having an identifier value larger than 100, with the intention of updating some column in the selected rows later:
1 SELECT * FROM child WHERE id > 100 FOR UPDATE;