OSDN Git Service

Good Bye, Time Travel!
[pg-rex/syncrep.git] / src / include / access / heapam.h
1 /*-------------------------------------------------------------------------
2  *
3  * heapam.h--
4  *        POSTGRES heap access method definitions.
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: heapam.h,v 1.21 1997/11/02 15:26:37 vadim Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef HEAPAM_H
14 #define HEAPAM_H
15
16 #include <access/htup.h>
17 #include <access/relscan.h>
18 #include <storage/block.h>
19 #include <utils/rel.h>
20
21 /* ----------------------------------------------------------------
22  *                              heap access method statistics
23  * ----------------------------------------------------------------
24  */
25
26 typedef struct HeapAccessStatisticsData
27 {
28         time_t          init_global_timestamp;  /* time global statistics started */
29         time_t          local_reset_timestamp;  /* last time local reset was done */
30         time_t          last_request_timestamp; /* last time stats were requested */
31
32         int                     global_open;
33         int                     global_openr;
34         int                     global_close;
35         int                     global_beginscan;
36         int                     global_rescan;
37         int                     global_endscan;
38         int                     global_getnext;
39         int                     global_fetch;
40         int                     global_insert;
41         int                     global_delete;
42         int                     global_replace;
43         int                     global_markpos;
44         int                     global_restrpos;
45         int                     global_BufferGetRelation;
46         int                     global_RelationIdGetRelation;
47         int                     global_RelationIdGetRelation_Buf;
48         int                     global_RelationNameGetRelation;
49         int                     global_getreldesc;
50         int                     global_heapgettup;
51         int                     global_RelationPutHeapTuple;
52         int                     global_RelationPutLongHeapTuple;
53
54         int                     local_open;
55         int                     local_openr;
56         int                     local_close;
57         int                     local_beginscan;
58         int                     local_rescan;
59         int                     local_endscan;
60         int                     local_getnext;
61         int                     local_fetch;
62         int                     local_insert;
63         int                     local_delete;
64         int                     local_replace;
65         int                     local_markpos;
66         int                     local_restrpos;
67         int                     local_BufferGetRelation;
68         int                     local_RelationIdGetRelation;
69         int                     local_RelationIdGetRelation_Buf;
70         int                     local_RelationNameGetRelation;
71         int                     local_getreldesc;
72         int                     local_heapgettup;
73         int                     local_RelationPutHeapTuple;
74         int                     local_RelationPutLongHeapTuple;
75 } HeapAccessStatisticsData;
76
77 typedef HeapAccessStatisticsData *HeapAccessStatistics;
78
79 #define IncrHeapAccessStat(x) \
80         (heap_access_stats == NULL ? 0 : (heap_access_stats->x)++)
81
82 /* ----------------
83  *              heap_getattr
84  *
85  *              Find a particular field in a row represented as a heap tuple.
86  *              We return a pointer into that heap tuple, which points to the
87  *              first byte of the value of the field in question.
88  *
89  *              If the field in question has a NULL value, we return a null
90  *              pointer and return <*isnull> == true.  Otherwise, we return
91  *              <*isnull> == false.
92  *
93  *              <tup> is the pointer to the heap tuple.  <attnum> is the attribute
94  *              number of the column (field) caller wants.      <tupleDesc> is a
95  *              pointer to the structure describing the row and all its fields.
96  *
97  *              Because this macro is often called with constants, it generates
98  *              compiler warnings about 'left-hand comma expression has no effect.
99  *
100  * ---------------- */
101 #define heap_getattr(tup, b, attnum, tupleDesc, isnull) \
102         (AssertMacro((tup) != NULL) ? \
103                 ((attnum) > (int) (tup)->t_natts) ? \
104                         (((isnull) ? (*(isnull) = true) : (void)NULL), (Datum)NULL) : \
105                 ((attnum) > 0) ? \
106                         fastgetattr((tup), (attnum), (tupleDesc), (isnull)) : \
107                 (((isnull) ? (*(isnull) = false) : (void)NULL), heap_getsysattr((tup), (b), (attnum))) : \
108         (Datum)NULL)
109
110 extern HeapAccessStatistics heap_access_stats;  /* in stats.c */
111
112 /* ----------------
113  *              function prototypes for heap access method
114  * ----------------
115  */
116 /* heap_create, heap_creatr, and heap_destroy are declared in catalog/heap.h */
117
118 /* heapam.c */
119 extern void doinsert(Relation relation, HeapTuple tup);
120
121 extern Relation heap_open(Oid relationId);
122 extern Relation heap_openr(char *relationName);
123 extern void heap_close(Relation relation);
124 extern HeapScanDesc
125 heap_beginscan(Relation relation, int atend,
126                            TimeQual timeQual, unsigned nkeys, ScanKey key);
127 extern void heap_rescan(HeapScanDesc sdesc, bool scanFromEnd, ScanKey key);
128 extern void heap_endscan(HeapScanDesc sdesc);
129 extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw, Buffer *b);
130 extern HeapTuple
131 heap_fetch(Relation relation, TimeQual timeQual,
132                    ItemPointer tid, Buffer *b);
133 extern Oid      heap_insert(Relation relation, HeapTuple tup);
134 extern int      heap_delete(Relation relation, ItemPointer tid);
135 extern int
136 heap_replace(Relation relation, ItemPointer otid,
137                          HeapTuple tup);
138 extern void heap_markpos(HeapScanDesc sdesc);
139 extern void heap_restrpos(HeapScanDesc sdesc);
140
141 /* in common/heaptuple.c */
142 extern Size ComputeDataSize(TupleDesc tupleDesc, Datum value[], char nulls[]);
143 extern void
144 DataFill(char *data, TupleDesc tupleDesc,
145                  Datum value[], char nulls[], uint16 *infomask,
146                  bits8 *bit);
147 extern int      heap_attisnull(HeapTuple tup, int attnum);
148 extern int      heap_sysattrlen(AttrNumber attno);
149 extern bool heap_sysattrbyval(AttrNumber attno);
150 extern Datum heap_getsysattr(HeapTuple tup, Buffer b, int attnum);
151 extern Datum fastgetattr(HeapTuple tup, int attnum,
152                                                  TupleDesc att, bool *isnull);
153 extern HeapTuple heap_copytuple(HeapTuple tuple);
154 extern HeapTuple
155 heap_formtuple(TupleDesc tupleDescriptor,
156                            Datum value[], char nulls[]);
157 extern HeapTuple
158 heap_modifytuple(HeapTuple tuple, Buffer buffer,
159          Relation relation, Datum replValue[], char replNull[], char repl[]);
160 HeapTuple       heap_addheader(uint32 natts, int structlen, char *structure);
161
162 /* in common/heap/stats.c */
163 extern void PrintHeapAccessStatistics(HeapAccessStatistics stats);
164 extern void initam(void);
165
166 /* hio.c */
167 extern void
168 RelationPutHeapTuple(Relation relation, BlockNumber blockIndex,
169                                          HeapTuple tuple);
170 extern void RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple);
171
172 #endif                                                  /* HEAPAM_H */