]> granicus.if.org Git - postgresql/blob - src/include/utils/snapshot.h
Add 'ignore_nulls' option to row_to_json
[postgresql] / src / include / utils / snapshot.h
1 /*-------------------------------------------------------------------------
2  *
3  * snapshot.h
4  *        POSTGRES snapshot definition
5  *
6  * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/utils/snapshot.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef SNAPSHOT_H
14 #define SNAPSHOT_H
15
16 #include "access/htup.h"
17 #include "storage/buf.h"
18
19
20 typedef struct SnapshotData *Snapshot;
21
22 #define InvalidSnapshot         ((Snapshot) NULL)
23
24 /*
25  * We use SnapshotData structures to represent both "regular" (MVCC)
26  * snapshots and "special" snapshots that have non-MVCC semantics.
27  * The specific semantics of a snapshot are encoded by the "satisfies"
28  * function.
29  */
30 typedef bool (*SnapshotSatisfiesFunc) (HeapTuple htup,
31                                                                                    Snapshot snapshot, Buffer buffer);
32
33 /*
34  * Struct representing all kind of possible snapshots.
35  *
36  * There are several different kinds of snapshots:
37  * * Normal MVCC snapshots
38  * * MVCC snapshots taken during recovery (in Hot-Standby mode)
39  * * Historic MVCC snapshots used during logical decoding
40  * * snapshots passed to HeapTupleSatisfiesDirty()
41  * * snapshots used for SatisfiesAny, Toast, Self where no members are
42  *       accessed.
43  *
44  * TODO: It's probably a good idea to split this struct using a NodeTag
45  * similar to how parser and executor nodes are handled, with one type for
46  * each different kind of snapshot to avoid overloading the meaning of
47  * individual fields.
48  */
49 typedef struct SnapshotData
50 {
51         SnapshotSatisfiesFunc satisfies;        /* tuple test function */
52
53         /*
54          * The remaining fields are used only for MVCC snapshots, and are normally
55          * just zeroes in special snapshots.  (But xmin and xmax are used
56          * specially by HeapTupleSatisfiesDirty.)
57          *
58          * An MVCC snapshot can never see the effects of XIDs >= xmax. It can see
59          * the effects of all older XIDs except those listed in the snapshot. xmin
60          * is stored as an optimization to avoid needing to search the XID arrays
61          * for most tuples.
62          */
63         TransactionId xmin;                     /* all XID < xmin are visible to me */
64         TransactionId xmax;                     /* all XID >= xmax are invisible to me */
65
66         /*
67          * For normal MVCC snapshot this contains the all xact IDs that are in
68          * progress, unless the snapshot was taken during recovery in which case
69          * it's empty. For historic MVCC snapshots, the meaning is inverted, i.e.
70          * it contains *committed* transactions between xmin and xmax.
71          */
72         TransactionId *xip;
73         uint32          xcnt;                   /* # of xact ids in xip[] */
74         /* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */
75         int32           subxcnt;                /* # of xact ids in subxip[] */
76
77         /*
78          * For non-historic MVCC snapshots, this contains subxact IDs that are in
79          * progress (and other transactions that are in progress if taken during
80          * recovery). For historic snapshot it contains *all* xids assigned to the
81          * replayed transaction, including the toplevel xid.
82          */
83         TransactionId *subxip;
84         bool            suboverflowed;  /* has the subxip array overflowed? */
85         bool            takenDuringRecovery;    /* recovery-shaped snapshot? */
86         bool            copied;                 /* false if it's a static snapshot */
87
88         /*
89          * note: all ids in subxip[] are >= xmin, but we don't bother filtering
90          * out any that are >= xmax
91          */
92         CommandId       curcid;                 /* in my xact, CID < curcid are visible */
93         uint32          active_count;   /* refcount on ActiveSnapshot stack */
94         uint32          regd_count;             /* refcount on RegisteredSnapshotList */
95 } SnapshotData;
96
97 /*
98  * Result codes for HeapTupleSatisfiesUpdate.  This should really be in
99  * tqual.h, but we want to avoid including that file elsewhere.
100  */
101 typedef enum
102 {
103         HeapTupleMayBeUpdated,
104         HeapTupleInvisible,
105         HeapTupleSelfUpdated,
106         HeapTupleUpdated,
107         HeapTupleBeingUpdated
108 } HTSU_Result;
109
110 #endif   /* SNAPSHOT_H */