@@ -361,6 +361,10 @@ systable_getnext(SysScanDesc sysscan)
361
361
/*
362
362
* systable_recheck_tuple --- recheck visibility of most-recently-fetched tuple
363
363
*
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
+ *
364
368
* This is useful to test whether an object was deleted while we waited to
365
369
* acquire lock on it.
366
370
*
@@ -370,30 +374,38 @@ systable_getnext(SysScanDesc sysscan)
370
374
bool
371
375
systable_recheck_tuple (SysScanDesc sysscan , HeapTuple tup )
372
376
{
377
+ Snapshot freshsnap ;
373
378
bool result ;
374
379
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
+
375
387
if (sysscan -> irel )
376
388
{
377
389
IndexScanDesc scan = sysscan -> iscan ;
378
390
391
+ Assert (IsMVCCSnapshot (scan -> xs_snapshot ));
379
392
Assert (tup == & scan -> xs_ctup );
380
393
Assert (BufferIsValid (scan -> xs_cbuf ));
381
394
/* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
382
395
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 );
385
397
LockBuffer (scan -> xs_cbuf , BUFFER_LOCK_UNLOCK );
386
398
}
387
399
else
388
400
{
389
401
HeapScanDesc scan = sysscan -> scan ;
390
402
403
+ Assert (IsMVCCSnapshot (scan -> rs_snapshot ));
391
404
Assert (tup == & scan -> rs_ctup );
392
405
Assert (BufferIsValid (scan -> rs_cbuf ));
393
406
/* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
394
407
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 );
397
409
LockBuffer (scan -> rs_cbuf , BUFFER_LOCK_UNLOCK );
398
410
}
399
411
return result ;
0 commit comments