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-2016, 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  * Callback function signatures --- see indexam.sgml for more info.
31  */
32 
33 /* build new index */
34 typedef IndexBuildResult *(*ambuild_function) (Relation heapRelation,
35  Relation indexRelation,
36  struct IndexInfo *indexInfo);
37 
38 /* build empty index */
39 typedef void (*ambuildempty_function) (Relation indexRelation);
40 
41 /* insert this tuple */
42 typedef bool (*aminsert_function) (Relation indexRelation,
43  Datum *values,
44  bool *isnull,
45  ItemPointer heap_tid,
46  Relation heapRelation,
47  IndexUniqueCheck checkUnique);
48 
49 /* bulk delete */
50 typedef IndexBulkDeleteResult *(*ambulkdelete_function) (IndexVacuumInfo *info,
51  IndexBulkDeleteResult *stats,
53  void *callback_state);
54 
55 /* post-VACUUM cleanup */
56 typedef IndexBulkDeleteResult *(*amvacuumcleanup_function) (IndexVacuumInfo *info,
57  IndexBulkDeleteResult *stats);
58 
59 /* can indexscan return IndexTuples? */
60 typedef bool (*amcanreturn_function) (Relation indexRelation, int attno);
61 
62 /* estimate cost of an indexscan */
63 typedef void (*amcostestimate_function) (struct PlannerInfo *root,
64  struct IndexPath *path,
65  double loop_count,
66  Cost *indexStartupCost,
67  Cost *indexTotalCost,
68  Selectivity *indexSelectivity,
69  double *indexCorrelation);
70 
71 /* parse index reloptions */
72 typedef bytea *(*amoptions_function) (Datum reloptions,
73  bool validate);
74 
75 /* validate definition of an opclass for this AM */
76 typedef bool (*amvalidate_function) (Oid opclassoid);
77 
78 /* prepare for index scan */
79 typedef IndexScanDesc (*ambeginscan_function) (Relation indexRelation,
80  int nkeys,
81  int norderbys);
82 
83 /* (re)start index scan */
84 typedef void (*amrescan_function) (IndexScanDesc scan,
85  ScanKey keys,
86  int nkeys,
87  ScanKey orderbys,
88  int norderbys);
89 
90 /* next valid tuple */
92  ScanDirection direction);
93 
94 /* fetch all valid tuples */
95 typedef int64 (*amgetbitmap_function) (IndexScanDesc scan,
96  TIDBitmap *tbm);
97 
98 /* end index scan */
99 typedef void (*amendscan_function) (IndexScanDesc scan);
100 
101 /* mark current scan position */
102 typedef void (*ammarkpos_function) (IndexScanDesc scan);
103 
104 /* restore marked scan position */
105 typedef void (*amrestrpos_function) (IndexScanDesc scan);
106 
107 
108 /*
109  * API struct for an index AM. Note this must be stored in a single palloc'd
110  * chunk of memory.
111  */
112 typedef struct IndexAmRoutine
113 {
115 
116  /*
117  * Total number of strategies (operators) by which we can traverse/search
118  * this AM. Zero if AM does not have a fixed set of strategy assignments.
119  */
121  /* total number of support functions that this AM uses */
123  /* does AM support ORDER BY indexed column's value? */
125  /* does AM support ORDER BY result of an operator on indexed column? */
127  /* does AM support backward scanning? */
129  /* does AM support UNIQUE indexes? */
131  /* does AM support multi-column indexes? */
133  /* does AM require scans to have a constraint on the first index column? */
135  /* does AM handle ScalarArrayOpExpr quals? */
137  /* does AM handle IS NULL/IS NOT NULL quals? */
139  /* can index storage data type differ from column data type? */
140  bool amstorage;
141  /* can an index of this type be clustered on? */
143  /* does AM handle predicate locks? */
145  /* type of data stored in index, or InvalidOid if variable */
147 
148  /* interface functions */
160  amgettuple_function amgettuple; /* can be NULL */
163  ammarkpos_function ammarkpos; /* can be NULL */
164  amrestrpos_function amrestrpos; /* can be NULL */
166 
167 
168 /* Functions in access/index/amapi.c */
169 extern IndexAmRoutine *GetIndexAmRoutine(Oid amhandler);
171 
173 
174 #endif /* AMAPI_H */
ambeginscan_function ambeginscan
Definition: amapi.h:158
void(* ambuildempty_function)(Relation indexRelation)
Definition: amapi.h:39
ambulkdelete_function ambulkdelete
Definition: amapi.h:152
bool amcanmulticol
Definition: amapi.h:132
uint16 amsupport
Definition: amapi.h:122
NodeTag type
Definition: amapi.h:114
Path path
Definition: relation.h:944
amgettuple_function amgettuple
Definition: amapi.h:160
bool amcanorderbyop
Definition: amapi.h:126
Datum amvalidate(PG_FUNCTION_ARGS)
Definition: amapi.c:92
bool amstorage
Definition: amapi.h:140
IndexBulkDeleteResult *(* ambulkdelete_function)(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition: amapi.h:50
bool ampredlocks
Definition: amapi.h:144
aminsert_function aminsert
Definition: amapi.h:151
double Selectivity
Definition: nodes.h:593
unsigned int Oid
Definition: postgres_ext.h:31
NodeTag
Definition: nodes.h:26
Oid amkeytype
Definition: amapi.h:146
bool amoptionalkey
Definition: amapi.h:134
amvalidate_function amvalidate
Definition: amapi.h:157
char bool
Definition: c.h:199
IndexUniqueCheck
Definition: genam.h:106
unsigned short uint16
Definition: c.h:264
void(* amrestrpos_function)(IndexScanDesc scan)
Definition: amapi.h:105
bool(* amgettuple_function)(IndexScanDesc scan, ScanDirection direction)
Definition: amapi.h:91
amgetbitmap_function amgetbitmap
Definition: amapi.h:161
ambuild_function ambuild
Definition: amapi.h:149
amoptions_function amoptions
Definition: amapi.h:156
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:49
amcostestimate_function amcostestimate
Definition: amapi.h:155
bool amcanunique
Definition: amapi.h:130
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:153
amendscan_function amendscan
Definition: amapi.h:162
bool amcanbackward
Definition: amapi.h:128
ScanDirection
Definition: sdir.h:22
struct IndexAmRoutine IndexAmRoutine
IndexScanDesc(* ambeginscan_function)(Relation indexRelation, int nkeys, int norderbys)
Definition: amapi.h:79
amrescan_function amrescan
Definition: amapi.h:159
bytea *(* amoptions_function)(Datum reloptions, bool validate)
Definition: amapi.h:72
bool amsearchnulls
Definition: amapi.h:138
uintptr_t Datum
Definition: postgres.h:374
bool amclusterable
Definition: amapi.h:142
bool amsearcharray
Definition: amapi.h:136
IndexAmRoutine * GetIndexAmRoutineByAmId(Oid amoid)
Definition: amapi.c:52
void(* amendscan_function)(IndexScanDesc scan)
Definition: amapi.h:99
IndexBulkDeleteResult *(* amvacuumcleanup_function)(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: amapi.h:56
void(* ammarkpos_function)(IndexScanDesc scan)
Definition: amapi.h:102
bool(* aminsert_function)(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_tid, Relation heapRelation, IndexUniqueCheck checkUnique)
Definition: amapi.h:42
ammarkpos_function ammarkpos
Definition: amapi.h:163
bool amcanorder
Definition: amapi.h:124
int64(* amgetbitmap_function)(IndexScanDesc scan, TIDBitmap *tbm)
Definition: amapi.h:95
uint16 amstrategies
Definition: amapi.h:120
static Datum values[MAXATTR]
Definition: bootstrap.c:160
void(* amrescan_function)(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
Definition: amapi.h:84
IndexAmRoutine * GetIndexAmRoutine(Oid amhandler)
Definition: amapi.c:32
bool(* amvalidate_function)(Oid opclassoid)
Definition: amapi.h:76
ambuildempty_function ambuildempty
Definition: amapi.h:150
Definition: c.h:434
#define PG_FUNCTION_ARGS
Definition: fmgr.h:150
IndexBuildResult *(* ambuild_function)(Relation heapRelation, Relation indexRelation, struct IndexInfo *indexInfo)
Definition: amapi.h:34
void(* amcostestimate_function)(struct PlannerInfo *root, struct IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation)
Definition: amapi.h:63
amcanreturn_function amcanreturn
Definition: amapi.h:154
struct IndexScanDescData * IndexScanDesc
Definition: genam.h:83
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition: genam.h:80
double Cost
Definition: nodes.h:594
bool(* amcanreturn_function)(Relation indexRelation, int attno)
Definition: amapi.h:60
amrestrpos_function amrestrpos
Definition: amapi.h:164