1/*-------------------------------------------------------------------------
4 * API for Postgres index access methods.
6 * Copyright (c) 2015-2025, PostgreSQL Global Development Group
8 * src/include/access/amapi.h
10 *-------------------------------------------------------------------------
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.
29/* Likewise, this file shouldn't depend on execnodes.h. */
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.
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.
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).
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.
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.
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.
90 bool is_func;
/* is this an operator, or support func? */
92 int number;
/* strategy or support func number */
103 * Callback function signatures --- see indexam.sgml for more info.
106/* translate AM-specific strategies to general operator types */
109/* translate general operator types to AM-specific strategies */
117/* build empty index */
120/* insert this tuple */
130/* cleanup after insert */
138 void *callback_state);
140/* post-VACUUM cleanup */
144/* can indexscan return IndexTuples? */
147/* estimate cost of an indexscan */
151 Cost *indexStartupCost,
152 Cost *indexTotalCost,
154 double *indexCorrelation,
157/* estimate height of a tree-structured index
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.
164/* parse index reloptions */
168/* report AM, index, or index column property */
171 bool *res,
bool *isnull);
173/* name of phase as used in progress reporting */
174 typedef char *(*ambuildphasename_function) (
int64 phasenum);
176/* validate definition of an opclass for this AM */
179/* validate operators and support functions to be added to an opclass/family */
185/* prepare for index scan */
190/* (re)start index scan */
197/* next valid tuple */
201/* fetch all valid tuples */
208/* mark current scan position */
211/* restore marked scan position */
215 * Callback function signatures - for parallel index scans.
218/* estimate size of parallel scan descriptor */
220 int nkeys,
int norderbys);
222/* prepare for parallel index scan */
225/* (re)start parallel index scan */
229 * API struct for an index AM. Note this must be stored in a single palloc'd
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.
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 */
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).
294 /* interface functions */
317 /* interface functions to support parallel index scans */
322 /* interface functions to support planning */
328/* Functions in access/index/amapi.c */
IndexAmRoutine * GetIndexAmRoutine(Oid amhandler)
void(* amparallelrescan_function)(IndexScanDesc scan)
CompareType(* amtranslate_strategy_function)(StrategyNumber strategy, Oid opfamily)
IndexScanDesc(* ambeginscan_function)(Relation indexRelation, int nkeys, int norderbys)
void(* amadjustmembers_function)(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
int(* amgettreeheight_function)(Relation rel)
bool(* amproperty_function)(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
bool(* amvalidate_function)(Oid opclassoid)
void(* amendscan_function)(IndexScanDesc scan)
IndexBulkDeleteResult *(* ambulkdelete_function)(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
bool(* amcanreturn_function)(Relation indexRelation, int attno)
bytea *(* amoptions_function)(Datum reloptions, bool validate)
IndexBuildResult *(* ambuild_function)(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo)
void(* ambuildempty_function)(Relation indexRelation)
StrategyNumber(* amtranslate_cmptype_function)(CompareType cmptype, Oid opfamily)
int64(* amgetbitmap_function)(IndexScanDesc scan, TIDBitmap *tbm)
void(* amrestrpos_function)(IndexScanDesc scan)
char *(* ambuildphasename_function)(int64 phasenum)
IndexBulkDeleteResult *(* amvacuumcleanup_function)(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
bool(* amgettuple_function)(IndexScanDesc scan, ScanDirection direction)
StrategyNumber IndexAmTranslateCompareType(CompareType cmptype, Oid amoid, Oid opfamily, bool missing_ok)
@ AMPROP_DISTANCE_ORDERABLE
void(* amcostestimate_function)(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Size(* amestimateparallelscan_function)(Relation indexRelation, int nkeys, int norderbys)
void(* aminsertcleanup_function)(Relation indexRelation, IndexInfo *indexInfo)
void(* aminitparallelscan_function)(void *target)
void(* ammarkpos_function)(IndexScanDesc scan)
struct OpFamilyMember OpFamilyMember
CompareType IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, bool missing_ok)
IndexAmRoutine * GetIndexAmRoutineByAmId(Oid amoid, bool noerror)
struct IndexAmRoutine IndexAmRoutine
bool(* aminsert_function)(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_tid, Relation heapRelation, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
void(* amrescan_function)(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
static bool validate(Port *port, const char *auth)
static Datum values[MAXATTR]
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
struct IndexScanDescData * IndexScanDesc
static const struct fns functions
ambuildphasename_function ambuildphasename
ambuildempty_function ambuildempty
amvacuumcleanup_function amvacuumcleanup
amoptions_function amoptions
amestimateparallelscan_function amestimateparallelscan
amrestrpos_function amrestrpos
aminsert_function aminsert
amendscan_function amendscan
amtranslate_strategy_function amtranslatestrategy
amparallelrescan_function amparallelrescan
bool amconsistentordering
amtranslate_cmptype_function amtranslatecmptype
amcostestimate_function amcostestimate
amadjustmembers_function amadjustmembers
amgettuple_function amgettuple
amcanreturn_function amcanreturn
amgetbitmap_function amgetbitmap
amproperty_function amproperty
ambulkdelete_function ambulkdelete
amvalidate_function amvalidate
ammarkpos_function ammarkpos
bool amusemaintenanceworkmem
ambeginscan_function ambeginscan
amrescan_function amrescan
aminitparallelscan_function aminitparallelscan
uint8 amparallelvacuumoptions
aminsertcleanup_function aminsertcleanup
amgettreeheight_function amgettreeheight
bool amconsistentequality
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)