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  IndexAmRoutine
 

Typedefs

typedef enum IndexAMProperty IndexAMProperty
 
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, 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 bool(* amvalidate_function) (Oid opclassoid)
 
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) (void)
 
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

◆ ambeginscan_function

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

Definition at line 115 of file amapi.h.

◆ ambuild_function

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

Definition at line 63 of file amapi.h.

◆ ambuildempty_function

typedef void(* ambuildempty_function) (Relation indexRelation)

Definition at line 68 of file amapi.h.

◆ ambulkdelete_function

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

Definition at line 80 of file amapi.h.

◆ amcanreturn_function

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

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

◆ amendscan_function

typedef void(* amendscan_function) (IndexScanDesc scan)

Definition at line 135 of file amapi.h.

◆ amestimateparallelscan_function

typedef Size(* amestimateparallelscan_function) (void)

Definition at line 148 of file amapi.h.

◆ amgetbitmap_function

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

Definition at line 131 of file amapi.h.

◆ amgettuple_function

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

Definition at line 127 of file amapi.h.

◆ aminitparallelscan_function

typedef void(* aminitparallelscan_function) (void *target)

Definition at line 151 of file amapi.h.

◆ aminsert_function

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

Definition at line 71 of file amapi.h.

◆ ammarkpos_function

typedef void(* ammarkpos_function) (IndexScanDesc scan)

Definition at line 138 of file amapi.h.

◆ amoptions_function

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

Definition at line 103 of file amapi.h.

◆ amparallelrescan_function

typedef void(* amparallelrescan_function) (IndexScanDesc scan)

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

◆ amrescan_function

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

Definition at line 120 of file amapi.h.

◆ amrestrpos_function

typedef void(* amrestrpos_function) (IndexScanDesc scan)

Definition at line 141 of file amapi.h.

◆ amvacuumcleanup_function

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

Definition at line 86 of file amapi.h.

◆ amvalidate_function

typedef bool(* amvalidate_function) (Oid opclassoid)

Definition at line 112 of file amapi.h.

◆ IndexAMProperty

◆ IndexAmRoutine

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.

Function Documentation

◆ GetIndexAmRoutine()

IndexAmRoutine* GetIndexAmRoutine ( Oid  amhandler)

Definition at line 33 of file amapi.c.

References DatumGetPointer, elog, ERROR, IsA, and OidFunctionCall0.

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

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 IsA(nodeptr, _type_)
Definition: nodes.h:568
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define OidFunctionCall0(functionId)
Definition: fmgr.h:626
#define DatumGetPointer(X)
Definition: postgres.h:534
#define elog
Definition: elog.h:219

◆ GetIndexAmRoutineByAmId()

IndexAmRoutine* GetIndexAmRoutineByAmId ( Oid  amoid,
bool  noerror 
)

Definition at line 56 of file amapi.c.

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

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

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 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:668
Definition: syscache.h:36
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
IndexAmRoutine * GetIndexAmRoutine(Oid amhandler)
Definition: amapi.c:33
#define RegProcedureIsValid(p)
Definition: c.h:607
#define ereport(elevel, rest)
Definition: elog.h:122
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
Oid regproc
Definition: c.h:471
FormData_pg_am * Form_pg_am
Definition: pg_am.h:46
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define NameStr(name)
Definition: c.h:576
#define elog
Definition: elog.h:219