1
/*-------------------------------------------------------------------------
4
* POSTGRES generalized index access method definitions.
7
* Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
8
* Portions Copyright (c) 1994, Regents of the University of California
10
* src/include/access/genam.h
12
*-------------------------------------------------------------------------
17
#include "access/sdir.h"
18
#include "access/skey.h"
19
#include "nodes/tidbitmap.h"
20
#include "storage/lock.h"
21
#include "utils/relcache.h"
22
#include "utils/snapshot.h"
25
* Struct for statistics returned by ambuild
27
typedef struct IndexBuildResult
29
double heap_tuples; /* # of tuples seen in parent table */
30
double index_tuples; /* # of tuples inserted into index */
34
* Struct for input arguments passed to ambulkdelete and amvacuumcleanup
36
* num_heap_tuples is accurate only when estimated_count is false;
37
* otherwise it's just an estimate (currently, the estimate is the
38
* prior value of the relation's pg_class.reltuples field). It will
39
* always just be an estimate during ambulkdelete.
41
typedef struct IndexVacuumInfo
43
Relation index; /* the index being vacuumed */
44
bool analyze_only; /* ANALYZE (without any actual vacuum) */
45
bool estimated_count; /* num_heap_tuples is an estimate */
46
int message_level; /* ereport level for progress messages */
47
double num_heap_tuples; /* tuples remaining in heap */
48
BufferAccessStrategy strategy; /* access strategy for reads */
52
* Struct for statistics returned by ambulkdelete and amvacuumcleanup
54
* This struct is normally allocated by the first ambulkdelete call and then
55
* passed along through subsequent ones until amvacuumcleanup; however,
56
* amvacuumcleanup must be prepared to allocate it in the case where no
57
* ambulkdelete calls were made (because no tuples needed deletion).
58
* Note that an index AM could choose to return a larger struct
59
* of which this is just the first field; this provides a way for ambulkdelete
60
* to communicate additional private data to amvacuumcleanup.
62
* Note: pages_removed is the amount by which the index physically shrank,
63
* if any (ie the change in its total size on disk). pages_deleted and
64
* pages_free refer to free space within the index file. Some index AMs
65
* may compute num_index_tuples by reference to num_heap_tuples, in which
66
* case they should copy the estimated_count field from IndexVacuumInfo.
68
typedef struct IndexBulkDeleteResult
70
BlockNumber num_pages; /* pages remaining in index */
71
BlockNumber pages_removed; /* # removed during vacuum operation */
72
bool estimated_count; /* num_index_tuples is an estimate */
73
double num_index_tuples; /* tuples remaining */
74
double tuples_removed; /* # removed during vacuum operation */
75
BlockNumber pages_deleted; /* # unused pages in index */
76
BlockNumber pages_free; /* # pages available for reuse */
77
} IndexBulkDeleteResult;
79
/* Typedef for callback function to determine if a tuple is bulk-deletable */
80
typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
82
/* struct definitions appear in relscan.h */
83
typedef struct IndexScanDescData *IndexScanDesc;
84
typedef struct SysScanDescData *SysScanDesc;
87
* Enumeration specifying the type of uniqueness check to perform in
90
* UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
91
* blocking to see if a conflicting transaction commits.
93
* For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
94
* insertion time. The index AM should test if the tuple is unique, but
95
* should not throw error, block, or prevent the insertion if the tuple
96
* appears not to be unique. We'll recheck later when it is time for the
97
* constraint to be enforced. The AM must return true if the tuple is
98
* known unique, false if it is possibly non-unique. In the "true" case
99
* it is safe to omit the later recheck.
101
* When it is time to recheck the deferred constraint, a pseudo-insertion
102
* call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
103
* index in this case, so it should not be inserted again. Rather, just
104
* check for conflicting live tuples (possibly blocking).
106
typedef enum IndexUniqueCheck
108
UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
109
UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
110
UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
111
UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
116
* generalized index_ interface routines (in indexam.c)
121
* True iff the index scan is valid.
123
#define IndexScanIsValid(scan) PointerIsValid(scan)
125
extern Relation index_open(Oid relationId, LOCKMODE lockmode);
126
extern void index_close(Relation relation, LOCKMODE lockmode);
128
extern bool index_insert(Relation indexRelation,
129
Datum *values, bool *isnull,
130
ItemPointer heap_t_ctid,
131
Relation heapRelation,
132
IndexUniqueCheck checkUnique);
134
extern IndexScanDesc index_beginscan(Relation heapRelation,
135
Relation indexRelation,
137
int nkeys, int norderbys);
138
extern IndexScanDesc index_beginscan_bitmap(Relation indexRelation,
141
extern void index_rescan(IndexScanDesc scan,
142
ScanKey keys, int nkeys,
143
ScanKey orderbys, int norderbys);
144
extern void index_endscan(IndexScanDesc scan);
145
extern void index_markpos(IndexScanDesc scan);
146
extern void index_restrpos(IndexScanDesc scan);
147
extern ItemPointer index_getnext_tid(IndexScanDesc scan,
148
ScanDirection direction);
149
extern HeapTuple index_fetch_heap(IndexScanDesc scan);
150
extern HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction);
151
extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
153
extern IndexBulkDeleteResult *index_bulk_delete(IndexVacuumInfo *info,
154
IndexBulkDeleteResult *stats,
155
IndexBulkDeleteCallback callback,
156
void *callback_state);
157
extern IndexBulkDeleteResult *index_vacuum_cleanup(IndexVacuumInfo *info,
158
IndexBulkDeleteResult *stats);
159
extern bool index_can_return(Relation indexRelation);
160
extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum,
162
extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
166
* index access method support routines (in genam.c)
168
extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
169
int nkeys, int norderbys);
170
extern void IndexScanEnd(IndexScanDesc scan);
171
extern char *BuildIndexValueDescription(Relation indexRelation,
172
Datum *values, bool *isnull);
175
* heap-or-index access to system catalogs (in genam.c)
177
extern SysScanDesc systable_beginscan(Relation heapRelation,
181
int nkeys, ScanKey key);
182
extern HeapTuple systable_getnext(SysScanDesc sysscan);
183
extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup);
184
extern void systable_endscan(SysScanDesc sysscan);
185
extern SysScanDesc systable_beginscan_ordered(Relation heapRelation,
186
Relation indexRelation,
188
int nkeys, ScanKey key);
189
extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan,
190
ScanDirection direction);
191
extern void systable_endscan_ordered(SysScanDesc sysscan);