heapam.h 5.6 KB
Newer Older
1
/*-------------------------------------------------------------------------
2 3
 *
 * heapam.h--
4
 *	  POSTGRES heap access method definitions.
5 6 7 8
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
B
Bruce Momjian 已提交
9
 * $Id: heapam.h,v 1.25 1998/01/27 15:35:18 momjian Exp $
10 11 12
 *
 *-------------------------------------------------------------------------
 */
13
#ifndef HEAPAM_H
14 15
#define HEAPAM_H

16
#include <access/htup.h>
M
Marc G. Fournier 已提交
17
#include <access/relscan.h>
18 19
#include <storage/block.h>
#include <utils/rel.h>
20 21

/* ----------------------------------------------------------------
22
 *				heap access method statistics
23 24 25
 * ----------------------------------------------------------------
 */

26 27
typedef struct HeapAccessStatisticsData
{
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
	time_t		init_global_timestamp;	/* time global statistics started */
	time_t		local_reset_timestamp;	/* last time local reset was done */
	time_t		last_request_timestamp; /* last time stats were requested */

	int			global_open;
	int			global_openr;
	int			global_close;
	int			global_beginscan;
	int			global_rescan;
	int			global_endscan;
	int			global_getnext;
	int			global_fetch;
	int			global_insert;
	int			global_delete;
	int			global_replace;
	int			global_markpos;
	int			global_restrpos;
	int			global_BufferGetRelation;
	int			global_RelationIdGetRelation;
	int			global_RelationIdGetRelation_Buf;
	int			global_RelationNameGetRelation;
	int			global_getreldesc;
	int			global_heapgettup;
	int			global_RelationPutHeapTuple;
	int			global_RelationPutLongHeapTuple;

	int			local_open;
	int			local_openr;
	int			local_close;
	int			local_beginscan;
	int			local_rescan;
	int			local_endscan;
	int			local_getnext;
	int			local_fetch;
	int			local_insert;
	int			local_delete;
	int			local_replace;
	int			local_markpos;
	int			local_restrpos;
	int			local_BufferGetRelation;
	int			local_RelationIdGetRelation;
	int			local_RelationIdGetRelation_Buf;
	int			local_RelationNameGetRelation;
	int			local_getreldesc;
	int			local_heapgettup;
	int			local_RelationPutHeapTuple;
	int			local_RelationPutLongHeapTuple;
75
} HeapAccessStatisticsData;
76 77 78 79

typedef HeapAccessStatisticsData *HeapAccessStatistics;

#define IncrHeapAccessStat(x) \
80
	(heap_access_stats == NULL ? 0 : (heap_access_stats->x)++)
81

B
Bruce Momjian 已提交
82
/* ----------------
83
 *		heap_getattr
B
Bruce Momjian 已提交
84
 *
85 86 87
 *		Find a particular field in a row represented as a heap tuple.
 *		We return a pointer into that heap tuple, which points to the
 *		first byte of the value of the field in question.
B
Bruce Momjian 已提交
88
 *
89 90 91
 *		If the field in question has a NULL value, we return a null
 *		pointer and return <*isnull> == true.  Otherwise, we return
 *		<*isnull> == false.
B
Bruce Momjian 已提交
92
 *
93 94 95
 *		<tup> is the pointer to the heap tuple.  <attnum> is the attribute
 *		number of the column (field) caller wants.	<tupleDesc> is a
 *		pointer to the structure describing the row and all its fields.
96 97 98 99
 *
 *		Because this macro is often called with constants, it generates
 *		compiler warnings about 'left-hand comma expression has no effect.
 *
B
Bruce Momjian 已提交
100 101
 * ---------------- */
#define heap_getattr(tup, b, attnum, tupleDesc, isnull) \
102 103
	(AssertMacro((tup) != NULL) ? \
		((attnum) > (int) (tup)->t_natts) ? \
B
Bruce Momjian 已提交
104
			(((isnull) ? (*(isnull) = true) : dummyretNULL), (Datum)NULL) : \
105 106
		((attnum) > 0) ? \
			fastgetattr((tup), (attnum), (tupleDesc), (isnull)) : \
B
Bruce Momjian 已提交
107
		(((isnull) ? (*(isnull) = false) : dummyretNULL), heap_getsysattr((tup), (b), (attnum))) : \
108
	(Datum)NULL)
B
Bruce Momjian 已提交
109

110 111 112
extern HeapAccessStatistics heap_access_stats;	/* in stats.c */

/* ----------------
113
 *		function prototypes for heap access method
114 115 116 117 118
 * ----------------
 */
/* heap_create, heap_creatr, and heap_destroy are declared in catalog/heap.h */

/* heapam.c */
119
extern void doinsert(Relation relation, HeapTuple tup);
120 121 122

extern Relation heap_open(Oid relationId);
extern Relation heap_openr(char *relationName);
123
extern void heap_close(Relation relation);
124
extern HeapScanDesc heap_beginscan(Relation relation, int atend,
125
			   bool seeself, unsigned nkeys, ScanKey key);
126 127
extern void heap_rescan(HeapScanDesc sdesc, bool scanFromEnd, ScanKey key);
extern void heap_endscan(HeapScanDesc sdesc);
B
Bruce Momjian 已提交
128
extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw, Buffer *b);
129
extern HeapTuple heap_fetch(Relation relation, bool seeself, ItemPointer tid, Buffer *b);
130 131
extern Oid	heap_insert(Relation relation, HeapTuple tup);
extern int	heap_delete(Relation relation, ItemPointer tid);
132
extern int heap_replace(Relation relation, ItemPointer otid,
133
			 HeapTuple tup);
134 135
extern void heap_markpos(HeapScanDesc sdesc);
extern void heap_restrpos(HeapScanDesc sdesc);
136 137

/* in common/heaptuple.c */
138
extern Size ComputeDataSize(TupleDesc tupleDesc, Datum value[], char nulls[]);
139
extern void DataFill(char *data, TupleDesc tupleDesc,
V
Vadim B. Mikheev 已提交
140
		 Datum value[], char nulls[], uint16 *infomask,
141
		 bits8 *bit);
142 143 144
extern int	heap_attisnull(HeapTuple tup, int attnum);
extern int	heap_sysattrlen(AttrNumber attno);
extern bool heap_sysattrbyval(AttrNumber attno);
145 146 147
extern Datum heap_getsysattr(HeapTuple tup, Buffer b, int attnum);
extern Datum fastgetattr(HeapTuple tup, int attnum,
						 TupleDesc att, bool *isnull);
148
extern HeapTuple heap_copytuple(HeapTuple tuple);
149
extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
150
			   Datum value[], char nulls[]);
151
extern HeapTuple heap_modifytuple(HeapTuple tuple, Buffer buffer,
152
	 Relation relation, Datum replValue[], char replNull[], char repl[]);
153
HeapTuple	heap_addheader(uint32 natts, int structlen, char *structure);
154 155

/* in common/heap/stats.c */
156 157
extern void PrintHeapAccessStatistics(HeapAccessStatistics stats);
extern void initam(void);
158

159
/* hio.c */
160
extern void RelationPutHeapTuple(Relation relation, BlockNumber blockIndex,
161
					 HeapTuple tuple);
162
extern void RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple);
163

164
#endif							/* HEAPAM_H */