1 /*-------------------------------------------------------------------------
4 * API for Postgres index access methods.
6 * Copyright (c) 2015-2021, PostgreSQL Global Development Group
8 * src/include/access/amapi.h
10 *-------------------------------------------------------------------------
15 #include "access/genam.h"
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.
25 /* Likewise, this file shouldn't depend on execnodes.h. */
30 * Properties for amproperty API. This list covers properties known to the
31 * core code, but an index AM can define its own properties, by matching the
32 * string property name.
34 typedef enum IndexAMProperty
36 AMPROP_UNKNOWN
= 0, /* anything not known to core code */
37 AMPROP_ASC
, /* column properties */
42 AMPROP_DISTANCE_ORDERABLE
,
46 AMPROP_CLUSTERABLE
, /* index properties */
50 AMPROP_CAN_ORDER
, /* AM properties */
58 * We use lists of this struct type to keep track of both operators and
59 * support functions while building or adding to an opclass or opfamily.
60 * amadjustmembers functions receive lists of these structs, and are allowed
61 * to alter their "ref" fields.
63 * The "ref" fields define how the pg_amop or pg_amproc entry should depend
64 * on the associated objects (that is, which dependency type to use, and
65 * which opclass or opfamily it should depend on).
67 * If ref_is_hard is true, the entry will have a NORMAL dependency on the
68 * operator or support func, and an INTERNAL dependency on the opclass or
69 * opfamily. This forces the opclass or opfamily to be dropped if the
70 * operator or support func is dropped, and requires the CASCADE option
71 * to do so. Nor will ALTER OPERATOR FAMILY DROP be allowed. This is
72 * the right behavior for objects that are essential to an opclass.
74 * If ref_is_hard is false, the entry will have an AUTO dependency on the
75 * operator or support func, and also an AUTO dependency on the opclass or
76 * opfamily. This allows ALTER OPERATOR FAMILY DROP, and causes that to
77 * happen automatically if the operator or support func is dropped. This
78 * is the right behavior for inessential ("loose") objects.
80 typedef struct OpFamilyMember
82 bool is_func
; /* is this an operator, or support func? */
83 Oid object
; /* operator or support func's OID */
84 int number
; /* strategy or support func number */
85 Oid lefttype
; /* lefttype */
86 Oid righttype
; /* righttype */
87 Oid sortfamily
; /* ordering operator's sort opfamily, or 0 */
88 bool ref_is_hard
; /* hard or soft dependency? */
89 bool ref_is_family
; /* is dependency on opclass or opfamily? */
90 Oid refobjid
; /* OID of opclass or opfamily */
95 * Callback function signatures --- see indexam.sgml for more info.
99 typedef IndexBuildResult
*(*ambuild_function
) (Relation heapRelation
,
100 Relation indexRelation
,
101 struct IndexInfo
*indexInfo
);
103 /* build empty index */
104 typedef void (*ambuildempty_function
) (Relation indexRelation
);
106 /* insert this tuple */
107 typedef bool (*aminsert_function
) (Relation indexRelation
,
110 ItemPointer heap_tid
,
111 Relation heapRelation
,
112 IndexUniqueCheck checkUnique
,
114 struct IndexInfo
*indexInfo
);
117 typedef IndexBulkDeleteResult
*(*ambulkdelete_function
) (IndexVacuumInfo
*info
,
118 IndexBulkDeleteResult
*stats
,
119 IndexBulkDeleteCallback callback
,
120 void *callback_state
);
122 /* post-VACUUM cleanup */
123 typedef IndexBulkDeleteResult
*(*amvacuumcleanup_function
) (IndexVacuumInfo
*info
,
124 IndexBulkDeleteResult
*stats
);
126 /* can indexscan return IndexTuples? */
127 typedef bool (*amcanreturn_function
) (Relation indexRelation
, int attno
);
129 /* estimate cost of an indexscan */
130 typedef void (*amcostestimate_function
) (struct PlannerInfo
*root
,
131 struct IndexPath
*path
,
133 Cost
*indexStartupCost
,
134 Cost
*indexTotalCost
,
135 Selectivity
*indexSelectivity
,
136 double *indexCorrelation
,
139 /* parse index reloptions */
140 typedef bytea
*(*amoptions_function
) (Datum reloptions
,
143 /* report AM, index, or index column property */
144 typedef bool (*amproperty_function
) (Oid index_oid
, int attno
,
145 IndexAMProperty prop
, const char *propname
,
146 bool *res
, bool *isnull
);
148 /* name of phase as used in progress reporting */
149 typedef char *(*ambuildphasename_function
) (int64 phasenum
);
151 /* validate definition of an opclass for this AM */
152 typedef bool (*amvalidate_function
) (Oid opclassoid
);
154 /* validate operators and support functions to be added to an opclass/family */
155 typedef void (*amadjustmembers_function
) (Oid opfamilyoid
,
160 /* prepare for index scan */
161 typedef IndexScanDesc (*ambeginscan_function
) (Relation indexRelation
,
165 /* (re)start index scan */
166 typedef void (*amrescan_function
) (IndexScanDesc scan
,
172 /* next valid tuple */
173 typedef bool (*amgettuple_function
) (IndexScanDesc scan
,
174 ScanDirection direction
);
176 /* fetch all valid tuples */
177 typedef int64 (*amgetbitmap_function
) (IndexScanDesc scan
,
181 typedef void (*amendscan_function
) (IndexScanDesc scan
);
183 /* mark current scan position */
184 typedef void (*ammarkpos_function
) (IndexScanDesc scan
);
186 /* restore marked scan position */
187 typedef void (*amrestrpos_function
) (IndexScanDesc scan
);
190 * Callback function signatures - for parallel index scans.
193 /* estimate size of parallel scan descriptor */
194 typedef Size (*amestimateparallelscan_function
) (void);
196 /* prepare for parallel index scan */
197 typedef void (*aminitparallelscan_function
) (void *target
);
199 /* (re)start parallel index scan */
200 typedef void (*amparallelrescan_function
) (IndexScanDesc scan
);
203 * API struct for an index AM. Note this must be stored in a single palloc'd
206 typedef struct IndexAmRoutine
211 * Total number of strategies (operators) by which we can traverse/search
212 * this AM. Zero if AM does not have a fixed set of strategy assignments.
215 /* total number of support functions that this AM uses */
217 /* opclass options support function number or 0 */
218 uint16 amoptsprocnum
;
219 /* does AM support ORDER BY indexed column's value? */
221 /* does AM support ORDER BY result of an operator on indexed column? */
223 /* does AM support backward scanning? */
225 /* does AM support UNIQUE indexes? */
227 /* does AM support multi-column indexes? */
229 /* does AM require scans to have a constraint on the first index column? */
231 /* does AM handle ScalarArrayOpExpr quals? */
233 /* does AM handle IS NULL/IS NOT NULL quals? */
235 /* can index storage data type differ from column data type? */
237 /* can an index of this type be clustered on? */
239 /* does AM handle predicate locks? */
241 /* does AM support parallel scan? */
243 /* does AM support columns included with clause INCLUDE? */
245 /* does AM use maintenance_work_mem? */
246 bool amusemaintenanceworkmem
;
247 /* OR of parallel vacuum flags. See vacuum.h for flags. */
248 uint8 amparallelvacuumoptions
;
249 /* type of data stored in index, or InvalidOid if variable */
253 * If you add new properties to either the above or the below lists, then
254 * they should also (usually) be exposed via the property API (see
255 * IndexAMProperty at the top of the file, and utils/adt/amutils.c).
258 /* interface functions */
259 ambuild_function ambuild
;
260 ambuildempty_function ambuildempty
;
261 aminsert_function aminsert
;
262 ambulkdelete_function ambulkdelete
;
263 amvacuumcleanup_function amvacuumcleanup
;
264 amcanreturn_function amcanreturn
; /* can be NULL */
265 amcostestimate_function amcostestimate
;
266 amoptions_function amoptions
;
267 amproperty_function amproperty
; /* can be NULL */
268 ambuildphasename_function ambuildphasename
; /* can be NULL */
269 amvalidate_function amvalidate
;
270 amadjustmembers_function amadjustmembers
; /* can be NULL */
271 ambeginscan_function ambeginscan
;
272 amrescan_function amrescan
;
273 amgettuple_function amgettuple
; /* can be NULL */
274 amgetbitmap_function amgetbitmap
; /* can be NULL */
275 amendscan_function amendscan
;
276 ammarkpos_function ammarkpos
; /* can be NULL */
277 amrestrpos_function amrestrpos
; /* can be NULL */
279 /* interface functions to support parallel index scans */
280 amestimateparallelscan_function amestimateparallelscan
; /* can be NULL */
281 aminitparallelscan_function aminitparallelscan
; /* can be NULL */
282 amparallelrescan_function amparallelrescan
; /* can be NULL */
286 /* Functions in access/index/amapi.c */
287 extern IndexAmRoutine
*GetIndexAmRoutine(Oid amhandler
);
288 extern IndexAmRoutine
*GetIndexAmRoutineByAmId(Oid amoid
, bool noerror
);