可重复读取关于 select * 的顺序和限制

Repeatable read regarding select * with order by and limit

在默认隔离级别 mysql(可重复读取)下,如果我发出 select 类似 select * from table_a where column_a = 'a' order by id limit 100,一段时间后,我在同一事务中发出另一个语句喜欢 select * from table_a where column_a = 'a' order by id limit 100, 101。同时,另一个事务正在使用新记录附加到此 table_a(它不会插入中间)并且它在第一个事务发出第二个 select 之前提交。问题是第一个事务中的第二个select return 是第二个事务新插入的结果吗?

问:"But what puzzles me is that the first select should only create a snapshot of the fist 100 records (the limited 100 records). But why the second select didn't return the newly inserted records?"

答:因为新插入的记录本质上是"don't exist"在你的事务上下文中。

https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html

REPEATABLE READ

This is the default isolation level for InnoDB. Consistent reads within the same transaction read the snapshot established by the first read. This means that if you issue several plain (nonlocking) SELECT statements within the same transaction, these SELECT statements are consistent also with respect to each other.