PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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/cmptype.h"
16#include "access/genam.h"
17#include "access/stratnum.h"
18#include "nodes/nodes.h"
19#include "nodes/pg_list.h"
20
21/*
22 * We don't wish to include planner header files here, since most of an index
23 * AM's implementation isn't concerned with those data structures. To allow
24 * declaring amcostestimate_function here, use forward struct references.
25 */
26typedef struct PlannerInfo PlannerInfo;
27typedef struct IndexPath IndexPath;
28
29/* Likewise, this file shouldn't depend on execnodes.h. */
30typedef struct IndexInfo IndexInfo;
31
32
33/*
34 * Properties for amproperty API. This list covers properties known to the
35 * core code, but an index AM can define its own properties, by matching the
36 * string property name.
37 */
60
61/*
62 * We use lists of this struct type to keep track of both operators and
63 * support functions while building or adding to an opclass or opfamily.
64 * amadjustmembers functions receive lists of these structs, and are allowed
65 * to alter their "ref" fields.
66 *
67 * The "ref" fields define how the pg_amop or pg_amproc entry should depend
68 * on the associated objects (that is, which dependency type to use, and
69 * which opclass or opfamily it should depend on).
70 *
71 * If ref_is_hard is true, the entry will have a NORMAL dependency on the
72 * operator or support func, and an INTERNAL dependency on the opclass or
73 * opfamily. This forces the opclass or opfamily to be dropped if the
74 * operator or support func is dropped, and requires the CASCADE option
75 * to do so. Nor will ALTER OPERATOR FAMILY DROP be allowed. This is
76 * the right behavior for objects that are essential to an opclass.
77 *
78 * If ref_is_hard is false, the entry will have an AUTO dependency on the
79 * operator or support func, and also an AUTO dependency on the opclass or
80 * opfamily. This allows ALTER OPERATOR FAMILY DROP, and causes that to
81 * happen automatically if the operator or support func is dropped. This
82 * is the right behavior for inessential ("loose") objects.
83 *
84 * We also make dependencies on lefttype/righttype, of the same strength as
85 * the dependency on the operator or support func, unless these dependencies
86 * are redundant with the dependency on the operator or support func.
87 */
88typedef struct OpFamilyMember
89{
90 bool is_func; /* is this an operator, or support func? */
91 Oid object; /* operator or support func's OID */
92 int number; /* strategy or support func number */
93 Oid lefttype; /* lefttype */
94 Oid righttype; /* righttype */
95 Oid sortfamily; /* ordering operator's sort opfamily, or 0 */
96 bool ref_is_hard; /* hard or soft dependency? */
97 bool ref_is_family; /* is dependency on opclass or opfamily? */
98 Oid refobjid; /* OID of opclass or opfamily */
100
101
102/*
103 * Callback function signatures --- see indexam.sgml for more info.
104 */
105
106/* translate AM-specific strategies to general operator types */
108
109/* translate general operator types to AM-specific strategies */
111
112/* build new index */
113typedef IndexBuildResult *(*ambuild_function) (Relation heapRelation,
114 Relation indexRelation,
115 IndexInfo *indexInfo);
116
117/* build empty index */
118typedef void (*ambuildempty_function) (Relation indexRelation);
119
120/* insert this tuple */
121typedef bool (*aminsert_function) (Relation indexRelation,
122 Datum *values,
123 bool *isnull,
125 Relation heapRelation,
127 bool indexUnchanged,
128 IndexInfo *indexInfo);
129
130/* cleanup after insert */
131typedef void (*aminsertcleanup_function) (Relation indexRelation,
132 IndexInfo *indexInfo);
133
134/* bulk delete */
135typedef IndexBulkDeleteResult *(*ambulkdelete_function) (IndexVacuumInfo *info,
138 void *callback_state);
139
140/* post-VACUUM cleanup */
141typedef IndexBulkDeleteResult *(*amvacuumcleanup_function) (IndexVacuumInfo *info,
142 IndexBulkDeleteResult *stats);
143
144/* can indexscan return IndexTuples? */
145typedef bool (*amcanreturn_function) (Relation indexRelation, int attno);
146
147/* estimate cost of an indexscan */
149 IndexPath *path,
150 double loop_count,
151 Cost *indexStartupCost,
152 Cost *indexTotalCost,
153 Selectivity *indexSelectivity,
154 double *indexCorrelation,
155 double *indexPages);
156
157/*
158 * estimate height of a tree-structured index
159 *
160 * XXX This just computes a value that is later used by amcostestimate. This
161 * API could be expanded to support passing more values if the need arises.
162 */
164
165/* parse index reloptions */
166typedef bytea *(*amoptions_function) (Datum reloptions,
167 bool validate);
168
169/* report AM, index, or index column property */
170typedef bool (*amproperty_function) (Oid index_oid, int attno,
171 IndexAMProperty prop, const char *propname,
172 bool *res, bool *isnull);
173
174/* name of phase as used in progress reporting */
175typedef char *(*ambuildphasename_function) (int64 phasenum);
176
177/* validate definition of an opclass for this AM */
178typedef bool (*amvalidate_function) (Oid opclassoid);
179
180/* validate operators and support functions to be added to an opclass/family */
182 Oid opclassoid,
183 List *operators,
184 List *functions);
185
186/* prepare for index scan */
188 int nkeys,
189 int norderbys);
190
191/* (re)start index scan */
193 ScanKey keys,
194 int nkeys,
195 ScanKey orderbys,
196 int norderbys);
197
198/* next valid tuple */
200 ScanDirection direction);
201
202/* fetch all valid tuples */
204 TIDBitmap *tbm);
205
206/* end index scan */
208
209/* mark current scan position */
211
212/* restore marked scan position */
214
215/*
216 * Callback function signatures - for parallel index scans.
217 */
218
219/* estimate size of parallel scan descriptor */
221 int nkeys, int norderbys);
222
223/* prepare for parallel index scan */
224typedef void (*aminitparallelscan_function) (void *target);
225
226/* (re)start parallel index scan */
228
229/*
230 * API struct for an index AM. Note we expect index AMs to allocate these
231 * structs statically; the core code never copies nor frees them.
232 */
233typedef struct IndexAmRoutine
234{
236
237 /*
238 * Total number of strategies (operators) by which we can traverse/search
239 * this AM. Zero if AM does not have a fixed set of strategy assignments.
240 */
242 /* total number of support functions that this AM uses */
244 /* opclass options support function number or 0 */
246 /* does AM support ORDER BY indexed column's value? */
248 /* does AM support ORDER BY result of an operator on indexed column? */
250 /* does AM support hashing using API consistent with the hash AM? */
252 /* do operators within an opfamily have consistent equality semantics? */
254 /* do operators within an opfamily have consistent ordering semantics? */
256 /* does AM support backward scanning? */
258 /* does AM support UNIQUE indexes? */
260 /* does AM support multi-column indexes? */
262 /* does AM require scans to have a constraint on the first index column? */
264 /* does AM handle ScalarArrayOpExpr quals? */
266 /* does AM handle IS NULL/IS NOT NULL quals? */
268 /* can index storage data type differ from column data type? */
270 /* can an index of this type be clustered on? */
272 /* does AM handle predicate locks? */
274 /* does AM support parallel scan? */
276 /* does AM support parallel build? */
278 /* does AM support columns included with clause INCLUDE? */
280 /* does AM use maintenance_work_mem? */
282 /* does AM store tuple information only at block granularity? */
284 /* OR of parallel vacuum flags. See vacuum.h for flags. */
286 /* type of data stored in index, or InvalidOid if variable */
288
289 /*
290 * If you add new properties to either the above or the below lists, then
291 * they should also (usually) be exposed via the property API (see
292 * IndexAMProperty at the top of the file, and utils/adt/amutils.c).
293 */
294
295 /* interface functions */
315 ammarkpos_function ammarkpos; /* can be NULL */
317
318 /* interface functions to support parallel index scans */
322
323 /* interface functions to support planning */
327
328
329/* Functions in access/index/amapi.c */
330extern const IndexAmRoutine *GetIndexAmRoutine(Oid amhandler);
332extern CompareType IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, bool missing_ok);
333extern StrategyNumber IndexAmTranslateCompareType(CompareType cmptype, Oid amoid, Oid opfamily, bool missing_ok);
334
335#endif /* AMAPI_H */
void(* amparallelrescan_function)(IndexScanDesc scan)
Definition amapi.h:227
CompareType(* amtranslate_strategy_function)(StrategyNumber strategy, Oid opfamily)
Definition amapi.h:107
IndexScanDesc(* ambeginscan_function)(Relation indexRelation, int nkeys, int norderbys)
Definition amapi.h:187
void(* amadjustmembers_function)(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
Definition amapi.h:181
int(* amgettreeheight_function)(Relation rel)
Definition amapi.h:163
bool(* amproperty_function)(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
Definition amapi.h:170
bool(* amvalidate_function)(Oid opclassoid)
Definition amapi.h:178
void(* amendscan_function)(IndexScanDesc scan)
Definition amapi.h:207
IndexBulkDeleteResult *(* ambulkdelete_function)(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition amapi.h:135
bool(* amcanreturn_function)(Relation indexRelation, int attno)
Definition amapi.h:145
const IndexAmRoutine * GetIndexAmRoutineByAmId(Oid amoid, bool noerror)
Definition amapi.c:69
const IndexAmRoutine * GetIndexAmRoutine(Oid amhandler)
Definition amapi.c:33
bytea *(* amoptions_function)(Datum reloptions, bool validate)
Definition amapi.h:166
IndexBuildResult *(* ambuild_function)(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo)
Definition amapi.h:113
void(* ambuildempty_function)(Relation indexRelation)
Definition amapi.h:118
StrategyNumber(* amtranslate_cmptype_function)(CompareType cmptype, Oid opfamily)
Definition amapi.h:110
int64(* amgetbitmap_function)(IndexScanDesc scan, TIDBitmap *tbm)
Definition amapi.h:203
void(* amrestrpos_function)(IndexScanDesc scan)
Definition amapi.h:213
char *(* ambuildphasename_function)(int64 phasenum)
Definition amapi.h:175
IndexBulkDeleteResult *(* amvacuumcleanup_function)(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition amapi.h:141
bool(* amgettuple_function)(IndexScanDesc scan, ScanDirection direction)
Definition amapi.h:199
StrategyNumber IndexAmTranslateCompareType(CompareType cmptype, Oid amoid, Oid opfamily, bool missing_ok)
Definition amapi.c:161
IndexAMProperty
Definition amapi.h:39
@ AMPROP_BACKWARD_SCAN
Definition amapi.h:53
@ AMPROP_SEARCH_ARRAY
Definition amapi.h:48
@ AMPROP_CAN_MULTI_COL
Definition amapi.h:56
@ AMPROP_CAN_ORDER
Definition amapi.h:54
@ AMPROP_ORDERABLE
Definition amapi.h:45
@ AMPROP_ASC
Definition amapi.h:41
@ AMPROP_DISTANCE_ORDERABLE
Definition amapi.h:46
@ AMPROP_CAN_INCLUDE
Definition amapi.h:58
@ AMPROP_SEARCH_NULLS
Definition amapi.h:49
@ AMPROP_CAN_EXCLUDE
Definition amapi.h:57
@ AMPROP_UNKNOWN
Definition amapi.h:40
@ AMPROP_CAN_UNIQUE
Definition amapi.h:55
@ AMPROP_DESC
Definition amapi.h:42
@ AMPROP_NULLS_LAST
Definition amapi.h:44
@ AMPROP_INDEX_SCAN
Definition amapi.h:51
@ AMPROP_NULLS_FIRST
Definition amapi.h:43
@ AMPROP_CLUSTERABLE
Definition amapi.h:50
@ AMPROP_RETURNABLE
Definition amapi.h:47
@ AMPROP_BITMAP_SCAN
Definition amapi.h:52
void(* amcostestimate_function)(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Definition amapi.h:148
Size(* amestimateparallelscan_function)(Relation indexRelation, int nkeys, int norderbys)
Definition amapi.h:220
void(* aminsertcleanup_function)(Relation indexRelation, IndexInfo *indexInfo)
Definition amapi.h:131
void(* aminitparallelscan_function)(void *target)
Definition amapi.h:224
void(* ammarkpos_function)(IndexScanDesc scan)
Definition amapi.h:210
CompareType IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, bool missing_ok)
Definition amapi.c:131
bool(* aminsert_function)(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_tid, Relation heapRelation, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
Definition amapi.h:121
void(* amrescan_function)(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
Definition amapi.h:192
static bool validate(Port *port, const char *auth, const char **logdetail)
Definition auth-oauth.c:672
static Datum values[MAXATTR]
Definition bootstrap.c:190
uint8_t uint8
Definition c.h:622
int64_t int64
Definition c.h:621
uint16_t uint16
Definition c.h:623
size_t Size
Definition c.h:689
CompareType
Definition cmptype.h:32
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition genam.h:95
IndexUniqueCheck
Definition genam.h:124
struct IndexScanDescData * IndexScanDesc
Definition genam.h:98
double Cost
Definition nodes.h:261
NodeTag
Definition nodes.h:27
double Selectivity
Definition nodes.h:260
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
static int fb(int x)
tree ctl root
Definition radixtree.h:1857
static const struct fns functions
Definition regcomp.c:358
ScanDirection
Definition sdir.h:25
uint16 StrategyNumber
Definition stratnum.h:22
ambuildphasename_function ambuildphasename
Definition amapi.h:307
ambuildempty_function ambuildempty
Definition amapi.h:297
amvacuumcleanup_function amvacuumcleanup
Definition amapi.h:301
bool amclusterable
Definition amapi.h:271
amoptions_function amoptions
Definition amapi.h:305
amestimateparallelscan_function amestimateparallelscan
Definition amapi.h:319
amrestrpos_function amrestrpos
Definition amapi.h:316
aminsert_function aminsert
Definition amapi.h:298
amendscan_function amendscan
Definition amapi.h:314
amtranslate_strategy_function amtranslatestrategy
Definition amapi.h:324
uint16 amoptsprocnum
Definition amapi.h:245
amparallelrescan_function amparallelrescan
Definition amapi.h:321
Oid amkeytype
Definition amapi.h:287
bool amconsistentordering
Definition amapi.h:255
bool ampredlocks
Definition amapi.h:273
uint16 amsupport
Definition amapi.h:243
amtranslate_cmptype_function amtranslatecmptype
Definition amapi.h:325
amcostestimate_function amcostestimate
Definition amapi.h:303
bool amcanorderbyop
Definition amapi.h:249
amadjustmembers_function amadjustmembers
Definition amapi.h:309
ambuild_function ambuild
Definition amapi.h:296
bool amstorage
Definition amapi.h:269
uint16 amstrategies
Definition amapi.h:241
bool amoptionalkey
Definition amapi.h:263
amgettuple_function amgettuple
Definition amapi.h:312
amcanreturn_function amcanreturn
Definition amapi.h:302
bool amcanunique
Definition amapi.h:259
amgetbitmap_function amgetbitmap
Definition amapi.h:313
amproperty_function amproperty
Definition amapi.h:306
ambulkdelete_function ambulkdelete
Definition amapi.h:300
bool amsearcharray
Definition amapi.h:265
bool amsummarizing
Definition amapi.h:283
amvalidate_function amvalidate
Definition amapi.h:308
ammarkpos_function ammarkpos
Definition amapi.h:315
bool amcanmulticol
Definition amapi.h:261
bool amusemaintenanceworkmem
Definition amapi.h:281
ambeginscan_function ambeginscan
Definition amapi.h:310
bool amcanparallel
Definition amapi.h:275
amrescan_function amrescan
Definition amapi.h:311
bool amcanorder
Definition amapi.h:247
bool amcanbuildparallel
Definition amapi.h:277
aminitparallelscan_function aminitparallelscan
Definition amapi.h:320
uint8 amparallelvacuumoptions
Definition amapi.h:285
aminsertcleanup_function aminsertcleanup
Definition amapi.h:299
bool amcanbackward
Definition amapi.h:257
amgettreeheight_function amgettreeheight
Definition amapi.h:304
NodeTag type
Definition amapi.h:235
bool amcaninclude
Definition amapi.h:279
bool amsearchnulls
Definition amapi.h:267
bool amconsistentequality
Definition amapi.h:253
bool amcanhash
Definition amapi.h:251
Definition pg_list.h:54
Oid refobjid
Definition amapi.h:98
Oid lefttype
Definition amapi.h:93
bool ref_is_family
Definition amapi.h:97
Oid righttype
Definition amapi.h:94
bool is_func
Definition amapi.h:90
bool ref_is_hard
Definition amapi.h:96
Oid sortfamily
Definition amapi.h:95
Definition c.h:776
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)