@@ -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)
370374bool
371375systable_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