PostgreSQL Source Code  git master
amapi.h File Reference
#include "access/genam.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 enum IndexAMProperty IndexAMProperty
 
typedef struct OpFamilyMember OpFamilyMember
 
typedef IndexBuildResult *(* ambuild_function) (Relation heapRelation, Relation indexRelation, struct 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, struct IndexInfo *indexInfo)
 
typedef void(* aminsertcleanup_function) (Relation indexRelation, struct 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) (struct PlannerInfo *root, struct IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
 
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) (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)
 

Typedef Documentation

◆ amadjustmembers_function

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

Definition at line 159 of file amapi.h.

◆ ambeginscan_function

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

Definition at line 165 of file amapi.h.

◆ ambuild_function

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

Definition at line 99 of file amapi.h.

◆ ambuildempty_function

typedef void(* ambuildempty_function) (Relation indexRelation)

Definition at line 104 of file amapi.h.

◆ ambuildphasename_function

typedef char*(* ambuildphasename_function) (int64 phasenum)

Definition at line 153 of file amapi.h.

◆ ambulkdelete_function

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

Definition at line 121 of file amapi.h.

◆ amcanreturn_function

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

Definition at line 131 of file amapi.h.

◆ amcostestimate_function

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

Definition at line 134 of file amapi.h.

◆ amendscan_function

typedef void(* amendscan_function) (IndexScanDesc scan)

Definition at line 185 of file amapi.h.

◆ amestimateparallelscan_function

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

Definition at line 198 of file amapi.h.

◆ amgetbitmap_function

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

Definition at line 181 of file amapi.h.

◆ amgettuple_function

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

Definition at line 177 of file amapi.h.

◆ aminitparallelscan_function

typedef void(* aminitparallelscan_function) (void *target)

Definition at line 201 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, struct IndexInfo *indexInfo)

Definition at line 107 of file amapi.h.

◆ aminsertcleanup_function

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

Definition at line 117 of file amapi.h.

◆ ammarkpos_function

typedef void(* ammarkpos_function) (IndexScanDesc scan)

Definition at line 188 of file amapi.h.

◆ amoptions_function

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

Definition at line 144 of file amapi.h.

◆ amparallelrescan_function

typedef void(* amparallelrescan_function) (IndexScanDesc scan)

Definition at line 204 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 148 of file amapi.h.

◆ amrescan_function

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

Definition at line 170 of file amapi.h.

◆ amrestrpos_function

typedef void(* amrestrpos_function) (IndexScanDesc scan)

Definition at line 191 of file amapi.h.

◆ amvacuumcleanup_function

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

Definition at line 127 of file amapi.h.

◆ amvalidate_function

typedef bool(* amvalidate_function) (Oid opclassoid)

Definition at line 156 of file amapi.h.

◆ IndexAMProperty

◆ IndexAmRoutine

◆ OpFamilyMember

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 34 of file amapi.h.

35 {
36  AMPROP_UNKNOWN = 0, /* anything not known to core code */
37  AMPROP_ASC, /* column properties */
46  AMPROP_CLUSTERABLE, /* index properties */
50  AMPROP_CAN_ORDER, /* AM properties */
IndexAMProperty
Definition: amapi.h:35
@ AMPROP_BACKWARD_SCAN
Definition: amapi.h:49
@ AMPROP_SEARCH_ARRAY
Definition: amapi.h:44
@ AMPROP_CAN_MULTI_COL
Definition: amapi.h:52
@ AMPROP_CAN_ORDER
Definition: amapi.h:50
@ AMPROP_ORDERABLE
Definition: amapi.h:41
@ AMPROP_ASC
Definition: amapi.h:37
@ AMPROP_DISTANCE_ORDERABLE
Definition: amapi.h:42
@ AMPROP_CAN_INCLUDE
Definition: amapi.h:54
@ AMPROP_SEARCH_NULLS
Definition: amapi.h:45
@ AMPROP_CAN_EXCLUDE
Definition: amapi.h:53
@ AMPROP_UNKNOWN
Definition: amapi.h:36
@ AMPROP_CAN_UNIQUE
Definition: amapi.h:51
@ AMPROP_DESC
Definition: amapi.h:38
@ AMPROP_NULLS_LAST
Definition: amapi.h:40
@ AMPROP_INDEX_SCAN
Definition: amapi.h:47
@ AMPROP_NULLS_FIRST
Definition: amapi.h:39
@ AMPROP_CLUSTERABLE
Definition: amapi.h:46
@ AMPROP_RETURNABLE
Definition: amapi.h:43
@ AMPROP_BITMAP_SCAN
Definition: amapi.h:48

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  return routine;
46 }
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define OidFunctionCall0(functionId)
Definition: fmgr.h:678
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312

References 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 56 of file amapi.c.

57 {
58  HeapTuple tuple;
59  Form_pg_am amform;
60  regproc amhandler;
61 
62  /* Get handler function OID for the access method */
63  tuple = SearchSysCache1(AMOID, ObjectIdGetDatum(amoid));
64  if (!HeapTupleIsValid(tuple))
65  {
66  if (noerror)
67  return NULL;
68  elog(ERROR, "cache lookup failed for access method %u",
69  amoid);
70  }
71  amform = (Form_pg_am) GETSTRUCT(tuple);
72 
73  /* Check if it's an index access method as opposed to some other AM */
74  if (amform->amtype != AMTYPE_INDEX)
75  {
76  if (noerror)
77  {
78  ReleaseSysCache(tuple);
79  return NULL;
80  }
81  ereport(ERROR,
82  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
83  errmsg("access method \"%s\" is not of type %s",
84  NameStr(amform->amname), "INDEX")));
85  }
86 
87  amhandler = amform->amhandler;
88 
89  /* Complain if handler OID is invalid */
90  if (!RegProcedureIsValid(amhandler))
91  {
92  if (noerror)
93  {
94  ReleaseSysCache(tuple);
95  return NULL;
96  }
97  ereport(ERROR,
98  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
99  errmsg("index access method \"%s\" does not have a handler",
100  NameStr(amform->amname))));
101  }
102 
103  ReleaseSysCache(tuple);
104 
105  /* And finally, call the handler function to get the API struct. */
106  return GetIndexAmRoutine(amhandler);
107 }
IndexAmRoutine * GetIndexAmRoutine(Oid amhandler)
Definition: amapi.c:33
#define NameStr(name)
Definition: c.h:746
#define RegProcedureIsValid(p)
Definition: c.h:777
Oid regproc
Definition: c.h:649
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ereport(elevel,...)
Definition: elog.h:149
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:266
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:218

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

Referenced by AlterOpFamily(), AlterOpFamilyAdd(), amvalidate(), assignOperTypes(), ConstructTupleDescriptor(), DefineOpClass(), indexam_property(), IndexSupportsBackwardScan(), IsIndexUsableForReplicaIdentityFull(), and pg_indexam_progress_phasename().