diff options
| author | Robert Haas | 2013-07-02 13:47:01 +0000 |
|---|---|---|
| committer | Robert Haas | 2013-07-02 13:47:01 +0000 |
| commit | 568d4138c646cd7cd8a837ac244ef2caf27c6bb8 (patch) | |
| tree | 82022e9bd58a217976f94fea942f24b0c40278c0 /src/include/access | |
| parent | 384f933046dc9e9a2b416f5f7b3be30b93587c63 (diff) | |
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.
Diffstat (limited to 'src/include/access')
| -rw-r--r-- | src/include/access/heapam.h | 2 | ||||
| -rw-r--r-- | src/include/access/relscan.h | 2 |
2 files changed, 4 insertions, 0 deletions
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index baa8c50addc..0d403985e2c 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -105,6 +105,8 @@ typedef struct HeapScanDescData *HeapScanDesc; extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot, int nkeys, ScanKey key); +extern HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys, + ScanKey key); extern HeapScanDesc heap_beginscan_strat(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, bool allow_strat, bool allow_sync); diff --git a/src/include/access/relscan.h b/src/include/access/relscan.h index 5b5802820d9..3a86ca4230a 100644 --- a/src/include/access/relscan.h +++ b/src/include/access/relscan.h @@ -32,6 +32,7 @@ typedef struct HeapScanDescData bool rs_pageatatime; /* verify visibility page-at-a-time? */ bool rs_allow_strat; /* allow or disallow use of access strategy */ bool rs_allow_sync; /* allow or disallow use of syncscan */ + bool rs_temp_snap; /* unregister snapshot at scan end? */ /* state set up at initscan time */ BlockNumber rs_nblocks; /* number of blocks to scan */ @@ -101,6 +102,7 @@ typedef struct SysScanDescData Relation irel; /* NULL if doing heap scan */ HeapScanDesc scan; /* only valid in heap-scan case */ IndexScanDesc iscan; /* only valid in index-scan case */ + Snapshot snapshot; /* snapshot to unregister at end of scan */ } SysScanDescData; #endif /* RELSCAN_H */ |
