PostgreSQL Source Code git master
amapi.h File Reference
#include "access/cmptype.h"
#include "access/genam.h"
#include "access/stratnum.h"
#include "nodes/nodes.h"
#include "nodes/pg_list.h"
Include dependency graph for amapi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  OpFamilyMember
 
struct  IndexAmRoutine
 

Typedefs

typedef struct PlannerInfo PlannerInfo
 
typedef struct IndexPath IndexPath
 
typedef struct IndexInfo IndexInfo
 
typedef enum IndexAMProperty IndexAMProperty
 
typedef struct OpFamilyMember OpFamilyMember
 
typedef CompareType(* amtranslate_strategy_function) (StrategyNumber strategy, Oid opfamily)
 
typedef StrategyNumber(* amtranslate_cmptype_function) (CompareType cmptype, Oid opfamily)
 
typedef IndexBuildResult *(* ambuild_function) (Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo)
 
typedef void(* ambuildempty_function) (Relation indexRelation)
 
typedef bool(* aminsert_function) (Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_tid, Relation heapRelation, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
 
typedef void(* aminsertcleanup_function) (Relation indexRelation, IndexInfo *indexInfo)
 
typedef IndexBulkDeleteResult *(* ambulkdelete_function) (IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
 
typedef IndexBulkDeleteResult *(* amvacuumcleanup_function) (IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
 
typedef bool(* amcanreturn_function) (Relation indexRelation, int attno)
 
typedef void(* amcostestimate_function) (PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
 
typedef int(* amgettreeheight_function) (Relation rel)
 
typedef bytea *(* amoptions_function) (Datum reloptions, bool validate)
 
typedef bool(* amproperty_function) (Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
 
typedef char *(* ambuildphasename_function) (int64 phasenum)
 
typedef bool(* amvalidate_function) (Oid opclassoid)
 
typedef void(* amadjustmembers_function) (Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
 
typedef IndexScanDesc(* ambeginscan_function) (Relation indexRelation, int nkeys, int norderbys)
 
typedef void(* amrescan_function) (IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
 
typedef bool(* amgettuple_function) (IndexScanDesc scan, ScanDirection direction)
 
typedef int64(* amgetbitmap_function) (IndexScanDesc scan, TIDBitmap *tbm)
 
typedef void(* amendscan_function) (IndexScanDesc scan)
 
typedef void(* ammarkpos_function) (IndexScanDesc scan)
 
typedef void(* amrestrpos_function) (IndexScanDesc scan)
 
typedef Size(* amestimateparallelscan_function) (Relation indexRelation, int nkeys, int norderbys)
 
typedef void(* aminitparallelscan_function) (void *target)
 
typedef void(* amparallelrescan_function) (IndexScanDesc scan)
 
typedef struct IndexAmRoutine IndexAmRoutine
 

Enumerations

enum  IndexAMProperty {
  AMPROP_UNKNOWN = 0 , AMPROP_ASC , AMPROP_DESC , AMPROP_NULLS_FIRST ,
  AMPROP_NULLS_LAST , AMPROP_ORDERABLE , AMPROP_DISTANCE_ORDERABLE , AMPROP_RETURNABLE ,
  AMPROP_SEARCH_ARRAY , AMPROP_SEARCH_NULLS , AMPROP_CLUSTERABLE , AMPROP_INDEX_SCAN ,
  AMPROP_BITMAP_SCAN , AMPROP_BACKWARD_SCAN , AMPROP_CAN_ORDER , AMPROP_CAN_UNIQUE ,
  AMPROP_CAN_MULTI_COL , AMPROP_CAN_EXCLUDE , AMPROP_CAN_INCLUDE
}
 

Functions

IndexAmRoutineGetIndexAmRoutine (Oid amhandler)
 
IndexAmRoutineGetIndexAmRoutineByAmId (Oid amoid, bool noerror)
 
CompareType IndexAmTranslateStrategy (StrategyNumber strategy, Oid amoid, Oid opfamily, bool missing_ok)
 
StrategyNumber IndexAmTranslateCompareType (CompareType cmptype, Oid amoid, Oid opfamily, bool missing_ok)
 

Typedef Documentation

◆ amadjustmembers_function

typedef void(* amadjustmembers_function) (Oid opfamilyoid, Oid opclassoid, List *operators,List *functions)

Definition at line 180 of file amapi.h.

◆ ambeginscan_function

typedef IndexScanDesc(* ambeginscan_function) (Relation indexRelation, int nkeys, int norderbys)

Definition at line 186 of file amapi.h.

◆ ambuild_function

typedef IndexBuildResult *(* ambuild_function) (Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo)

Definition at line 113 of file amapi.h.

◆ ambuildempty_function

typedef void(* ambuildempty_function) (Relation indexRelation)

Definition at line 118 of file amapi.h.

◆ ambuildphasename_function

typedef char *(* ambuildphasename_function) (int64 phasenum)

Definition at line 174 of file amapi.h.

◆ ambulkdelete_function

typedef IndexBulkDeleteResult *(* ambulkdelete_function) (IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)

Definition at line 135 of file amapi.h.

◆ amcanreturn_function

typedef bool(* amcanreturn_function) (Relation indexRelation, int attno)

Definition at line 145 of file amapi.h.

◆ amcostestimate_function

typedef void(* amcostestimate_function) (PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)

Definition at line 148 of file amapi.h.

◆ amendscan_function

typedef void(* amendscan_function) (IndexScanDesc scan)

Definition at line 206 of file amapi.h.

◆ amestimateparallelscan_function

typedef Size(* amestimateparallelscan_function) (Relation indexRelation, int nkeys, int norderbys)

Definition at line 219 of file amapi.h.

◆ amgetbitmap_function

typedef int64(* amgetbitmap_function) (IndexScanDesc scan, TIDBitmap *tbm)

Definition at line 202 of file amapi.h.

◆ amgettreeheight_function

typedef int(* amgettreeheight_function) (Relation rel)

Definition at line 162 of file amapi.h.

◆ amgettuple_function

typedef bool(* amgettuple_function) (IndexScanDesc scan, ScanDirection direction)

Definition at line 198 of file amapi.h.

◆ aminitparallelscan_function

typedef void(* aminitparallelscan_function) (void *target)

Definition at line 223 of file amapi.h.

◆ aminsert_function

typedef bool(* aminsert_function) (Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_tid, Relation heapRelation, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)

Definition at line 121 of file amapi.h.

◆ aminsertcleanup_function

typedef void(* aminsertcleanup_function) (Relation indexRelation, IndexInfo *indexInfo)

Definition at line 131 of file amapi.h.

◆ ammarkpos_function

typedef void(* ammarkpos_function) (IndexScanDesc scan)

Definition at line 209 of file amapi.h.

◆ amoptions_function

typedef bytea *(* amoptions_function) (Datum reloptions, bool validate)

Definition at line 165 of file amapi.h.

◆ amparallelrescan_function

typedef void(* amparallelrescan_function) (IndexScanDesc scan)

Definition at line 226 of file amapi.h.

◆ amproperty_function

typedef bool(* amproperty_function) (Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)

Definition at line 169 of file amapi.h.

◆ amrescan_function

typedef void(* amrescan_function) (IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)

Definition at line 191 of file amapi.h.

◆ amrestrpos_function

typedef void(* amrestrpos_function) (IndexScanDesc scan)

Definition at line 212 of file amapi.h.

◆ amtranslate_cmptype_function

typedef StrategyNumber(* amtranslate_cmptype_function) (CompareType cmptype, Oid opfamily)

Definition at line 110 of file amapi.h.

◆ amtranslate_strategy_function

typedef CompareType(* amtranslate_strategy_function) (StrategyNumber strategy, Oid opfamily)

Definition at line 107 of file amapi.h.

◆ amvacuumcleanup_function

typedef IndexBulkDeleteResult *(* amvacuumcleanup_function) (IndexVacuumInfo *info, IndexBulkDeleteResult *stats)

Definition at line 141 of file amapi.h.

◆ amvalidate_function

typedef bool(* amvalidate_function) (Oid opclassoid)

Definition at line 177 of file amapi.h.

◆ IndexAMProperty

◆ IndexAmRoutine

◆ IndexInfo

typedef struct IndexInfo IndexInfo

Definition at line 30 of file amapi.h.

◆ IndexPath

typedef struct IndexPath IndexPath

Definition at line 27 of file amapi.h.

◆ OpFamilyMember

◆ PlannerInfo

typedef struct PlannerInfo PlannerInfo

Definition at line 26 of file amapi.h.

Enumeration Type Documentation

◆ IndexAMProperty

Enumerator
AMPROP_UNKNOWN 
AMPROP_ASC 
AMPROP_DESC 
AMPROP_NULLS_FIRST 
AMPROP_NULLS_LAST 
AMPROP_ORDERABLE 
AMPROP_DISTANCE_ORDERABLE 
AMPROP_RETURNABLE 
AMPROP_SEARCH_ARRAY 
AMPROP_SEARCH_NULLS 
AMPROP_CLUSTERABLE 
AMPROP_INDEX_SCAN 
AMPROP_BITMAP_SCAN 
AMPROP_BACKWARD_SCAN 
AMPROP_CAN_ORDER 
AMPROP_CAN_UNIQUE 
AMPROP_CAN_MULTI_COL 
AMPROP_CAN_EXCLUDE 
AMPROP_CAN_INCLUDE 

Definition at line 38 of file amapi.h.

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 */
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

Function Documentation

◆ GetIndexAmRoutine()

IndexAmRoutine * GetIndexAmRoutine ( Oid  amhandler)

Definition at line 33 of file amapi.c.

34{
35 Datum datum;
36 IndexAmRoutine *routine;
37
38 datum = OidFunctionCall0(amhandler);
39 routine = (IndexAmRoutine *) DatumGetPointer(datum);
40
41 if (routine == NULL || !IsA(routine, IndexAmRoutine))
42 elog(ERROR, "index access method handler function %u did not return an IndexAmRoutine struct",
43 amhandler);
44
45 /* Assert that all required callbacks are present. */
46 Assert(routine->ambuild != NULL);
47 Assert(routine->ambuildempty != NULL);
48 Assert(routine->aminsert != NULL);
49 Assert(routine->ambulkdelete != NULL);
50 Assert(routine->amvacuumcleanup != NULL);
51 Assert(routine->amcostestimate != NULL);
52 Assert(routine->amoptions != NULL);
53 Assert(routine->amvalidate != NULL);
54 Assert(routine->ambeginscan != NULL);
55 Assert(routine->amrescan != NULL);
56 Assert(routine->amendscan != NULL);
57
58 return routine;
59}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define OidFunctionCall0(functionId)
Definition: fmgr.h:718
Assert(PointerIsAligned(start, uint64))
#define IsA(nodeptr, _type_)
Definition: nodes.h:164
uint64_t Datum
Definition: postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:322
ambuildempty_function ambuildempty
Definition: amapi.h:296
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:300
amoptions_function amoptions
Definition: amapi.h:304
aminsert_function aminsert
Definition: amapi.h:297
amendscan_function amendscan
Definition: amapi.h:313
amcostestimate_function amcostestimate
Definition: amapi.h:302
ambuild_function ambuild
Definition: amapi.h:295
ambulkdelete_function ambulkdelete
Definition: amapi.h:299
amvalidate_function amvalidate
Definition: amapi.h:307
ambeginscan_function ambeginscan
Definition: amapi.h:309
amrescan_function amrescan
Definition: amapi.h:310

References IndexAmRoutine::ambeginscan, IndexAmRoutine::ambuild, IndexAmRoutine::ambuildempty, IndexAmRoutine::ambulkdelete, IndexAmRoutine::amcostestimate, IndexAmRoutine::amendscan, IndexAmRoutine::aminsert, IndexAmRoutine::amoptions, IndexAmRoutine::amrescan, IndexAmRoutine::amvacuumcleanup, IndexAmRoutine::amvalidate, Assert(), DatumGetPointer(), elog, ERROR, IsA, and OidFunctionCall0.

Referenced by CheckIndexCompatible(), DefineIndex(), GetIndexAmRoutineByAmId(), InitIndexAmRoutine(), and pg_get_indexdef_worker().

◆ GetIndexAmRoutineByAmId()

IndexAmRoutine * GetIndexAmRoutineByAmId ( Oid  amoid,
bool  noerror 
)

Definition at line 69 of file amapi.c.

70{
71 HeapTuple tuple;
72 Form_pg_am amform;
73 regproc amhandler;
74
75 /* Get handler function OID for the access method */
76 tuple = SearchSysCache1(AMOID, ObjectIdGetDatum(amoid));
77 if (!HeapTupleIsValid(tuple))
78 {
79 if (noerror)
80 return NULL;
81 elog(ERROR, "cache lookup failed for access method %u",
82 amoid);
83 }
84 amform = (Form_pg_am) GETSTRUCT(tuple);
85
86 /* Check if it's an index access method as opposed to some other AM */
87 if (amform->amtype != AMTYPE_INDEX)
88 {
89 if (noerror)
90 {
91 ReleaseSysCache(tuple);
92 return NULL;
93 }
95 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
96 errmsg("access method \"%s\" is not of type %s",
97 NameStr(amform->amname), "INDEX")));
98 }
99
100 amhandler = amform->amhandler;
101
102 /* Complain if handler OID is invalid */
103 if (!RegProcedureIsValid(amhandler))
104 {
105 if (noerror)
106 {
107 ReleaseSysCache(tuple);
108 return NULL;
109 }
111 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
112 errmsg("index access method \"%s\" does not have a handler",
113 NameStr(amform->amname))));
114 }
115
116 ReleaseSysCache(tuple);
117
118 /* And finally, call the handler function to get the API struct. */
119 return GetIndexAmRoutine(amhandler);
120}
IndexAmRoutine * GetIndexAmRoutine(Oid amhandler)
Definition: amapi.c:33
#define NameStr(name)
Definition: c.h:756
#define RegProcedureIsValid(p)
Definition: c.h:781
Oid regproc
Definition: c.h:659
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ereport(elevel,...)
Definition: elog.h:150
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:220

References elog, ereport, errcode(), errmsg(), ERROR, GetIndexAmRoutine(), GETSTRUCT(), HeapTupleIsValid, NameStr, ObjectIdGetDatum(), RegProcedureIsValid, ReleaseSysCache(), and SearchSysCache1().

Referenced by AlterOpFamily(), AlterOpFamilyAdd(), amvalidate(), assignOperTypes(), assignProcTypes(), comparison_ops_are_compatible(), ConstructTupleDescriptor(), DefineOpClass(), equality_ops_are_compatible(), get_op_index_interpretation(), get_opmethod_canorder(), indexam_property(), IndexAmTranslateCompareType(), IndexAmTranslateStrategy(), IndexSupportsBackwardScan(), IsIndexUsableForReplicaIdentityFull(), and pg_indexam_progress_phasename().

◆ IndexAmTranslateCompareType()

StrategyNumber IndexAmTranslateCompareType ( CompareType  cmptype,
Oid  amoid,
Oid  opfamily,
bool  missing_ok 
)

Definition at line 161 of file amapi.c.

162{
163 StrategyNumber result;
164 IndexAmRoutine *amroutine;
165
166 /* shortcut for common case */
167 if (amoid == BTREE_AM_OID &&
168 (cmptype > COMPARE_INVALID && cmptype <= COMPARE_GT))
169 return (StrategyNumber) cmptype;
170
171 amroutine = GetIndexAmRoutineByAmId(amoid, false);
172 if (amroutine->amtranslatecmptype)
173 result = amroutine->amtranslatecmptype(cmptype, opfamily);
174 else
175 result = InvalidStrategy;
176
177 if (!missing_ok && result == InvalidStrategy)
178 elog(ERROR, "could not translate compare type %u for index AM %u", cmptype, amoid);
179
180 return result;
181}
IndexAmRoutine * GetIndexAmRoutineByAmId(Oid amoid, bool noerror)
Definition: amapi.c:69
@ COMPARE_INVALID
Definition: cmptype.h:33
@ COMPARE_GT
Definition: cmptype.h:38
uint16 StrategyNumber
Definition: stratnum.h:22
#define InvalidStrategy
Definition: stratnum.h:24
amtranslate_cmptype_function amtranslatecmptype
Definition: amapi.h:324

References IndexAmRoutine::amtranslatecmptype, COMPARE_GT, COMPARE_INVALID, elog, ERROR, GetIndexAmRoutineByAmId(), and InvalidStrategy.

Referenced by ATAddForeignKeyConstraint(), build_replindex_scan_key(), BuildSpeculativeIndexInfo(), get_opfamily_member_for_cmptype(), GetOperatorFromCompareType(), IsIndexUsableForReplicaIdentityFull(), and mergejoinscansel().

◆ IndexAmTranslateStrategy()

CompareType IndexAmTranslateStrategy ( StrategyNumber  strategy,
Oid  amoid,
Oid  opfamily,
bool  missing_ok 
)

Definition at line 131 of file amapi.c.

132{
133 CompareType result;
134 IndexAmRoutine *amroutine;
135
136 /* shortcut for common case */
137 if (amoid == BTREE_AM_OID &&
138 (strategy > InvalidStrategy && strategy <= BTMaxStrategyNumber))
139 return (CompareType) strategy;
140
141 amroutine = GetIndexAmRoutineByAmId(amoid, false);
142 if (amroutine->amtranslatestrategy)
143 result = amroutine->amtranslatestrategy(strategy, opfamily);
144 else
145 result = COMPARE_INVALID;
146
147 if (!missing_ok && result == COMPARE_INVALID)
148 elog(ERROR, "could not translate strategy number %d for index AM %u", strategy, amoid);
149
150 return result;
151}
CompareType
Definition: cmptype.h:32
#define BTMaxStrategyNumber
Definition: stratnum.h:35
amtranslate_strategy_function amtranslatestrategy
Definition: amapi.h:323

References IndexAmRoutine::amtranslatestrategy, BTMaxStrategyNumber, COMPARE_INVALID, elog, ERROR, GetIndexAmRoutineByAmId(), and InvalidStrategy.

Referenced by get_actual_variable_range(), get_mergejoin_opfamilies(), get_op_index_interpretation(), get_ordering_op_for_equality_op(), get_ordering_op_properties(), mergejoinscansel(), and MJExamineQuals().