Eneboo - Documentación para desarrolladores
src/libpq/include/utils/tqual.h
Ir a la documentación de este archivo.
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-2005, PostgreSQL Global Development Group
00009  * Portions Copyright (c) 1994, Regents of the University of California
00010  *
00011  * $PostgreSQL: pgsql/src/include/utils/tqual.h,v 1.59 2005/10/15 02:49:46 momjian Exp $
00012  *
00013  *-------------------------------------------------------------------------
00014  */
00015 #ifndef TQUAL_H
00016 #define TQUAL_H
00017 
00018 #include "access/htup.h"
00019 #include "access/xact.h"
00020 #include "storage/buf.h"
00021 
00022 
00023 /*
00024  * "Regular" snapshots are pointers to a SnapshotData structure.
00025  *
00026  * We also have some "special" snapshot values that have fixed meanings
00027  * and don't need any backing SnapshotData.  These are encoded by small
00028  * integer values, which of course is a gross violation of ANSI C, but
00029  * it works fine on all known platforms.
00030  *
00031  * SnapshotDirty is an even more special case: its semantics are fixed,
00032  * but there is a backing SnapshotData struct for it.  That struct is
00033  * actually used as *output* data from tqual.c, not input into it.
00034  * (But hey, SnapshotDirty ought to have a dirty implementation, no? ;-))
00035  */
00036 
00037 typedef struct SnapshotData
00038 {
00039         TransactionId xmin;                     /* XID < xmin are visible to me */
00040         TransactionId xmax;                     /* XID >= xmax are invisible to me */
00041         uint32          xcnt;                   /* # of xact ids in xip[] */
00042         TransactionId *xip;                     /* array of xact IDs in progress */
00043         /* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */
00044         CommandId       curcid;                 /* in my xact, CID < curcid are visible */
00045 } SnapshotData;
00046 
00047 typedef SnapshotData *Snapshot;
00048 
00049 /* Special snapshot values: */
00050 #define InvalidSnapshot                         ((Snapshot) 0x0)        /* same as NULL */
00051 #define SnapshotNow                                     ((Snapshot) 0x1)
00052 #define SnapshotSelf                            ((Snapshot) 0x2)
00053 #define SnapshotAny                                     ((Snapshot) 0x3)
00054 #define SnapshotToast                           ((Snapshot) 0x4)
00055 
00056 extern DLLIMPORT Snapshot SnapshotDirty;
00057 
00058 extern DLLIMPORT Snapshot SerializableSnapshot;
00059 extern DLLIMPORT Snapshot LatestSnapshot;
00060 extern DLLIMPORT Snapshot ActiveSnapshot;
00061 
00062 extern TransactionId TransactionXmin;
00063 extern TransactionId RecentXmin;
00064 extern TransactionId RecentGlobalXmin;
00065 
00066 
00067 /*
00068  * HeapTupleSatisfiesVisibility
00069  *              True iff heap tuple satisfies a time qual.
00070  *
00071  * Notes:
00072  *              Assumes heap tuple is valid.
00073  *              Beware of multiple evaluations of snapshot argument.
00074  */
00075 #define HeapTupleSatisfiesVisibility(tuple, snapshot, buffer) \
00076 ((snapshot) == SnapshotNow ? \
00077         HeapTupleSatisfiesNow((tuple)->t_data, buffer) \
00078 : \
00079         ((snapshot) == SnapshotSelf ? \
00080                 HeapTupleSatisfiesItself((tuple)->t_data, buffer) \
00081         : \
00082                 ((snapshot) == SnapshotAny ? \
00083                         true \
00084                 : \
00085                         ((snapshot) == SnapshotToast ? \
00086                                 HeapTupleSatisfiesToast((tuple)->t_data, buffer) \
00087                         : \
00088                                 ((snapshot) == SnapshotDirty ? \
00089                                         HeapTupleSatisfiesDirty((tuple)->t_data, buffer) \
00090                                 : \
00091                                         HeapTupleSatisfiesSnapshot((tuple)->t_data, snapshot, buffer) \
00092                                 ) \
00093                         ) \
00094                 ) \
00095         ) \
00096 )
00097 
00098 /* Result codes for HeapTupleSatisfiesUpdate */
00099 typedef enum
00100 {
00101         HeapTupleMayBeUpdated,
00102         HeapTupleInvisible,
00103         HeapTupleSelfUpdated,
00104         HeapTupleUpdated,
00105         HeapTupleBeingUpdated
00106 } HTSU_Result;
00107 
00108 /* Result codes for HeapTupleSatisfiesVacuum */
00109 typedef enum
00110 {
00111         HEAPTUPLE_DEAD,                         /* tuple is dead and deletable */
00112         HEAPTUPLE_LIVE,                         /* tuple is live (committed, no deleter) */
00113         HEAPTUPLE_RECENTLY_DEAD,        /* tuple is dead, but not deletable yet */
00114         HEAPTUPLE_INSERT_IN_PROGRESS,           /* inserting xact is still in progress */
00115         HEAPTUPLE_DELETE_IN_PROGRESS    /* deleting xact is still in progress */
00116 } HTSV_Result;
00117 
00118 extern bool HeapTupleSatisfiesItself(HeapTupleHeader tuple, Buffer buffer);
00119 extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple, Buffer buffer);
00120 extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple, Buffer buffer);
00121 extern bool HeapTupleSatisfiesToast(HeapTupleHeader tuple, Buffer buffer);
00122 extern bool HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple,
00123                                                    Snapshot snapshot, Buffer buffer);
00124 extern HTSU_Result HeapTupleSatisfiesUpdate(HeapTupleHeader tuple,
00125                                                  CommandId curcid, Buffer buffer);
00126 extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTupleHeader tuple,
00127                                                  TransactionId OldestXmin, Buffer buffer);
00128 
00129 extern Snapshot GetTransactionSnapshot(void);
00130 extern Snapshot GetLatestSnapshot(void);
00131 extern Snapshot CopySnapshot(Snapshot snapshot);
00132 extern void FreeSnapshot(Snapshot snapshot);
00133 extern void FreeXactSnapshot(void);
00134 
00135 /* in procarray.c; declared here to avoid including tqual.h in procarray.h: */
00136 extern Snapshot GetSnapshotData(Snapshot snapshot, bool serializable);
00137 
00138 #endif   /* TQUAL_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'