00001 /*------------------------------------------------------------------------- 00002 * 00003 * snapshot.h 00004 * POSTGRES snapshot definition 00005 * 00006 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00007 * Portions Copyright (c) 1994, Regents of the University of California 00008 * 00009 * src/include/utils/snapshot.h 00010 * 00011 *------------------------------------------------------------------------- 00012 */ 00013 #ifndef SNAPSHOT_H 00014 #define SNAPSHOT_H 00015 00016 #include "access/htup.h" 00017 #include "storage/buf.h" 00018 00019 00020 typedef struct SnapshotData *Snapshot; 00021 00022 #define InvalidSnapshot ((Snapshot) NULL) 00023 00024 /* 00025 * We use SnapshotData structures to represent both "regular" (MVCC) 00026 * snapshots and "special" snapshots that have non-MVCC semantics. 00027 * The specific semantics of a snapshot are encoded by the "satisfies" 00028 * function. 00029 */ 00030 typedef bool (*SnapshotSatisfiesFunc) (HeapTupleHeader tuple, 00031 Snapshot snapshot, Buffer buffer); 00032 00033 typedef struct SnapshotData 00034 { 00035 SnapshotSatisfiesFunc satisfies; /* tuple test function */ 00036 00037 /* 00038 * The remaining fields are used only for MVCC snapshots, and are normally 00039 * just zeroes in special snapshots. (But xmin and xmax are used 00040 * specially by HeapTupleSatisfiesDirty.) 00041 * 00042 * An MVCC snapshot can never see the effects of XIDs >= xmax. It can see 00043 * the effects of all older XIDs except those listed in the snapshot. xmin 00044 * is stored as an optimization to avoid needing to search the XID arrays 00045 * for most tuples. 00046 */ 00047 TransactionId xmin; /* all XID < xmin are visible to me */ 00048 TransactionId xmax; /* all XID >= xmax are invisible to me */ 00049 TransactionId *xip; /* array of xact IDs in progress */ 00050 uint32 xcnt; /* # of xact ids in xip[] */ 00051 /* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */ 00052 int32 subxcnt; /* # of xact ids in subxip[] */ 00053 TransactionId *subxip; /* array of subxact IDs in progress */ 00054 bool suboverflowed; /* has the subxip array overflowed? */ 00055 bool takenDuringRecovery; /* recovery-shaped snapshot? */ 00056 bool copied; /* false if it's a static snapshot */ 00057 00058 /* 00059 * note: all ids in subxip[] are >= xmin, but we don't bother filtering 00060 * out any that are >= xmax 00061 */ 00062 CommandId curcid; /* in my xact, CID < curcid are visible */ 00063 uint32 active_count; /* refcount on ActiveSnapshot stack */ 00064 uint32 regd_count; /* refcount on RegisteredSnapshotList */ 00065 } SnapshotData; 00066 00067 /* 00068 * Result codes for HeapTupleSatisfiesUpdate. This should really be in 00069 * tqual.h, but we want to avoid including that file elsewhere. 00070 */ 00071 typedef enum 00072 { 00073 HeapTupleMayBeUpdated, 00074 HeapTupleInvisible, 00075 HeapTupleSelfUpdated, 00076 HeapTupleUpdated, 00077 HeapTupleBeingUpdated 00078 } HTSU_Result; 00079 00080 #endif /* SNAPSHOT_H */