PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
amapi.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * amapi.h
4  * API for Postgres index access methods.
5  *
6  * Copyright (c) 2015-2017, PostgreSQL Global Development Group
7  *
8  * src/include/access/amapi.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 #ifndef AMAPI_H
13 #define AMAPI_H
14 
15 #include "access/genam.h"
16 
17 /*
18  * We don't wish to include planner header files here, since most of an index
19  * AM's implementation isn't concerned with those data structures. To allow
20  * declaring amcostestimate_function here, use forward struct references.
21  */
22 struct PlannerInfo;
23 struct IndexPath;
24 
25 /* Likewise, this file shouldn't depend on execnodes.h. */
26 struct IndexInfo;
27 
28 
29 /*
30  * Properties for amproperty API. This list covers properties known to the
31  * core code, but an index AM can define its own properties, by matching the
32  * string property name.
33  */
34 typedef enum IndexAMProperty
35 {
36  AMPROP_UNKNOWN = 0, /* anything not known to core code */
37  AMPROP_ASC, /* column properties */
46  AMPROP_CLUSTERABLE, /* index properties */
50  AMPROP_CAN_ORDER, /* AM properties */
55 
56 
57 /*
58  * Callback function signatures --- see indexam.sgml for more info.
59  */
60 
61 /* build new index */
62 typedef IndexBuildResult *(*ambuild_function) (Relation heapRelation,
63  Relation indexRelation,
64  struct IndexInfo *indexInfo);
65 
66 /* build empty index */
67 typedef void (*ambuildempty_function) (Relation indexRelation);
68 
69 /* insert this tuple */
70 typedef bool (*aminsert_function) (Relation indexRelation,
71  Datum *values,
72  bool *isnull,
73  ItemPointer heap_tid,
74  Relation heapRelation,
75  IndexUniqueCheck checkUnique,
76  struct IndexInfo *indexInfo);
77 
78 /* bulk delete */
79 typedef IndexBulkDeleteResult *(*ambulkdelete_function) (IndexVacuumInfo *info,
80  IndexBulkDeleteResult *stats,
82  void *callback_state);
83 
84 /* post-VACUUM cleanup */
85 typedef IndexBulkDeleteResult *(*amvacuumcleanup_function) (IndexVacuumInfo *info,
86  IndexBulkDeleteResult *stats);
87 
88 /* can indexscan return IndexTuples? */
89 typedef bool (*amcanreturn_function) (Relation indexRelation, int attno);
90 
91 /* estimate cost of an indexscan */
92 typedef void (*amcostestimate_function) (struct PlannerInfo *root,
93  struct IndexPath *path,
94  double loop_count,
95  Cost *indexStartupCost,
96  Cost *indexTotalCost,
97  Selectivity *indexSelectivity,
98  double *indexCorrelation,
99  double *indexPages);
100 
101 /* parse index reloptions */
102 typedef bytea *(*amoptions_function) (Datum reloptions,
103  bool validate);
104 
105 /* report AM, index, or index column property */
106 typedef bool (*amproperty_function) (Oid index_oid, int attno,
107  IndexAMProperty prop, const char *propname,
108  bool *res, bool *isnull);
109 
110 /* validate definition of an opclass for this AM */
111 typedef bool (*amvalidate_function) (Oid opclassoid);
112 
113 /* prepare for index scan */
114 typedef IndexScanDesc (*ambeginscan_function) (Relation indexRelation,
115  int nkeys,
116  int norderbys);
117 
118 /* (re)start index scan */
119 typedef void (*amrescan_function) (IndexScanDesc scan,
120  ScanKey keys,
121  int nkeys,
122  ScanKey orderbys,
123  int norderbys);
124 
125 /* next valid tuple */
127  ScanDirection direction);
128 
129 /* fetch all valid tuples */
130 typedef int64 (*amgetbitmap_function) (IndexScanDesc scan,
131  TIDBitmap *tbm);
132 
133 /* end index scan */
134 typedef void (*amendscan_function) (IndexScanDesc scan);
135 
136 /* mark current scan position */
137 typedef void (*ammarkpos_function) (IndexScanDesc scan);
138 
139 /* restore marked scan position */
140 typedef void (*amrestrpos_function) (IndexScanDesc scan);
141 
142 /*
143  * Callback function signatures - for parallel index scans.
144  */
145 
146 /* estimate size of parallel scan descriptor */
148 
149 /* prepare for parallel index scan */
150 typedef void (*aminitparallelscan_function) (void *target);
151 
152 /* (re)start parallel index scan */
154 
155 /*
156  * API struct for an index AM. Note this must be stored in a single palloc'd
157  * chunk of memory.
158  */
159 typedef struct IndexAmRoutine
160 {
162 
163  /*
164  * Total number of strategies (operators) by which we can traverse/search
165  * this AM. Zero if AM does not have a fixed set of strategy assignments.
166  */
168  /* total number of support functions that this AM uses */
170  /* does AM support ORDER BY indexed column's value? */
172  /* does AM support ORDER BY result of an operator on indexed column? */
174  /* does AM support backward scanning? */
176  /* does AM support UNIQUE indexes? */
178  /* does AM support multi-column indexes? */
180  /* does AM require scans to have a constraint on the first index column? */
182  /* does AM handle ScalarArrayOpExpr quals? */
184  /* does AM handle IS NULL/IS NOT NULL quals? */
186  /* can index storage data type differ from column data type? */
187  bool amstorage;
188  /* can an index of this type be clustered on? */
190  /* does AM handle predicate locks? */
192  /* does AM support parallel scan? */
194  /* type of data stored in index, or InvalidOid if variable */
196 
197  /* interface functions */
206  amproperty_function amproperty; /* can be NULL */
210  amgettuple_function amgettuple; /* can be NULL */
213  ammarkpos_function ammarkpos; /* can be NULL */
214  amrestrpos_function amrestrpos; /* can be NULL */
215 
216  /* interface functions to support parallel index scans */
221 
222 
223 /* Functions in access/index/amapi.c */
224 extern IndexAmRoutine *GetIndexAmRoutine(Oid amhandler);
225 extern IndexAmRoutine *GetIndexAmRoutineByAmId(Oid amoid, bool noerror);
226 
227 #endif /* AMAPI_H */
ambeginscan_function ambeginscan
Definition: amapi.h:208
void(* ambuildempty_function)(Relation indexRelation)
Definition: amapi.h:67
ambulkdelete_function ambulkdelete
Definition: amapi.h:201
bool amcanmulticol
Definition: amapi.h:179
uint16 amsupport
Definition: amapi.h:169
NodeTag type
Definition: amapi.h:161
Path path
Definition: relation.h:971
IndexAMProperty
Definition: amapi.h:34
amgettuple_function amgettuple
Definition: amapi.h:210
bool amcanorderbyop
Definition: amapi.h:173
amproperty_function amproperty
Definition: amapi.h:206
amparallelrescan_function amparallelrescan
Definition: amapi.h:219
bool amstorage
Definition: amapi.h:187
IndexBulkDeleteResult *(* ambulkdelete_function)(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition: amapi.h:79
bool ampredlocks
Definition: amapi.h:191
aminsert_function aminsert
Definition: amapi.h:200
double Selectivity
Definition: nodes.h:632
unsigned int Oid
Definition: postgres_ext.h:31
NodeTag
Definition: nodes.h:26
Oid amkeytype
Definition: amapi.h:195
bool amoptionalkey
Definition: amapi.h:181
amvalidate_function amvalidate
Definition: amapi.h:207
char bool
Definition: c.h:199
IndexUniqueCheck
Definition: genam.h:111
unsigned short uint16
Definition: c.h:264
void(* amrestrpos_function)(IndexScanDesc scan)
Definition: amapi.h:140
bool(* amgettuple_function)(IndexScanDesc scan, ScanDirection direction)
Definition: amapi.h:126
amgetbitmap_function amgetbitmap
Definition: amapi.h:211
ambuild_function ambuild
Definition: amapi.h:198
amoptions_function amoptions
Definition: amapi.h:205
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:49
amcostestimate_function amcostestimate
Definition: amapi.h:204
bool amcanunique
Definition: amapi.h:177
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:202
amendscan_function amendscan
Definition: amapi.h:212
bool amcanbackward
Definition: amapi.h:175
ScanDirection
Definition: sdir.h:22
struct IndexAmRoutine IndexAmRoutine
IndexScanDesc(* ambeginscan_function)(Relation indexRelation, int nkeys, int norderbys)
Definition: amapi.h:114
amrescan_function amrescan
Definition: amapi.h:209
bool amcanparallel
Definition: amapi.h:193
bytea *(* amoptions_function)(Datum reloptions, bool validate)
Definition: amapi.h:102
bool(* aminsert_function)(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_tid, Relation heapRelation, IndexUniqueCheck checkUnique, struct IndexInfo *indexInfo)
Definition: amapi.h:70
bool amsearchnulls
Definition: amapi.h:185
uintptr_t Datum
Definition: postgres.h:374
bool amclusterable
Definition: amapi.h:189
bool amsearcharray
Definition: amapi.h:183
void(* amendscan_function)(IndexScanDesc scan)
Definition: amapi.h:134
IndexBulkDeleteResult *(* amvacuumcleanup_function)(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: amapi.h:85
void(* ammarkpos_function)(IndexScanDesc scan)
Definition: amapi.h:137
size_t Size
Definition: c.h:353
ammarkpos_function ammarkpos
Definition: amapi.h:213
bool amcanorder
Definition: amapi.h:171
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:217
int64(* amgetbitmap_function)(IndexScanDesc scan, TIDBitmap *tbm)
Definition: amapi.h:130
bool(* amproperty_function)(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
Definition: amapi.h:106
uint16 amstrategies
Definition: amapi.h:167
static Datum values[MAXATTR]
Definition: bootstrap.c:162
IndexAmRoutine * GetIndexAmRoutineByAmId(Oid amoid, bool noerror)
Definition: amapi.c:56
void(* amrescan_function)(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
Definition: amapi.h:119
IndexAmRoutine * GetIndexAmRoutine(Oid amhandler)
Definition: amapi.c:33
bool(* amvalidate_function)(Oid opclassoid)
Definition: amapi.h:111
void(* amparallelrescan_function)(IndexScanDesc scan)
Definition: amapi.h:153
ambuildempty_function ambuildempty
Definition: amapi.h:199
Definition: c.h:435
IndexBuildResult *(* ambuild_function)(Relation heapRelation, Relation indexRelation, struct IndexInfo *indexInfo)
Definition: amapi.h:62
Size(* amestimateparallelscan_function)(void)
Definition: amapi.h:147
void(* aminitparallelscan_function)(void *target)
Definition: amapi.h:150
amcanreturn_function amcanreturn
Definition: amapi.h:203
struct IndexScanDescData * IndexScanDesc
Definition: genam.h:86
void(* amcostestimate_function)(struct PlannerInfo *root, struct IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Definition: amapi.h:92
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition: genam.h:83
double Cost
Definition: nodes.h:633
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:218
bool(* amcanreturn_function)(Relation indexRelation, int attno)
Definition: amapi.h:89
amrestrpos_function amrestrpos
Definition: amapi.h:214