Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ffcf654

Browse files
committed
Fix systable_recheck_tuple() for MVCC scan snapshots.
Since this function assumed non-MVCC snapshots, it broke when commit 568d413 switched its one caller from SnapshotNow scans to MVCC-snapshot scans. Reviewed by Robert Haas, Tom Lane and Andres Freund.
1 parent b560ec1 commit ffcf654

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/backend/access/index/genam.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ systable_getnext(SysScanDesc sysscan)
361361
/*
362362
* systable_recheck_tuple --- recheck visibility of most-recently-fetched tuple
363363
*
364+
* In particular, determine if this tuple would be visible to a catalog scan
365+
* that started now. We don't handle the case of a non-MVCC scan snapshot,
366+
* because no caller needs that yet.
367+
*
364368
* This is useful to test whether an object was deleted while we waited to
365369
* acquire lock on it.
366370
*
@@ -370,30 +374,38 @@ systable_getnext(SysScanDesc sysscan)
370374
bool
371375
systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
372376
{
377+
Snapshot freshsnap;
373378
bool result;
374379

380+
/*
381+
* Trust that LockBuffer() and HeapTupleSatisfiesMVCC() do not themselves
382+
* acquire snapshots, so we need not register the snapshot. Those
383+
* facilities are too low-level to have any business scanning tables.
384+
*/
385+
freshsnap = GetCatalogSnapshot(RelationGetRelid(sysscan->heap_rel));
386+
375387
if (sysscan->irel)
376388
{
377389
IndexScanDesc scan = sysscan->iscan;
378390

391+
Assert(IsMVCCSnapshot(scan->xs_snapshot));
379392
Assert(tup == &scan->xs_ctup);
380393
Assert(BufferIsValid(scan->xs_cbuf));
381394
/* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
382395
LockBuffer(scan->xs_cbuf, BUFFER_LOCK_SHARE);
383-
result = HeapTupleSatisfiesVisibility(tup, scan->xs_snapshot,
384-
scan->xs_cbuf);
396+
result = HeapTupleSatisfiesVisibility(tup, freshsnap, scan->xs_cbuf);
385397
LockBuffer(scan->xs_cbuf, BUFFER_LOCK_UNLOCK);
386398
}
387399
else
388400
{
389401
HeapScanDesc scan = sysscan->scan;
390402

403+
Assert(IsMVCCSnapshot(scan->rs_snapshot));
391404
Assert(tup == &scan->rs_ctup);
392405
Assert(BufferIsValid(scan->rs_cbuf));
393406
/* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
394407
LockBuffer(scan->rs_cbuf, BUFFER_LOCK_SHARE);
395-
result = HeapTupleSatisfiesVisibility(tup, scan->rs_snapshot,
396-
scan->rs_cbuf);
408+
result = HeapTupleSatisfiesVisibility(tup, freshsnap, scan->rs_cbuf);
397409
LockBuffer(scan->rs_cbuf, BUFFER_LOCK_UNLOCK);
398410
}
399411
return result;

0 commit comments

Comments
 (0)