PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pg_visibility.c File Reference
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/visibilitymap.h"
#include "access/xloginsert.h"
#include "catalog/pg_type.h"
#include "catalog/storage_xlog.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "storage/read_stream.h"
#include "storage/smgr.h"
#include "utils/rel.h"
Include dependency graph for pg_visibility.c:

Go to the source code of this file.

Data Structures

struct  vbits
 
struct  corrupt_items
 
struct  collect_corrupt_items_read_stream_private
 

Typedefs

typedef struct vbits vbits
 
typedef struct corrupt_items corrupt_items
 

Functions

 PG_MODULE_MAGIC_EXT (.name="pg_visibility",.version=PG_VERSION)
 
 PG_FUNCTION_INFO_V1 (pg_visibility_map)
 
 PG_FUNCTION_INFO_V1 (pg_visibility_map_rel)
 
 PG_FUNCTION_INFO_V1 (pg_visibility)
 
 PG_FUNCTION_INFO_V1 (pg_visibility_rel)
 
 PG_FUNCTION_INFO_V1 (pg_visibility_map_summary)
 
 PG_FUNCTION_INFO_V1 (pg_check_frozen)
 
 PG_FUNCTION_INFO_V1 (pg_check_visible)
 
 PG_FUNCTION_INFO_V1 (pg_truncate_visibility_map)
 
static TupleDesc pg_visibility_tupdesc (bool include_blkno, bool include_pd)
 
static vbitscollect_visibility_data (Oid relid, bool include_pd)
 
static corrupt_itemscollect_corrupt_items (Oid relid, bool all_visible, bool all_frozen)
 
static void record_corrupt_item (corrupt_items *items, ItemPointer tid)
 
static bool tuple_all_visible (HeapTuple tup, TransactionId OldestXmin, Buffer buffer)
 
static void check_relation_relkind (Relation rel)
 
Datum pg_visibility_map (PG_FUNCTION_ARGS)
 
Datum pg_visibility (PG_FUNCTION_ARGS)
 
Datum pg_visibility_map_rel (PG_FUNCTION_ARGS)
 
Datum pg_visibility_rel (PG_FUNCTION_ARGS)
 
Datum pg_visibility_map_summary (PG_FUNCTION_ARGS)
 
Datum pg_check_frozen (PG_FUNCTION_ARGS)
 
Datum pg_check_visible (PG_FUNCTION_ARGS)
 
Datum pg_truncate_visibility_map (PG_FUNCTION_ARGS)
 
static TransactionId GetStrictOldestNonRemovableTransactionId (Relation rel)
 
static BlockNumber collect_corrupt_items_read_stream_next_block (ReadStream *stream, void *callback_private_data, void *per_buffer_data)
 

Typedef Documentation

◆ corrupt_items

typedef struct corrupt_items corrupt_items

◆ vbits

typedef struct vbits vbits

Function Documentation

◆ check_relation_relkind()

static void check_relation_relkind ( Relation  rel)
static

Definition at line 938 of file pg_visibility.c.

939{
940 if (!RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind))
942 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
943 errmsg("relation \"%s\" is of wrong relation kind",
946}
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
#define RelationGetRelationName(relation)
Definition: rel.h:547
Form_pg_class rd_rel
Definition: rel.h:111

References ereport, errcode(), errdetail_relkind_not_supported(), errmsg(), ERROR, RelationData::rd_rel, collect_corrupt_items_read_stream_private::rel, and RelationGetRelationName.

Referenced by collect_corrupt_items(), collect_visibility_data(), pg_truncate_visibility_map(), pg_visibility(), pg_visibility_map(), and pg_visibility_map_summary().

◆ collect_corrupt_items()

static corrupt_items * collect_corrupt_items ( Oid  relid,
bool  all_visible,
bool  all_frozen 
)
static

Definition at line 711 of file pg_visibility.c.

712{
713 Relation rel;
715 Buffer vmbuffer = InvalidBuffer;
719 ReadStream *stream;
720 Buffer buffer;
721
723
724 /* Only some relkinds have a visibility map */
726
727 if (all_visible)
729
730 /*
731 * Guess an initial array size. We don't expect many corrupted tuples, so
732 * start with a small array. This function uses the "next" field to track
733 * the next offset where we can store an item (which is the same thing as
734 * the number of items found so far) and the "count" field to track the
735 * number of entries allocated. We'll repurpose these fields before
736 * returning.
737 */
738 items = palloc0(sizeof(corrupt_items));
739 items->next = 0;
740 items->count = 64;
741 items->tids = palloc(items->count * sizeof(ItemPointerData));
742
743 p.current_blocknum = 0;
744 p.last_exclusive = RelationGetNumberOfBlocks(rel);
745 p.rel = rel;
746 p.vmbuffer = InvalidBuffer;
747 p.all_frozen = all_frozen;
748 p.all_visible = all_visible;
750 bstrategy,
751 rel,
754 &p,
755 0);
756
757 /* Loop over every block in the relation. */
758 while ((buffer = read_stream_next_buffer(stream, NULL)) != InvalidBuffer)
759 {
760 bool check_frozen = all_frozen;
761 bool check_visible = all_visible;
762 Page page;
763 OffsetNumber offnum,
764 maxoff;
765 BlockNumber blkno;
766
767 /* Make sure we are interruptible. */
769
771
772 page = BufferGetPage(buffer);
773 maxoff = PageGetMaxOffsetNumber(page);
774 blkno = BufferGetBlockNumber(buffer);
775
776 /*
777 * The visibility map bits might have changed while we were acquiring
778 * the page lock. Recheck to avoid returning spurious results.
779 */
780 if (check_frozen && !VM_ALL_FROZEN(rel, blkno, &vmbuffer))
781 check_frozen = false;
782 if (check_visible && !VM_ALL_VISIBLE(rel, blkno, &vmbuffer))
783 check_visible = false;
784 if (!check_visible && !check_frozen)
785 {
786 UnlockReleaseBuffer(buffer);
787 continue;
788 }
789
790 /* Iterate over each tuple on the page. */
791 for (offnum = FirstOffsetNumber;
792 offnum <= maxoff;
793 offnum = OffsetNumberNext(offnum))
794 {
795 HeapTupleData tuple;
796 ItemId itemid;
797
798 itemid = PageGetItemId(page, offnum);
799
800 /* Unused or redirect line pointers are of no interest. */
801 if (!ItemIdIsUsed(itemid) || ItemIdIsRedirected(itemid))
802 continue;
803
804 /* Dead line pointers are neither all-visible nor frozen. */
805 if (ItemIdIsDead(itemid))
806 {
807 ItemPointerSet(&(tuple.t_self), blkno, offnum);
809 continue;
810 }
811
812 /* Initialize a HeapTupleData structure for checks below. */
813 ItemPointerSet(&(tuple.t_self), blkno, offnum);
814 tuple.t_data = (HeapTupleHeader) PageGetItem(page, itemid);
815 tuple.t_len = ItemIdGetLength(itemid);
816 tuple.t_tableOid = relid;
817
818 /*
819 * If we're checking whether the page is all-visible, we expect
820 * the tuple to be all-visible.
821 */
822 if (check_visible &&
823 !tuple_all_visible(&tuple, OldestXmin, buffer))
824 {
825 TransactionId RecomputedOldestXmin;
826
827 /*
828 * Time has passed since we computed OldestXmin, so it's
829 * possible that this tuple is all-visible in reality even
830 * though it doesn't appear so based on our
831 * previously-computed value. Let's compute a new value so we
832 * can be certain whether there is a problem.
833 *
834 * From a concurrency point of view, it sort of sucks to
835 * retake ProcArrayLock here while we're holding the buffer
836 * exclusively locked, but it should be safe against
837 * deadlocks, because surely
838 * GetStrictOldestNonRemovableTransactionId() should never
839 * take a buffer lock. And this shouldn't happen often, so
840 * it's worth being careful so as to avoid false positives.
841 */
842 RecomputedOldestXmin = GetStrictOldestNonRemovableTransactionId(rel);
843
844 if (!TransactionIdPrecedes(OldestXmin, RecomputedOldestXmin))
846 else
847 {
848 OldestXmin = RecomputedOldestXmin;
849 if (!tuple_all_visible(&tuple, OldestXmin, buffer))
851 }
852 }
853
854 /*
855 * If we're checking whether the page is all-frozen, we expect the
856 * tuple to be in a state where it will never need freezing.
857 */
858 if (check_frozen)
859 {
862 }
863 }
864
865 UnlockReleaseBuffer(buffer);
866 }
867 read_stream_end(stream);
868
869 /* Clean up. */
870 if (vmbuffer != InvalidBuffer)
872 if (p.vmbuffer != InvalidBuffer)
873 ReleaseBuffer(p.vmbuffer);
875
876 /*
877 * Before returning, repurpose the fields to match caller's expectations.
878 * next is now the next item that should be read (rather than written) and
879 * count is now the number of items we wrote (rather than the number we
880 * allocated).
881 */
882 items->count = items->next;
883 items->next = 0;
884
885 return items;
886}
uint32 BlockNumber
Definition: block.h:31
int Buffer
Definition: buf.h:23
#define InvalidBuffer
Definition: buf.h:25
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:3795
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4917
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4934
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:5151
@ BAS_BULKREAD
Definition: bufmgr.h:36
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:191
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:274
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:401
static Item PageGetItem(const PageData *page, const ItemIdData *itemId)
Definition: bufpage.h:354
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
Definition: bufpage.h:244
PageData * Page
Definition: bufpage.h:82
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
Definition: bufpage.h:372
uint32 TransactionId
Definition: c.h:623
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:541
bool heap_tuple_needs_eventual_freeze(HeapTupleHeader tuple)
Definition: heapam.c:7799
HeapTupleHeaderData * HeapTupleHeader
Definition: htup.h:23
#define ItemIdGetLength(itemId)
Definition: itemid.h:59
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
#define ItemIdIsUsed(itemId)
Definition: itemid.h:92
#define ItemIdIsRedirected(itemId)
Definition: itemid.h:106
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
Definition: itemptr.h:135
#define AccessShareLock
Definition: lockdefs.h:36
void * palloc0(Size size)
Definition: mcxt.c:1347
void * palloc(Size size)
Definition: mcxt.c:1317
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
uint16 OffsetNumber
Definition: off.h:24
#define FirstOffsetNumber
Definition: off.h:27
static BlockNumber collect_corrupt_items_read_stream_next_block(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
static void check_relation_relkind(Relation rel)
static void record_corrupt_item(corrupt_items *items, ItemPointer tid)
static TransactionId GetStrictOldestNonRemovableTransactionId(Relation rel)
static bool tuple_all_visible(HeapTuple tup, TransactionId OldestXmin, Buffer buffer)
Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
Definition: read_stream.c:742
ReadStream * read_stream_begin_relation(int flags, BufferAccessStrategy strategy, Relation rel, ForkNumber forknum, ReadStreamBlockNumberCB callback, void *callback_private_data, size_t per_buffer_data_size)
Definition: read_stream.c:688
void read_stream_end(ReadStream *stream)
Definition: read_stream.c:1023
#define READ_STREAM_FULL
Definition: read_stream.h:43
@ MAIN_FORKNUM
Definition: relpath.h:58
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:47
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid t_tableOid
Definition: htup.h:66
static ItemArray items
Definition: test_tidstore.c:48
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280
#define InvalidTransactionId
Definition: transam.h:31
#define VM_ALL_VISIBLE(r, b, v)
Definition: visibilitymap.h:24
#define VM_ALL_FROZEN(r, b, v)
Definition: visibilitymap.h:26

References AccessShareLock, collect_corrupt_items_read_stream_private::all_frozen, collect_corrupt_items_read_stream_private::all_visible, BAS_BULKREAD, BUFFER_LOCK_SHARE, BufferGetBlockNumber(), BufferGetPage(), CHECK_FOR_INTERRUPTS, check_relation_relkind(), collect_corrupt_items_read_stream_next_block(), collect_corrupt_items_read_stream_private::current_blocknum, FirstOffsetNumber, GetAccessStrategy(), GetStrictOldestNonRemovableTransactionId(), heap_tuple_needs_eventual_freeze(), InvalidBuffer, InvalidTransactionId, ItemIdGetLength, ItemIdIsDead, ItemIdIsRedirected, ItemIdIsUsed, ItemPointerSet(), items, collect_corrupt_items_read_stream_private::last_exclusive, LockBuffer(), MAIN_FORKNUM, OffsetNumberNext, PageGetItem(), PageGetItemId(), PageGetMaxOffsetNumber(), palloc(), palloc0(), read_stream_begin_relation(), read_stream_end(), READ_STREAM_FULL, read_stream_next_buffer(), record_corrupt_item(), collect_corrupt_items_read_stream_private::rel, relation_close(), relation_open(), RelationGetNumberOfBlocks, ReleaseBuffer(), HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, TransactionIdPrecedes(), tuple_all_visible(), UnlockReleaseBuffer(), VM_ALL_FROZEN, VM_ALL_VISIBLE, and collect_corrupt_items_read_stream_private::vmbuffer.

Referenced by pg_check_frozen(), and pg_check_visible().

◆ collect_corrupt_items_read_stream_next_block()

static BlockNumber collect_corrupt_items_read_stream_next_block ( ReadStream stream,
void *  callback_private_data,
void *  per_buffer_data 
)
static

Definition at line 669 of file pg_visibility.c.

672{
673 struct collect_corrupt_items_read_stream_private *p = callback_private_data;
674
676 {
677 bool check_frozen = false;
678 bool check_visible = false;
679
680 /* Make sure we are interruptible. */
682
684 check_frozen = true;
686 check_visible = true;
687 if (!check_visible && !check_frozen)
688 continue;
689
690 return p->current_blocknum++;
691 }
692
693 return InvalidBlockNumber;
694}
#define InvalidBlockNumber
Definition: block.h:33

References collect_corrupt_items_read_stream_private::all_frozen, collect_corrupt_items_read_stream_private::all_visible, CHECK_FOR_INTERRUPTS, collect_corrupt_items_read_stream_private::current_blocknum, InvalidBlockNumber, collect_corrupt_items_read_stream_private::last_exclusive, collect_corrupt_items_read_stream_private::rel, VM_ALL_FROZEN, VM_ALL_VISIBLE, and collect_corrupt_items_read_stream_private::vmbuffer.

Referenced by collect_corrupt_items().

◆ collect_visibility_data()

static vbits * collect_visibility_data ( Oid  relid,
bool  include_pd 
)
static

Definition at line 503 of file pg_visibility.c.

504{
505 Relation rel;
506 BlockNumber nblocks;
507 vbits *info;
508 BlockNumber blkno;
509 Buffer vmbuffer = InvalidBuffer;
512 ReadStream *stream = NULL;
513
514 rel = relation_open(relid, AccessShareLock);
515
516 /* Only some relkinds have a visibility map */
518
519 nblocks = RelationGetNumberOfBlocks(rel);
520 info = palloc0(offsetof(vbits, bits) + nblocks);
521 info->next = 0;
522 info->count = nblocks;
523
524 /* Create a stream if reading main fork. */
525 if (include_pd)
526 {
527 p.current_blocknum = 0;
528 p.last_exclusive = nblocks;
530 bstrategy,
531 rel,
534 &p,
535 0);
536 }
537
538 for (blkno = 0; blkno < nblocks; ++blkno)
539 {
540 int32 mapbits;
541
542 /* Make sure we are interruptible. */
544
545 /* Get map info. */
546 mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
547 if ((mapbits & VISIBILITYMAP_ALL_VISIBLE) != 0)
548 info->bits[blkno] |= (1 << 0);
549 if ((mapbits & VISIBILITYMAP_ALL_FROZEN) != 0)
550 info->bits[blkno] |= (1 << 1);
551
552 /*
553 * Page-level data requires reading every block, so only get it if the
554 * caller needs it. Use a buffer access strategy, too, to prevent
555 * cache-trashing.
556 */
557 if (include_pd)
558 {
559 Buffer buffer;
560 Page page;
561
562 buffer = read_stream_next_buffer(stream, NULL);
564
565 page = BufferGetPage(buffer);
566 if (PageIsAllVisible(page))
567 info->bits[blkno] |= (1 << 2);
568
569 UnlockReleaseBuffer(buffer);
570 }
571 }
572
573 if (include_pd)
574 {
576 read_stream_end(stream);
577 }
578
579 /* Clean up. */
580 if (vmbuffer != InvalidBuffer)
581 ReleaseBuffer(vmbuffer);
583
584 return info;
585}
static bool PageIsAllVisible(const PageData *page)
Definition: bufpage.h:429
int32_t int32
Definition: c.h:498
Assert(PointerIsAligned(start, uint64))
BlockNumber block_range_read_stream_cb(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
Definition: read_stream.c:158
BlockNumber next
Definition: pg_visibility.c:35
uint8 bits[FLEXIBLE_ARRAY_MEMBER]
Definition: pg_visibility.c:37
BlockNumber count
Definition: pg_visibility.c:36
uint8 visibilitymap_get_status(Relation rel, BlockNumber heapBlk, Buffer *vmbuf)
#define VISIBILITYMAP_ALL_FROZEN
#define VISIBILITYMAP_ALL_VISIBLE

References AccessShareLock, Assert(), BAS_BULKREAD, vbits::bits, block_range_read_stream_cb(), BUFFER_LOCK_SHARE, BufferGetPage(), CHECK_FOR_INTERRUPTS, check_relation_relkind(), vbits::count, BlockRangeReadStreamPrivate::current_blocknum, GetAccessStrategy(), InvalidBuffer, BlockRangeReadStreamPrivate::last_exclusive, LockBuffer(), MAIN_FORKNUM, vbits::next, PageIsAllVisible(), palloc0(), read_stream_begin_relation(), read_stream_end(), READ_STREAM_FULL, read_stream_next_buffer(), relation_close(), relation_open(), RelationGetNumberOfBlocks, ReleaseBuffer(), UnlockReleaseBuffer(), VISIBILITYMAP_ALL_FROZEN, VISIBILITYMAP_ALL_VISIBLE, and visibilitymap_get_status().

Referenced by pg_visibility_map_rel(), and pg_visibility_rel().

◆ GetStrictOldestNonRemovableTransactionId()

static TransactionId GetStrictOldestNonRemovableTransactionId ( Relation  rel)
static

Definition at line 620 of file pg_visibility.c.

621{
622 RunningTransactions runningTransactions;
623
624 if (RecoveryInProgress())
625 {
626 TransactionId result;
627
628 /* As we ignore KnownAssignedXids on standby, just pick nextXid */
629 LWLockAcquire(XidGenLock, LW_SHARED);
631 LWLockRelease(XidGenLock);
632 return result;
633 }
634 else if (rel == NULL || rel->rd_rel->relisshared)
635 {
636 /* Shared relation: take into account all running xids */
637 runningTransactions = GetRunningTransactionData();
638 LWLockRelease(ProcArrayLock);
639 LWLockRelease(XidGenLock);
640 return runningTransactions->oldestRunningXid;
641 }
642 else if (!RELATION_IS_LOCAL(rel))
643 {
644 /*
645 * Normal relation: take into account xids running within the current
646 * database
647 */
648 runningTransactions = GetRunningTransactionData();
649 LWLockRelease(ProcArrayLock);
650 LWLockRelease(XidGenLock);
651 return runningTransactions->oldestDatabaseRunningXid;
652 }
653 else
654 {
655 /*
656 * For temporary relations, ComputeXidHorizons() uses only
657 * TransamVariables->latestCompletedXid and MyProc->xid. These two
658 * shouldn't go backwards. So we're fine with this horizon.
659 */
661 }
662}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1180
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1900
@ LW_SHARED
Definition: lwlock.h:115
TransactionId GetOldestNonRemovableTransactionId(Relation rel)
Definition: procarray.c:2005
RunningTransactions GetRunningTransactionData(void)
Definition: procarray.c:2689
#define RELATION_IS_LOCAL(relation)
Definition: rel.h:656
TransactionId oldestRunningXid
Definition: standby.h:92
TransactionId oldestDatabaseRunningXid
Definition: standby.h:93
FullTransactionId nextXid
Definition: transam.h:220
#define XidFromFullTransactionId(x)
Definition: transam.h:48
TransamVariablesData * TransamVariables
Definition: varsup.c:34
bool RecoveryInProgress(void)
Definition: xlog.c:6380

References GetOldestNonRemovableTransactionId(), GetRunningTransactionData(), LW_SHARED, LWLockAcquire(), LWLockRelease(), TransamVariablesData::nextXid, RunningTransactionsData::oldestDatabaseRunningXid, RunningTransactionsData::oldestRunningXid, RelationData::rd_rel, RecoveryInProgress(), RELATION_IS_LOCAL, TransamVariables, and XidFromFullTransactionId.

Referenced by collect_corrupt_items().

◆ pg_check_frozen()

Datum pg_check_frozen ( PG_FUNCTION_ARGS  )

Definition at line 324 of file pg_visibility.c.

325{
326 FuncCallContext *funcctx;
328
329 if (SRF_IS_FIRSTCALL())
330 {
331 Oid relid = PG_GETARG_OID(0);
332 MemoryContext oldcontext;
333
334 funcctx = SRF_FIRSTCALL_INIT();
335 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
336 /* collect_corrupt_items will verify the relkind */
337 funcctx->user_fctx = collect_corrupt_items(relid, false, true);
338 MemoryContextSwitchTo(oldcontext);
339 }
340
341 funcctx = SRF_PERCALL_SETUP();
342 items = (corrupt_items *) funcctx->user_fctx;
343
344 if (items->next < items->count)
345 SRF_RETURN_NEXT(funcctx, PointerGetDatum(&items->tids[items->next++]));
346
347 SRF_RETURN_DONE(funcctx);
348}
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:304
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:308
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:310
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:306
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:328
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
static corrupt_items * collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen)
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
unsigned int Oid
Definition: postgres_ext.h:30
void * user_fctx
Definition: funcapi.h:82
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101

References collect_corrupt_items(), if(), items, MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, PG_GETARG_OID, PointerGetDatum(), SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, and FuncCallContext::user_fctx.

◆ pg_check_visible()

Datum pg_check_visible ( PG_FUNCTION_ARGS  )

Definition at line 356 of file pg_visibility.c.

357{
358 FuncCallContext *funcctx;
360
361 if (SRF_IS_FIRSTCALL())
362 {
363 Oid relid = PG_GETARG_OID(0);
364 MemoryContext oldcontext;
365
366 funcctx = SRF_FIRSTCALL_INIT();
367 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
368 /* collect_corrupt_items will verify the relkind */
369 funcctx->user_fctx = collect_corrupt_items(relid, true, false);
370 MemoryContextSwitchTo(oldcontext);
371 }
372
373 funcctx = SRF_PERCALL_SETUP();
374 items = (corrupt_items *) funcctx->user_fctx;
375
376 if (items->next < items->count)
377 SRF_RETURN_NEXT(funcctx, PointerGetDatum(&items->tids[items->next++]));
378
379 SRF_RETURN_DONE(funcctx);
380}

References collect_corrupt_items(), if(), items, MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, PG_GETARG_OID, PointerGetDatum(), SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, and FuncCallContext::user_fctx.

◆ PG_FUNCTION_INFO_V1() [1/8]

PG_FUNCTION_INFO_V1 ( pg_check_frozen  )

◆ PG_FUNCTION_INFO_V1() [2/8]

PG_FUNCTION_INFO_V1 ( pg_check_visible  )

◆ PG_FUNCTION_INFO_V1() [3/8]

PG_FUNCTION_INFO_V1 ( pg_truncate_visibility_map  )

◆ PG_FUNCTION_INFO_V1() [4/8]

PG_FUNCTION_INFO_V1 ( pg_visibility  )

◆ PG_FUNCTION_INFO_V1() [5/8]

PG_FUNCTION_INFO_V1 ( pg_visibility_map  )

◆ PG_FUNCTION_INFO_V1() [6/8]

PG_FUNCTION_INFO_V1 ( pg_visibility_map_rel  )

◆ PG_FUNCTION_INFO_V1() [7/8]

PG_FUNCTION_INFO_V1 ( pg_visibility_map_summary  )

◆ PG_FUNCTION_INFO_V1() [8/8]

PG_FUNCTION_INFO_V1 ( pg_visibility_rel  )

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "pg_visibility",
version = PG_VERSION 
)

◆ pg_truncate_visibility_map()

Datum pg_truncate_visibility_map ( PG_FUNCTION_ARGS  )

Definition at line 391 of file pg_visibility.c.

392{
393 Oid relid = PG_GETARG_OID(0);
394 Relation rel;
395 ForkNumber fork;
396 BlockNumber block;
397 BlockNumber old_block;
398
400
401 /* Only some relkinds have a visibility map */
403
404 /* Forcibly reset cached file size */
406
407 /* Compute new and old size before entering critical section. */
409 block = visibilitymap_prepare_truncate(rel, 0);
410 old_block = BlockNumberIsValid(block) ? smgrnblocks(RelationGetSmgr(rel), fork) : 0;
411
412 /*
413 * WAL-logging, buffer dropping, file truncation must be atomic and all on
414 * one side of a checkpoint. See RelationTruncate() for discussion.
415 */
419
420 if (RelationNeedsWAL(rel))
421 {
422 XLogRecPtr lsn;
423 xl_smgr_truncate xlrec;
424
425 xlrec.blkno = 0;
426 xlrec.rlocator = rel->rd_locator;
427 xlrec.flags = SMGR_TRUNCATE_VM;
428
430 XLogRegisterData(&xlrec, sizeof(xlrec));
431
432 lsn = XLogInsert(RM_SMGR_ID,
434 XLogFlush(lsn);
435 }
436
437 if (BlockNumberIsValid(block))
438 smgrtruncate(RelationGetSmgr(rel), &fork, 1, &old_block, &block);
439
442
443 /*
444 * Release the lock right away, not at commit time.
445 *
446 * It would be a problem to release the lock prior to commit if this
447 * truncate operation sends any transactional invalidation messages. Other
448 * backends would potentially be able to lock the relation without
449 * processing them in the window of time between when we release the lock
450 * here and when we sent the messages at our eventual commit. However,
451 * we're currently only sending a non-transactional smgr invalidation,
452 * which will have been posted to shared memory immediately from within
453 * smgr_truncate. Therefore, there should be no race here.
454 *
455 * The reason why it's desirable to release the lock early here is because
456 * of the possibility that someone will need to use this to blow away many
457 * visibility map forks at once. If we can't release the lock until
458 * commit time, the transaction doing this will accumulate
459 * AccessExclusiveLocks on all of those relations at the same time, which
460 * is undesirable. However, if this turns out to be unsafe we may have no
461 * choice...
462 */
464
465 /* Nothing to return. */
467}
static bool BlockNumberIsValid(BlockNumber blockNumber)
Definition: block.h:71
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define START_CRIT_SECTION()
Definition: miscadmin.h:149
#define END_CRIT_SECTION()
Definition: miscadmin.h:151
#define DELAY_CHKPT_START
Definition: proc.h:120
#define DELAY_CHKPT_COMPLETE
Definition: proc.h:121
static SMgrRelation RelationGetSmgr(Relation rel)
Definition: rel.h:575
#define RelationNeedsWAL(relation)
Definition: rel.h:636
ForkNumber
Definition: relpath.h:56
@ VISIBILITYMAP_FORKNUM
Definition: relpath.h:60
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:767
void smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks, BlockNumber *old_nblocks, BlockNumber *nblocks)
Definition: smgr.c:823
PGPROC * MyProc
Definition: proc.c:66
#define SMGR_TRUNCATE_VM
Definition: storage_xlog.h:41
#define XLOG_SMGR_TRUNCATE
Definition: storage_xlog.h:31
int delayChkptFlags
Definition: proc.h:241
RelFileLocator rd_locator
Definition: rel.h:57
BlockNumber smgr_cached_nblocks[MAX_FORKNUM+1]
Definition: smgr.h:46
RelFileLocator rlocator
Definition: storage_xlog.h:49
BlockNumber blkno
Definition: storage_xlog.h:48
BlockNumber visibilitymap_prepare_truncate(Relation rel, BlockNumber nheapblocks)
void XLogFlush(XLogRecPtr record)
Definition: xlog.c:2790
uint64 XLogRecPtr
Definition: xlogdefs.h:21
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:474
void XLogRegisterData(const void *data, uint32 len)
Definition: xloginsert.c:364
void XLogBeginInsert(void)
Definition: xloginsert.c:149
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:82

References AccessExclusiveLock, Assert(), xl_smgr_truncate::blkno, BlockNumberIsValid(), check_relation_relkind(), DELAY_CHKPT_COMPLETE, DELAY_CHKPT_START, PGPROC::delayChkptFlags, END_CRIT_SECTION, xl_smgr_truncate::flags, InvalidBlockNumber, MyProc, PG_GETARG_OID, PG_RETURN_VOID, RelationData::rd_locator, relation_close(), relation_open(), RelationGetSmgr(), RelationNeedsWAL, xl_smgr_truncate::rlocator, SMgrRelationData::smgr_cached_nblocks, SMGR_TRUNCATE_VM, smgrnblocks(), smgrtruncate(), START_CRIT_SECTION, VISIBILITYMAP_FORKNUM, visibilitymap_prepare_truncate(), XLOG_SMGR_TRUNCATE, XLogBeginInsert(), XLogFlush(), XLogInsert(), XLogRegisterData(), and XLR_SPECIAL_REL_UPDATE.

◆ pg_visibility()

Datum pg_visibility ( PG_FUNCTION_ARGS  )

Definition at line 123 of file pg_visibility.c.

124{
125 Oid relid = PG_GETARG_OID(0);
126 int64 blkno = PG_GETARG_INT64(1);
127 int32 mapbits;
128 Relation rel;
129 Buffer vmbuffer = InvalidBuffer;
130 Buffer buffer;
131 Page page;
132 TupleDesc tupdesc;
133 Datum values[3];
134 bool nulls[3] = {0};
135
136 rel = relation_open(relid, AccessShareLock);
137
138 /* Only some relkinds have a visibility map */
140
141 if (blkno < 0 || blkno > MaxBlockNumber)
143 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
144 errmsg("invalid block number")));
145
146 tupdesc = pg_visibility_tupdesc(false, true);
147
148 mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
149 if (vmbuffer != InvalidBuffer)
150 ReleaseBuffer(vmbuffer);
151 values[0] = BoolGetDatum((mapbits & VISIBILITYMAP_ALL_VISIBLE) != 0);
152 values[1] = BoolGetDatum((mapbits & VISIBILITYMAP_ALL_FROZEN) != 0);
153
154 /* Here we have to explicitly check rel size ... */
155 if (blkno < RelationGetNumberOfBlocks(rel))
156 {
157 buffer = ReadBuffer(rel, blkno);
159
160 page = BufferGetPage(buffer);
162
163 UnlockReleaseBuffer(buffer);
164 }
165 else
166 {
167 /* As with the vismap, silently return 0 for pages past EOF */
168 values[2] = BoolGetDatum(false);
169 }
170
172
174}
#define MaxBlockNumber
Definition: block.h:35
static Datum values[MAXATTR]
Definition: bootstrap.c:151
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:751
int64_t int64
Definition: c.h:499
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
static TupleDesc pg_visibility_tupdesc(bool include_blkno, bool include_pd)
uintptr_t Datum
Definition: postgres.h:69
static Datum BoolGetDatum(bool X)
Definition: postgres.h:107

References AccessShareLock, BoolGetDatum(), BUFFER_LOCK_SHARE, BufferGetPage(), check_relation_relkind(), ereport, errcode(), errmsg(), ERROR, heap_form_tuple(), HeapTupleGetDatum(), InvalidBuffer, LockBuffer(), MaxBlockNumber, PageIsAllVisible(), PG_GETARG_INT64, PG_GETARG_OID, PG_RETURN_DATUM, pg_visibility_tupdesc(), ReadBuffer(), relation_close(), relation_open(), RelationGetNumberOfBlocks, ReleaseBuffer(), UnlockReleaseBuffer(), values, VISIBILITYMAP_ALL_FROZEN, VISIBILITYMAP_ALL_VISIBLE, and visibilitymap_get_status().

◆ pg_visibility_map()

Datum pg_visibility_map ( PG_FUNCTION_ARGS  )

Definition at line 84 of file pg_visibility.c.

85{
86 Oid relid = PG_GETARG_OID(0);
87 int64 blkno = PG_GETARG_INT64(1);
88 int32 mapbits;
89 Relation rel;
90 Buffer vmbuffer = InvalidBuffer;
91 TupleDesc tupdesc;
92 Datum values[2];
93 bool nulls[2] = {0};
94
95 rel = relation_open(relid, AccessShareLock);
96
97 /* Only some relkinds have a visibility map */
99
100 if (blkno < 0 || blkno > MaxBlockNumber)
102 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
103 errmsg("invalid block number")));
104
105 tupdesc = pg_visibility_tupdesc(false, false);
106
107 mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
108 if (vmbuffer != InvalidBuffer)
109 ReleaseBuffer(vmbuffer);
110 values[0] = BoolGetDatum((mapbits & VISIBILITYMAP_ALL_VISIBLE) != 0);
111 values[1] = BoolGetDatum((mapbits & VISIBILITYMAP_ALL_FROZEN) != 0);
112
114
116}

References AccessShareLock, BoolGetDatum(), check_relation_relkind(), ereport, errcode(), errmsg(), ERROR, heap_form_tuple(), HeapTupleGetDatum(), InvalidBuffer, MaxBlockNumber, PG_GETARG_INT64, PG_GETARG_OID, PG_RETURN_DATUM, pg_visibility_tupdesc(), relation_close(), relation_open(), ReleaseBuffer(), values, VISIBILITYMAP_ALL_FROZEN, VISIBILITYMAP_ALL_VISIBLE, and visibilitymap_get_status().

◆ pg_visibility_map_rel()

Datum pg_visibility_map_rel ( PG_FUNCTION_ARGS  )

Definition at line 180 of file pg_visibility.c.

181{
182 FuncCallContext *funcctx;
183 vbits *info;
184
185 if (SRF_IS_FIRSTCALL())
186 {
187 Oid relid = PG_GETARG_OID(0);
188 MemoryContext oldcontext;
189
190 funcctx = SRF_FIRSTCALL_INIT();
191 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
192 funcctx->tuple_desc = pg_visibility_tupdesc(true, false);
193 /* collect_visibility_data will verify the relkind */
194 funcctx->user_fctx = collect_visibility_data(relid, false);
195 MemoryContextSwitchTo(oldcontext);
196 }
197
198 funcctx = SRF_PERCALL_SETUP();
199 info = (vbits *) funcctx->user_fctx;
200
201 if (info->next < info->count)
202 {
203 Datum values[3];
204 bool nulls[3] = {0};
205 HeapTuple tuple;
206
207 values[0] = Int64GetDatum(info->next);
208 values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
209 values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
210 info->next++;
211
212 tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
213 SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
214 }
215
216 SRF_RETURN_DONE(funcctx);
217}
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
static vbits * collect_visibility_data(Oid relid, bool include_pd)
TupleDesc tuple_desc
Definition: funcapi.h:112

References vbits::bits, BoolGetDatum(), collect_visibility_data(), vbits::count, heap_form_tuple(), HeapTupleGetDatum(), if(), Int64GetDatum(), MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, vbits::next, PG_GETARG_OID, pg_visibility_tupdesc(), SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, FuncCallContext::tuple_desc, FuncCallContext::user_fctx, and values.

◆ pg_visibility_map_summary()

Datum pg_visibility_map_summary ( PG_FUNCTION_ARGS  )

Definition at line 269 of file pg_visibility.c.

270{
271 Oid relid = PG_GETARG_OID(0);
272 Relation rel;
273 BlockNumber nblocks;
274 BlockNumber blkno;
275 Buffer vmbuffer = InvalidBuffer;
276 int64 all_visible = 0;
277 int64 all_frozen = 0;
278 TupleDesc tupdesc;
279 Datum values[2];
280 bool nulls[2] = {0};
281
282 rel = relation_open(relid, AccessShareLock);
283
284 /* Only some relkinds have a visibility map */
286
287 nblocks = RelationGetNumberOfBlocks(rel);
288
289 for (blkno = 0; blkno < nblocks; ++blkno)
290 {
291 int32 mapbits;
292
293 /* Make sure we are interruptible. */
295
296 /* Get map info. */
297 mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
298 if ((mapbits & VISIBILITYMAP_ALL_VISIBLE) != 0)
299 ++all_visible;
300 if ((mapbits & VISIBILITYMAP_ALL_FROZEN) != 0)
301 ++all_frozen;
302 }
303
304 /* Clean up. */
305 if (vmbuffer != InvalidBuffer)
306 ReleaseBuffer(vmbuffer);
308
309 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
310 elog(ERROR, "return type must be a row type");
311
312 values[0] = Int64GetDatum(all_visible);
313 values[1] = Int64GetDatum(all_frozen);
314
316}
#define elog(elevel,...)
Definition: elog.h:225
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149

References AccessShareLock, CHECK_FOR_INTERRUPTS, check_relation_relkind(), elog, ERROR, get_call_result_type(), heap_form_tuple(), HeapTupleGetDatum(), Int64GetDatum(), InvalidBuffer, PG_GETARG_OID, PG_RETURN_DATUM, relation_close(), relation_open(), RelationGetNumberOfBlocks, ReleaseBuffer(), TYPEFUNC_COMPOSITE, values, VISIBILITYMAP_ALL_FROZEN, VISIBILITYMAP_ALL_VISIBLE, and visibilitymap_get_status().

◆ pg_visibility_rel()

Datum pg_visibility_rel ( PG_FUNCTION_ARGS  )

Definition at line 224 of file pg_visibility.c.

225{
226 FuncCallContext *funcctx;
227 vbits *info;
228
229 if (SRF_IS_FIRSTCALL())
230 {
231 Oid relid = PG_GETARG_OID(0);
232 MemoryContext oldcontext;
233
234 funcctx = SRF_FIRSTCALL_INIT();
235 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
236 funcctx->tuple_desc = pg_visibility_tupdesc(true, true);
237 /* collect_visibility_data will verify the relkind */
238 funcctx->user_fctx = collect_visibility_data(relid, true);
239 MemoryContextSwitchTo(oldcontext);
240 }
241
242 funcctx = SRF_PERCALL_SETUP();
243 info = (vbits *) funcctx->user_fctx;
244
245 if (info->next < info->count)
246 {
247 Datum values[4];
248 bool nulls[4] = {0};
249 HeapTuple tuple;
250
251 values[0] = Int64GetDatum(info->next);
252 values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
253 values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
254 values[3] = BoolGetDatum((info->bits[info->next] & (1 << 2)) != 0);
255 info->next++;
256
257 tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
258 SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
259 }
260
261 SRF_RETURN_DONE(funcctx);
262}

References vbits::bits, BoolGetDatum(), collect_visibility_data(), vbits::count, heap_form_tuple(), HeapTupleGetDatum(), if(), Int64GetDatum(), MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, vbits::next, PG_GETARG_OID, pg_visibility_tupdesc(), SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, FuncCallContext::tuple_desc, FuncCallContext::user_fctx, and values.

◆ pg_visibility_tupdesc()

static TupleDesc pg_visibility_tupdesc ( bool  include_blkno,
bool  include_pd 
)
static

Definition at line 474 of file pg_visibility.c.

475{
476 TupleDesc tupdesc;
477 AttrNumber maxattr = 2;
478 AttrNumber a = 0;
479
480 if (include_blkno)
481 ++maxattr;
482 if (include_pd)
483 ++maxattr;
484 tupdesc = CreateTemplateTupleDesc(maxattr);
485 if (include_blkno)
486 TupleDescInitEntry(tupdesc, ++a, "blkno", INT8OID, -1, 0);
487 TupleDescInitEntry(tupdesc, ++a, "all_visible", BOOLOID, -1, 0);
488 TupleDescInitEntry(tupdesc, ++a, "all_frozen", BOOLOID, -1, 0);
489 if (include_pd)
490 TupleDescInitEntry(tupdesc, ++a, "pd_all_visible", BOOLOID, -1, 0);
491 Assert(a == maxattr);
492
493 return BlessTupleDesc(tupdesc);
494}
int16 AttrNumber
Definition: attnum.h:21
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2260
int a
Definition: isn.c:73
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:164
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:801

References a, Assert(), BlessTupleDesc(), CreateTemplateTupleDesc(), and TupleDescInitEntry().

Referenced by pg_visibility(), pg_visibility_map(), pg_visibility_map_rel(), and pg_visibility_rel().

◆ record_corrupt_item()

static void record_corrupt_item ( corrupt_items items,
ItemPointer  tid 
)
static

Definition at line 892 of file pg_visibility.c.

893{
894 /* enlarge output array if needed. */
895 if (items->next >= items->count)
896 {
897 items->count *= 2;
898 items->tids = repalloc(items->tids,
899 items->count * sizeof(ItemPointerData));
900 }
901 /* and add the new item */
902 items->tids[items->next++] = *tid;
903}
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1544

References items, and repalloc().

Referenced by collect_corrupt_items().

◆ tuple_all_visible()

static bool tuple_all_visible ( HeapTuple  tup,
TransactionId  OldestXmin,
Buffer  buffer 
)
static

Definition at line 910 of file pg_visibility.c.

911{
913 TransactionId xmin;
914
915 state = HeapTupleSatisfiesVacuum(tup, OldestXmin, buffer);
916 if (state != HEAPTUPLE_LIVE)
917 return false; /* all-visible implies live */
918
919 /*
920 * Neither lazy_scan_heap nor heap_page_is_all_visible will mark a page
921 * all-visible unless every tuple is hinted committed. However, those hint
922 * bits could be lost after a crash, so we can't be certain that they'll
923 * be set here. So just check the xmin.
924 */
925
926 xmin = HeapTupleHeaderGetXmin(tup->t_data);
927 if (!TransactionIdPrecedes(xmin, OldestXmin))
928 return false; /* xmin not old enough for all to see */
929
930 return true;
931}
HTSV_Result
Definition: heapam.h:133
@ HEAPTUPLE_LIVE
Definition: heapam.h:135
HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin, Buffer buffer)
static TransactionId HeapTupleHeaderGetXmin(const HeapTupleHeaderData *tup)
Definition: htup_details.h:324
Definition: regguts.h:323

References HEAPTUPLE_LIVE, HeapTupleHeaderGetXmin(), HeapTupleSatisfiesVacuum(), HeapTupleData::t_data, and TransactionIdPrecedes().

Referenced by collect_corrupt_items().