diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c index 2bfe78a..2fecc88 100644 --- a/src/backend/access/index/genam.c +++ b/src/backend/access/index/genam.c @@ -362,7 +362,8 @@ systable_getnext(SysScanDesc sysscan) * systable_recheck_tuple --- recheck visibility of most-recently-fetched tuple * * This is useful to test whether an object was deleted while we waited to - * acquire lock on it. + * acquire lock on it. We recheck visibility in the style of SnapshotNow by + * checking against a fresh catalog snapshot. * * Note: we don't actually *need* the tuple to be passed in, but it's a * good crosscheck that the caller is interested in the right tuple. @@ -370,30 +371,37 @@ systable_getnext(SysScanDesc sysscan) bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup) { + Snapshot freshsnap; bool result; + /* + * For a scan using a non-MVCC snapshot like SnapshotSelf, we would simply + * reuse the old snapshot. So far, the only caller uses MVCC snapshots. + */ + freshsnap = GetCatalogSnapshot(RelationGetRelid(sysscan->heap_rel)); + if (sysscan->irel) { IndexScanDesc scan = sysscan->iscan; + Assert(IsMVCCSnapshot(scan->xs_snapshot)); Assert(tup == &scan->xs_ctup); Assert(BufferIsValid(scan->xs_cbuf)); /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */ LockBuffer(scan->xs_cbuf, BUFFER_LOCK_SHARE); - result = HeapTupleSatisfiesVisibility(tup, scan->xs_snapshot, - scan->xs_cbuf); + result = HeapTupleSatisfiesVisibility(tup, freshsnap, scan->xs_cbuf); LockBuffer(scan->xs_cbuf, BUFFER_LOCK_UNLOCK); } else { HeapScanDesc scan = sysscan->scan; + Assert(IsMVCCSnapshot(scan->rs_snapshot)); Assert(tup == &scan->rs_ctup); Assert(BufferIsValid(scan->rs_cbuf)); /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */ LockBuffer(scan->rs_cbuf, BUFFER_LOCK_SHARE); - result = HeapTupleSatisfiesVisibility(tup, scan->rs_snapshot, - scan->rs_cbuf); + result = HeapTupleSatisfiesVisibility(tup, freshsnap, scan->rs_cbuf); LockBuffer(scan->rs_cbuf, BUFFER_LOCK_UNLOCK); } return result;