SELECT * FROM foo WHERE bar = true
假设这是一个相当长时间运行的查询(例如花一分钟).
如果在查询开始时有500万条记录,其中bar = true,则在另一个事务中的查询期间,在foo表中添加和删除行,对于某些现有行,对条形字段进行更新.
我知道单个事务中单独语句之间的事务隔离和可见性,但是正在运行的单个语句呢?
由于MVCC模型,只有在查询开始时可见的元组才会在单个SELECT中使用.手册 here中的详细信息:
Read Committed is the default isolation level in Postgresql. When a
transaction uses this isolation level,a SELECT query (without a FOR
UPDATE/SHARE clause) sees only data committed before the query began;
it never sees either uncommitted data or changes committed during
query execution by concurrent transactions. In effect,a SELECT query
sees a snapshot of the database as of the instant the query begins to
run. However,SELECT does see the effects of prevIoUs updates executed
within its own transaction,even though they are not yet committed.
Also note that two successive SELECT commands can see different data,
even though they are within a single transaction,if other
transactions commit changes during execution of the first SELECT.
强调我的.