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