mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Use an MVCC snapshot, rather than SnapshotNow, for catalog scans.
SnapshotNow scans have the undesirable property that, in the face of concurrent updates, the scan can fail to see either the old or the new versions of the row. In many cases, we work around this by requiring DDL operations to hold AccessExclusiveLock on the object being modified; in some cases, the existing locking is inadequate and random failures occur as a result. This commit doesn't change anything related to locking, but will hopefully pave the way to allowing lock strength reductions in the future. The major issue has held us back from making this change in the past is that taking an MVCC snapshot is significantly more expensive than using a static special snapshot such as SnapshotNow. However, testing of various worst-case scenarios reveals that this problem is not severe except under fairly extreme workloads. To mitigate those problems, we avoid retaking the MVCC snapshot for each new scan; instead, we take a new snapshot only when invalidation messages have been processed. The catcache machinery already requires that invalidation messages be sent before releasing the related heavyweight lock; else other backends might rely on locally-cached data rather than scanning the catalog at all. Thus, making snapshot reuse dependent on the same guarantees shouldn't break anything that wasn't already subtly broken. Patch by me. Review by Michael Paquier and Andres Freund.
This commit is contained in:
@@ -141,9 +141,10 @@ deletes index entries before deleting tuples, the super-exclusive lock
|
||||
guarantees that VACUUM can't delete any heap tuple that an indexscanning
|
||||
process might be about to visit. (This guarantee works only for simple
|
||||
indexscans that visit the heap in sync with the index scan, not for bitmap
|
||||
scans. We only need the guarantee when using non-MVCC snapshot rules such
|
||||
as SnapshotNow, so in practice this is only important for system catalog
|
||||
accesses.)
|
||||
scans. We only need the guarantee when using non-MVCC snapshot rules; in
|
||||
an MVCC snapshot, it wouldn't matter if the heap tuple were replaced with
|
||||
an unrelated tuple at the same TID, because the new tuple wouldn't be
|
||||
visible to our scan anyway.)
|
||||
|
||||
Because a page can be split even while someone holds a pin on it, it is
|
||||
possible that an indexscan will return items that are no longer stored on
|
||||
|
Reference in New Issue
Block a user