PostgreSQL Source Code  git master
genam.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * genam.h
4  * POSTGRES generalized index access method definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/access/genam.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef GENAM_H
15 #define GENAM_H
16 
17 #include "access/sdir.h"
18 #include "access/skey.h"
19 #include "nodes/tidbitmap.h"
20 #include "storage/lockdefs.h"
21 #include "utils/relcache.h"
22 #include "utils/snapshot.h"
23 
24 /* We don't want this file to depend on execnodes.h. */
25 struct IndexInfo;
26 
27 /*
28  * Struct for statistics returned by ambuild
29  */
30 typedef struct IndexBuildResult
31 {
32  double heap_tuples; /* # of tuples seen in parent table */
33  double index_tuples; /* # of tuples inserted into index */
35 
36 /*
37  * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
38  *
39  * num_heap_tuples is accurate only when estimated_count is false;
40  * otherwise it's just an estimate (currently, the estimate is the
41  * prior value of the relation's pg_class.reltuples field, so it could
42  * even be -1). It will always just be an estimate during ambulkdelete.
43  */
44 typedef struct IndexVacuumInfo
45 {
46  Relation index; /* the index being vacuumed */
47  bool analyze_only; /* ANALYZE (without any actual vacuum) */
48  bool report_progress; /* emit progress.h status reports */
49  bool estimated_count; /* num_heap_tuples is an estimate */
50  int message_level; /* ereport level for progress messages */
51  double num_heap_tuples; /* tuples remaining in heap */
52  BufferAccessStrategy strategy; /* access strategy for reads */
54 
55 /*
56  * Struct for statistics returned by ambulkdelete and amvacuumcleanup
57  *
58  * This struct is normally allocated by the first ambulkdelete call and then
59  * passed along through subsequent ones until amvacuumcleanup; however,
60  * amvacuumcleanup must be prepared to allocate it in the case where no
61  * ambulkdelete calls were made (because no tuples needed deletion).
62  * Note that an index AM could choose to return a larger struct
63  * of which this is just the first field; this provides a way for ambulkdelete
64  * to communicate additional private data to amvacuumcleanup.
65  *
66  * Note: pages_newly_deleted is the number of pages in the index that were
67  * deleted by the current vacuum operation. pages_deleted and pages_free
68  * refer to free space within the index file.
69  *
70  * Note: Some index AMs may compute num_index_tuples by reference to
71  * num_heap_tuples, in which case they should copy the estimated_count field
72  * from IndexVacuumInfo.
73  */
74 typedef struct IndexBulkDeleteResult
75 {
76  BlockNumber num_pages; /* pages remaining in index */
77  bool estimated_count; /* num_index_tuples is an estimate */
78  double num_index_tuples; /* tuples remaining */
79  double tuples_removed; /* # removed during vacuum operation */
80  BlockNumber pages_newly_deleted; /* # pages marked deleted by us */
81  BlockNumber pages_deleted; /* # pages marked deleted (could be by us) */
82  BlockNumber pages_free; /* # pages available for reuse */
84 
85 /* Typedef for callback function to determine if a tuple is bulk-deletable */
86 typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
87 
88 /* struct definitions appear in relscan.h */
90 typedef struct SysScanDescData *SysScanDesc;
91 
93 
94 /*
95  * Enumeration specifying the type of uniqueness check to perform in
96  * index_insert().
97  *
98  * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
99  * blocking to see if a conflicting transaction commits.
100  *
101  * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
102  * insertion time. The index AM should test if the tuple is unique, but
103  * should not throw error, block, or prevent the insertion if the tuple
104  * appears not to be unique. We'll recheck later when it is time for the
105  * constraint to be enforced. The AM must return true if the tuple is
106  * known unique, false if it is possibly non-unique. In the "true" case
107  * it is safe to omit the later recheck.
108  *
109  * When it is time to recheck the deferred constraint, a pseudo-insertion
110  * call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
111  * index in this case, so it should not be inserted again. Rather, just
112  * check for conflicting live tuples (possibly blocking).
113  */
114 typedef enum IndexUniqueCheck
115 {
116  UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
117  UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
118  UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
119  UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
121 
122 
123 /* Nullable "ORDER BY col op const" distance */
124 typedef struct IndexOrderByDistance
125 {
126  double value;
127  bool isnull;
129 
130 /*
131  * generalized index_ interface routines (in indexam.c)
132  */
133 
134 /*
135  * IndexScanIsValid
136  * True iff the index scan is valid.
137  */
138 #define IndexScanIsValid(scan) PointerIsValid(scan)
139 
140 extern Relation index_open(Oid relationId, LOCKMODE lockmode);
141 extern void index_close(Relation relation, LOCKMODE lockmode);
142 
143 extern bool index_insert(Relation indexRelation,
144  Datum *values, bool *isnull,
145  ItemPointer heap_t_ctid,
146  Relation heapRelation,
147  IndexUniqueCheck checkUnique,
148  bool indexUnchanged,
149  struct IndexInfo *indexInfo);
150 
151 extern IndexScanDesc index_beginscan(Relation heapRelation,
152  Relation indexRelation,
153  Snapshot snapshot,
154  int nkeys, int norderbys);
155 extern IndexScanDesc index_beginscan_bitmap(Relation indexRelation,
156  Snapshot snapshot,
157  int nkeys);
158 extern void index_rescan(IndexScanDesc scan,
159  ScanKey keys, int nkeys,
160  ScanKey orderbys, int norderbys);
161 extern void index_endscan(IndexScanDesc scan);
162 extern void index_markpos(IndexScanDesc scan);
163 extern void index_restrpos(IndexScanDesc scan);
164 extern Size index_parallelscan_estimate(Relation indexrel, Snapshot snapshot);
165 extern void index_parallelscan_initialize(Relation heaprel, Relation indexrel,
166  Snapshot snapshot, ParallelIndexScanDesc target);
167 extern void index_parallelrescan(IndexScanDesc scan);
169  Relation indexrel, int nkeys, int norderbys,
170  ParallelIndexScanDesc pscan);
172  ScanDirection direction);
173 struct TupleTableSlot;
174 extern bool index_fetch_heap(IndexScanDesc scan, struct TupleTableSlot *slot);
175 extern bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction,
176  struct TupleTableSlot *slot);
177 extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
178 
180  IndexBulkDeleteResult *istat,
182  void *callback_state);
184  IndexBulkDeleteResult *istat);
185 extern bool index_can_return(Relation indexRelation, int attno);
187  uint16 procnum);
189  uint16 procnum);
191  Oid *orderByTypes,
192  IndexOrderByDistance *distances,
193  bool recheckOrderBy);
195  Datum attoptions, bool validate);
196 
197 
198 /*
199  * index access method support routines (in genam.c)
200  */
201 extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
202  int nkeys, int norderbys);
203 extern void IndexScanEnd(IndexScanDesc scan);
204 extern char *BuildIndexValueDescription(Relation indexRelation,
205  Datum *values, bool *isnull);
207  Relation hrel,
208  Buffer ibuf,
209  OffsetNumber *itemnos,
210  int nitems);
211 
212 /*
213  * heap-or-index access to system catalogs (in genam.c)
214  */
215 extern SysScanDesc systable_beginscan(Relation heapRelation,
216  Oid indexId,
217  bool indexOK,
218  Snapshot snapshot,
219  int nkeys, ScanKey key);
220 extern HeapTuple systable_getnext(SysScanDesc sysscan);
221 extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup);
222 extern void systable_endscan(SysScanDesc sysscan);
224  Relation indexRelation,
225  Snapshot snapshot,
226  int nkeys, ScanKey key);
228  ScanDirection direction);
229 extern void systable_endscan_ordered(SysScanDesc sysscan);
230 
231 #endif /* GENAM_H */
int16 AttrNumber
Definition: attnum.h:21
uint32 BlockNumber
Definition: block.h:31
static Datum values[MAXATTR]
Definition: bootstrap.c:156
int Buffer
Definition: buf.h:23
unsigned short uint16
Definition: c.h:440
unsigned char bool
Definition: c.h:391
regproc RegProcedure
Definition: c.h:585
uint32 TransactionId
Definition: c.h:587
size_t Size
Definition: c.h:540
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:598
IndexBulkDeleteResult * index_vacuum_cleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *istat)
Definition: indexam.c:712
struct IndexOrderByDistance IndexOrderByDistance
bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
Definition: genam.c:564
bool index_insert(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_t_ctid, Relation heapRelation, IndexUniqueCheck checkUnique, bool indexUnchanged, struct IndexInfo *indexInfo)
Definition: indexam.c:176
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition: genam.h:86
void IndexScanEnd(IndexScanDesc scan)
Definition: genam.c:145
IndexUniqueCheck
Definition: genam.h:115
@ UNIQUE_CHECK_NO
Definition: genam.h:116
@ UNIQUE_CHECK_EXISTING
Definition: genam.h:119
@ UNIQUE_CHECK_PARTIAL
Definition: genam.h:118
@ UNIQUE_CHECK_YES
Definition: genam.h:117
void index_restrpos(IndexScanDesc scan)
Definition: indexam.c:377
char * BuildIndexValueDescription(Relation indexRelation, Datum *values, bool *isnull)
Definition: genam.c:177
IndexScanDesc index_beginscan_parallel(Relation heaprel, Relation indexrel, int nkeys, int norderbys, ParallelIndexScanDesc pscan)
Definition: indexam.c:484
struct IndexVacuumInfo IndexVacuumInfo
IndexScanDesc index_beginscan_bitmap(Relation indexRelation, Snapshot snapshot, int nkeys)
Definition: indexam.c:234
TransactionId index_compute_xid_horizon_for_tuples(Relation irel, Relation hrel, Buffer ibuf, OffsetNumber *itemnos, int nitems)
Definition: genam.c:293
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
bool index_can_return(Relation indexRelation, int attno)
Definition: indexam.c:731
struct IndexBuildResult IndexBuildResult
ItemPointer index_getnext_tid(IndexScanDesc scan, ScanDirection direction)
Definition: indexam.c:517
SysScanDesc systable_beginscan_ordered(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:645
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:505
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:803
void index_parallelscan_initialize(Relation heaprel, Relation indexrel, Snapshot snapshot, ParallelIndexScanDesc target)
Definition: indexam.c:435
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, int norderbys)
Definition: indexam.c:205
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:769
bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction, struct TupleTableSlot *slot)
Definition: indexam.c:616
void systable_endscan_ordered(SysScanDesc sysscan)
Definition: genam.c:735
HeapTuple systable_getnext_ordered(SysScanDesc sysscan, ScanDirection direction)
Definition: genam.c:710
void index_markpos(IndexScanDesc scan)
Definition: indexam.c:353
bytea * index_opclass_options(Relation relation, AttrNumber attnum, Datum attoptions, bool validate)
Definition: indexam.c:939
void index_endscan(IndexScanDesc scan)
Definition: indexam.c:323
Size index_parallelscan_estimate(Relation indexrel, Snapshot snapshot)
Definition: indexam.c:402
struct IndexBulkDeleteResult IndexBulkDeleteResult
IndexBulkDeleteResult * index_bulk_delete(IndexVacuumInfo *info, IndexBulkDeleteResult *istat, IndexBulkDeleteCallback callback, void *callback_state)
Definition: indexam.c:691
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:132
struct SysScanDescData * SysScanDesc
Definition: genam.h:90
bool index_fetch_heap(IndexScanDesc scan, struct TupleTableSlot *slot)
Definition: indexam.c:575
int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap)
Definition: indexam.c:661
void index_parallelrescan(IndexScanDesc scan)
Definition: indexam.c:466
void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
Definition: indexam.c:297
struct ParallelIndexScanDescData * ParallelIndexScanDesc
Definition: genam.h:92
struct IndexScanDescData * IndexScanDesc
Definition: genam.h:89
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:386
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
Definition: genam.c:81
void index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes, IndexOrderByDistance *distances, bool recheckOrderBy)
Definition: indexam.c:871
int LOCKMODE
Definition: lockdefs.h:26
uint16 OffsetNumber
Definition: off.h:24
int16 attnum
Definition: pg_attribute.h:83
uintptr_t Datum
Definition: postgres.h:411
unsigned int Oid
Definition: postgres_ext.h:31
ScanDirection
Definition: sdir.h:23
Definition: fmgr.h:57
double heap_tuples
Definition: genam.h:32
double index_tuples
Definition: genam.h:33
bool estimated_count
Definition: genam.h:77
BlockNumber pages_deleted
Definition: genam.h:81
BlockNumber pages_newly_deleted
Definition: genam.h:80
BlockNumber pages_free
Definition: genam.h:82
BlockNumber num_pages
Definition: genam.h:76
double tuples_removed
Definition: genam.h:79
double num_index_tuples
Definition: genam.h:78
Relation index
Definition: genam.h:46
double num_heap_tuples
Definition: genam.h:51
bool analyze_only
Definition: genam.h:47
BufferAccessStrategy strategy
Definition: genam.h:52
bool report_progress
Definition: genam.h:48
int message_level
Definition: genam.h:50
bool estimated_count
Definition: genam.h:49
Definition: regguts.h:318
Definition: c.h:622
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48