Header And Logo

PostgreSQL
| The world's most advanced open source database.

tqual.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * tqual.h
00004  *    POSTGRES "time qualification" definitions, ie, tuple visibility rules.
00005  *
00006  *    Should be moved/renamed...    - vadim 07/28/98
00007  *
00008  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00009  * Portions Copyright (c) 1994, Regents of the University of California
00010  *
00011  * src/include/utils/tqual.h
00012  *
00013  *-------------------------------------------------------------------------
00014  */
00015 #ifndef TQUAL_H
00016 #define TQUAL_H
00017 
00018 #include "utils/snapshot.h"
00019 
00020 
00021 /* Static variables representing various special snapshot semantics */
00022 extern PGDLLIMPORT SnapshotData SnapshotNowData;
00023 extern PGDLLIMPORT SnapshotData SnapshotSelfData;
00024 extern PGDLLIMPORT SnapshotData SnapshotAnyData;
00025 extern PGDLLIMPORT SnapshotData SnapshotToastData;
00026 
00027 #define SnapshotNow         (&SnapshotNowData)
00028 #define SnapshotSelf        (&SnapshotSelfData)
00029 #define SnapshotAny         (&SnapshotAnyData)
00030 #define SnapshotToast       (&SnapshotToastData)
00031 
00032 /*
00033  * We don't provide a static SnapshotDirty variable because it would be
00034  * non-reentrant.  Instead, users of that snapshot type should declare a
00035  * local variable of type SnapshotData, and initialize it with this macro.
00036  */
00037 #define InitDirtySnapshot(snapshotdata)  \
00038     ((snapshotdata).satisfies = HeapTupleSatisfiesDirty)
00039 
00040 /* This macro encodes the knowledge of which snapshots are MVCC-safe */
00041 #define IsMVCCSnapshot(snapshot)  \
00042     ((snapshot)->satisfies == HeapTupleSatisfiesMVCC)
00043 
00044 /*
00045  * HeapTupleSatisfiesVisibility
00046  *      True iff heap tuple satisfies a time qual.
00047  *
00048  * Notes:
00049  *  Assumes heap tuple is valid.
00050  *  Beware of multiple evaluations of snapshot argument.
00051  *  Hint bits in the HeapTuple's t_infomask may be updated as a side effect;
00052  *  if so, the indicated buffer is marked dirty.
00053  */
00054 #define HeapTupleSatisfiesVisibility(tuple, snapshot, buffer) \
00055     ((*(snapshot)->satisfies) ((tuple)->t_data, snapshot, buffer))
00056 
00057 /* Result codes for HeapTupleSatisfiesVacuum */
00058 typedef enum
00059 {
00060     HEAPTUPLE_DEAD,             /* tuple is dead and deletable */
00061     HEAPTUPLE_LIVE,             /* tuple is live (committed, no deleter) */
00062     HEAPTUPLE_RECENTLY_DEAD,    /* tuple is dead, but not deletable yet */
00063     HEAPTUPLE_INSERT_IN_PROGRESS,       /* inserting xact is still in progress */
00064     HEAPTUPLE_DELETE_IN_PROGRESS    /* deleting xact is still in progress */
00065 } HTSV_Result;
00066 
00067 /* These are the "satisfies" test routines for the various snapshot types */
00068 extern bool HeapTupleSatisfiesMVCC(HeapTupleHeader tuple,
00069                        Snapshot snapshot, Buffer buffer);
00070 extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple,
00071                       Snapshot snapshot, Buffer buffer);
00072 extern bool HeapTupleSatisfiesSelf(HeapTupleHeader tuple,
00073                        Snapshot snapshot, Buffer buffer);
00074 extern bool HeapTupleSatisfiesAny(HeapTupleHeader tuple,
00075                       Snapshot snapshot, Buffer buffer);
00076 extern bool HeapTupleSatisfiesToast(HeapTupleHeader tuple,
00077                         Snapshot snapshot, Buffer buffer);
00078 extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple,
00079                         Snapshot snapshot, Buffer buffer);
00080 
00081 /* Special "satisfies" routines with different APIs */
00082 extern HTSU_Result HeapTupleSatisfiesUpdate(HeapTupleHeader tuple,
00083                          CommandId curcid, Buffer buffer);
00084 extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTupleHeader tuple,
00085                          TransactionId OldestXmin, Buffer buffer);
00086 extern bool HeapTupleIsSurelyDead(HeapTupleHeader tuple,
00087                       TransactionId OldestXmin);
00088 
00089 extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
00090                      uint16 infomask, TransactionId xid);
00091 extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);
00092 
00093 #endif   /* TQUAL_H */