Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

PostgreSQL Source Code git master
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#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 */
38typedef enum IndexAMProperty
39{
40 AMPROP_UNKNOWN = 0, /* anything not known to core code */
41 AMPROP_ASC, /* column properties */
50 AMPROP_CLUSTERABLE, /* index properties */
54 AMPROP_CAN_ORDER, /* AM properties */
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,
124 ItemPointer heap_tid,
125 Relation heapRelation,
126 IndexUniqueCheck checkUnique,
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/* estimate height of a tree-structured index
158 *
159 * XXX This just computes a value that is later used by amcostestimate. This
160 * API could be expanded to support passing more values if the need arises.
161 */
163
164/* parse index reloptions */
165typedef bytea *(*amoptions_function) (Datum reloptions,
166 bool validate);
167
168/* report AM, index, or index column property */
169typedef bool (*amproperty_function) (Oid index_oid, int attno,
170 IndexAMProperty prop, const char *propname,
171 bool *res, bool *isnull);
172
173/* name of phase as used in progress reporting */
174typedef char *(*ambuildphasename_function) (int64 phasenum);
175
176/* validate definition of an opclass for this AM */
177typedef bool (*amvalidate_function) (Oid opclassoid);
178
179/* validate operators and support functions to be added to an opclass/family */
180typedef void (*amadjustmembers_function) (Oid opfamilyoid,
181 Oid opclassoid,
182 List *operators,
183 List *functions);
184
185/* prepare for index scan */
187 int nkeys,
188 int norderbys);
189
190/* (re)start index scan */
191typedef void (*amrescan_function) (IndexScanDesc scan,
192 ScanKey keys,
193 int nkeys,
194 ScanKey orderbys,
195 int norderbys);
196
197/* next valid tuple */
198typedef bool (*amgettuple_function) (IndexScanDesc scan,
199 ScanDirection direction);
200
201/* fetch all valid tuples */
203 TIDBitmap *tbm);
204
205/* end index scan */
206typedef void (*amendscan_function) (IndexScanDesc scan);
207
208/* mark current scan position */
209typedef void (*ammarkpos_function) (IndexScanDesc scan);
210
211/* restore marked scan position */
212typedef void (*amrestrpos_function) (IndexScanDesc scan);
213
214/*
215 * Callback function signatures - for parallel index scans.
216 */
217
218/* estimate size of parallel scan descriptor */
220 int nkeys, int norderbys);
221
222/* prepare for parallel index scan */
223typedef void (*aminitparallelscan_function) (void *target);
224
225/* (re)start parallel index scan */
227
228/*
229 * API struct for an index AM. Note this must be stored in a single palloc'd
230 * chunk of memory.
231 */
232typedef struct IndexAmRoutine
233{
235
236 /*
237 * Total number of strategies (operators) by which we can traverse/search
238 * this AM. Zero if AM does not have a fixed set of strategy assignments.
239 */
241 /* total number of support functions that this AM uses */
243 /* opclass options support function number or 0 */
245 /* does AM support ORDER BY indexed column's value? */
247 /* does AM support ORDER BY result of an operator on indexed column? */
249 /* does AM support hashing using API consistent with the hash AM? */
251 /* do operators within an opfamily have consistent equality semantics? */
253 /* do operators within an opfamily have consistent ordering semantics? */
255 /* does AM support backward scanning? */
257 /* does AM support UNIQUE indexes? */
259 /* does AM support multi-column indexes? */
261 /* does AM require scans to have a constraint on the first index column? */
263 /* does AM handle ScalarArrayOpExpr quals? */
265 /* does AM handle IS NULL/IS NOT NULL quals? */
267 /* can index storage data type differ from column data type? */
269 /* can an index of this type be clustered on? */
271 /* does AM handle predicate locks? */
273 /* does AM support parallel scan? */
275 /* does AM support parallel build? */
277 /* does AM support columns included with clause INCLUDE? */
279 /* does AM use maintenance_work_mem? */
281 /* does AM store tuple information only at block granularity? */
283 /* OR of parallel vacuum flags. See vacuum.h for flags. */
285 /* type of data stored in index, or InvalidOid if variable */
287
288 /*
289 * If you add new properties to either the above or the below lists, then
290 * they should also (usually) be exposed via the property API (see
291 * IndexAMProperty at the top of the file, and utils/adt/amutils.c).
292 */
293
294 /* interface functions */
314 ammarkpos_function ammarkpos; /* can be NULL */
316
317 /* interface functions to support parallel index scans */
321
322 /* interface functions to support planning */
326
327
328/* Functions in access/index/amapi.c */
329extern IndexAmRoutine *GetIndexAmRoutine(Oid amhandler);
330extern IndexAmRoutine *GetIndexAmRoutineByAmId(Oid amoid, bool noerror);
331extern CompareType IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, bool missing_ok);
332extern StrategyNumber IndexAmTranslateCompareType(CompareType cmptype, Oid amoid, Oid opfamily, bool missing_ok);
333
334#endif /* AMAPI_H */
IndexAmRoutine * GetIndexAmRoutine(Oid amhandler)
Definition: amapi.c:33
void(* amparallelrescan_function)(IndexScanDesc scan)
Definition: amapi.h:226
CompareType(* amtranslate_strategy_function)(StrategyNumber strategy, Oid opfamily)
Definition: amapi.h:107
IndexScanDesc(* ambeginscan_function)(Relation indexRelation, int nkeys, int norderbys)
Definition: amapi.h:186
void(* amadjustmembers_function)(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
Definition: amapi.h:180
int(* amgettreeheight_function)(Relation rel)
Definition: amapi.h:162
bool(* amproperty_function)(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
Definition: amapi.h:169
bool(* amvalidate_function)(Oid opclassoid)
Definition: amapi.h:177
void(* amendscan_function)(IndexScanDesc scan)
Definition: amapi.h:206
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
bytea *(* amoptions_function)(Datum reloptions, bool validate)
Definition: amapi.h:165
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:202
void(* amrestrpos_function)(IndexScanDesc scan)
Definition: amapi.h:212
char *(* ambuildphasename_function)(int64 phasenum)
Definition: amapi.h:174
IndexBulkDeleteResult *(* amvacuumcleanup_function)(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: amapi.h:141
bool(* amgettuple_function)(IndexScanDesc scan, ScanDirection direction)
Definition: amapi.h:198
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:219
void(* aminsertcleanup_function)(Relation indexRelation, IndexInfo *indexInfo)
Definition: amapi.h:131
void(* aminitparallelscan_function)(void *target)
Definition: amapi.h:223
void(* ammarkpos_function)(IndexScanDesc scan)
Definition: amapi.h:209
struct OpFamilyMember OpFamilyMember
CompareType IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, bool missing_ok)
Definition: amapi.c:131
IndexAmRoutine * GetIndexAmRoutineByAmId(Oid amoid, bool noerror)
Definition: amapi.c:69
struct IndexAmRoutine IndexAmRoutine
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:191
static bool validate(Port *port, const char *auth)
Definition: auth-oauth.c:638
static Datum values[MAXATTR]
Definition: bootstrap.c:153
uint8_t uint8
Definition: c.h:536
int64_t int64
Definition: c.h:535
uint16_t uint16
Definition: c.h:537
size_t Size
Definition: c.h:610
CompareType
Definition: cmptype.h:32
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition: genam.h:114
IndexUniqueCheck
Definition: genam.h:143
struct IndexScanDescData * IndexScanDesc
Definition: genam.h:117
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
Definition: postgres_ext.h:32
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:306
ambuildempty_function ambuildempty
Definition: amapi.h:296
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:300
bool amclusterable
Definition: amapi.h:270
amoptions_function amoptions
Definition: amapi.h:304
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:318
amrestrpos_function amrestrpos
Definition: amapi.h:315
aminsert_function aminsert
Definition: amapi.h:297
amendscan_function amendscan
Definition: amapi.h:313
amtranslate_strategy_function amtranslatestrategy
Definition: amapi.h:323
uint16 amoptsprocnum
Definition: amapi.h:244
amparallelrescan_function amparallelrescan
Definition: amapi.h:320
Oid amkeytype
Definition: amapi.h:286
bool amconsistentordering
Definition: amapi.h:254
bool ampredlocks
Definition: amapi.h:272
uint16 amsupport
Definition: amapi.h:242
amtranslate_cmptype_function amtranslatecmptype
Definition: amapi.h:324
amcostestimate_function amcostestimate
Definition: amapi.h:302
bool amcanorderbyop
Definition: amapi.h:248
amadjustmembers_function amadjustmembers
Definition: amapi.h:308
ambuild_function ambuild
Definition: amapi.h:295
bool amstorage
Definition: amapi.h:268
uint16 amstrategies
Definition: amapi.h:240
bool amoptionalkey
Definition: amapi.h:262
amgettuple_function amgettuple
Definition: amapi.h:311
amcanreturn_function amcanreturn
Definition: amapi.h:301
bool amcanunique
Definition: amapi.h:258
amgetbitmap_function amgetbitmap
Definition: amapi.h:312
amproperty_function amproperty
Definition: amapi.h:305
ambulkdelete_function ambulkdelete
Definition: amapi.h:299
bool amsearcharray
Definition: amapi.h:264
bool amsummarizing
Definition: amapi.h:282
amvalidate_function amvalidate
Definition: amapi.h:307
ammarkpos_function ammarkpos
Definition: amapi.h:314
bool amcanmulticol
Definition: amapi.h:260
bool amusemaintenanceworkmem
Definition: amapi.h:280
ambeginscan_function ambeginscan
Definition: amapi.h:309
bool amcanparallel
Definition: amapi.h:274
amrescan_function amrescan
Definition: amapi.h:310
bool amcanorder
Definition: amapi.h:246
bool amcanbuildparallel
Definition: amapi.h:276
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:319
uint8 amparallelvacuumoptions
Definition: amapi.h:284
aminsertcleanup_function aminsertcleanup
Definition: amapi.h:298
bool amcanbackward
Definition: amapi.h:256
amgettreeheight_function amgettreeheight
Definition: amapi.h:303
NodeTag type
Definition: amapi.h:234
bool amcaninclude
Definition: amapi.h:278
bool amsearchnulls
Definition: amapi.h:266
bool amconsistentequality
Definition: amapi.h:252
bool amcanhash
Definition: amapi.h:250
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
int number
Definition: amapi.h:92
Oid object
Definition: amapi.h:91
bool is_func
Definition: amapi.h:90
bool ref_is_hard
Definition: amapi.h:96
Oid sortfamily
Definition: amapi.h:95
Definition: c.h:692
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46