amapi.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*-------------------------------------------------------------------------
  2. *
  3. * amapi.h
  4. * API for Postgres index access methods.
  5. *
  6. * Copyright (c) 2015-2016, PostgreSQL Global Development Group
  7. *
  8. * src/include/access/amapi.h
  9. *
  10. *-------------------------------------------------------------------------
  11. */
  12. #ifndef AMAPI_H
  13. #define AMAPI_H
  14. #include "access/genam.h"
  15. /*
  16. * We don't wish to include planner header files here, since most of an index
  17. * AM's implementation isn't concerned with those data structures. To allow
  18. * declaring amcostestimate_function here, use forward struct references.
  19. */
  20. struct PlannerInfo;
  21. struct IndexPath;
  22. /* Likewise, this file shouldn't depend on execnodes.h. */
  23. struct IndexInfo;
  24. /*
  25. * Properties for amproperty API. This list covers properties known to the
  26. * core code, but an index AM can define its own properties, by matching the
  27. * string property name.
  28. */
  29. typedef enum IndexAMProperty
  30. {
  31. AMPROP_UNKNOWN = 0, /* anything not known to core code */
  32. AMPROP_ASC, /* column properties */
  33. AMPROP_DESC,
  34. AMPROP_NULLS_FIRST,
  35. AMPROP_NULLS_LAST,
  36. AMPROP_ORDERABLE,
  37. AMPROP_DISTANCE_ORDERABLE,
  38. AMPROP_RETURNABLE,
  39. AMPROP_SEARCH_ARRAY,
  40. AMPROP_SEARCH_NULLS,
  41. AMPROP_CLUSTERABLE, /* index properties */
  42. AMPROP_INDEX_SCAN,
  43. AMPROP_BITMAP_SCAN,
  44. AMPROP_BACKWARD_SCAN,
  45. AMPROP_CAN_ORDER, /* AM properties */
  46. AMPROP_CAN_UNIQUE,
  47. AMPROP_CAN_MULTI_COL,
  48. AMPROP_CAN_EXCLUDE
  49. } IndexAMProperty;
  50. /*
  51. * Callback function signatures --- see indexam.sgml for more info.
  52. */
  53. /* build new index */
  54. typedef IndexBuildResult *(*ambuild_function) (Relation heapRelation,
  55. Relation indexRelation,
  56. struct IndexInfo *indexInfo);
  57. /* build empty index */
  58. typedef void (*ambuildempty_function) (Relation indexRelation);
  59. /* insert this tuple */
  60. typedef bool (*aminsert_function) (Relation indexRelation,
  61. Datum *values,
  62. bool *isnull,
  63. ItemPointer heap_tid,
  64. Relation heapRelation,
  65. IndexUniqueCheck checkUnique);
  66. /* bulk delete */
  67. typedef IndexBulkDeleteResult *(*ambulkdelete_function) (IndexVacuumInfo *info,
  68. IndexBulkDeleteResult *stats,
  69. IndexBulkDeleteCallback callback,
  70. void *callback_state);
  71. /* post-VACUUM cleanup */
  72. typedef IndexBulkDeleteResult *(*amvacuumcleanup_function) (IndexVacuumInfo *info,
  73. IndexBulkDeleteResult *stats);
  74. /* can indexscan return IndexTuples? */
  75. typedef bool (*amcanreturn_function) (Relation indexRelation, int attno);
  76. /* estimate cost of an indexscan */
  77. typedef void (*amcostestimate_function) (struct PlannerInfo *root,
  78. struct IndexPath *path,
  79. double loop_count,
  80. Cost *indexStartupCost,
  81. Cost *indexTotalCost,
  82. Selectivity *indexSelectivity,
  83. double *indexCorrelation);
  84. /* parse index reloptions */
  85. typedef bytea *(*amoptions_function) (Datum reloptions,
  86. bool validate);
  87. /* report AM, index, or index column property */
  88. typedef bool (*amproperty_function) (Oid index_oid, int attno,
  89. IndexAMProperty prop, const char *propname,
  90. bool *res, bool *isnull);
  91. /* validate definition of an opclass for this AM */
  92. typedef bool (*amvalidate_function) (Oid opclassoid);
  93. /* prepare for index scan */
  94. typedef IndexScanDesc (*ambeginscan_function) (Relation indexRelation,
  95. int nkeys,
  96. int norderbys);
  97. /* (re)start index scan */
  98. typedef void (*amrescan_function) (IndexScanDesc scan,
  99. ScanKey keys,
  100. int nkeys,
  101. ScanKey orderbys,
  102. int norderbys);
  103. /* next valid tuple */
  104. typedef bool (*amgettuple_function) (IndexScanDesc scan,
  105. ScanDirection direction);
  106. /* fetch all valid tuples */
  107. typedef int64 (*amgetbitmap_function) (IndexScanDesc scan,
  108. TIDBitmap *tbm);
  109. /* end index scan */
  110. typedef void (*amendscan_function) (IndexScanDesc scan);
  111. /* mark current scan position */
  112. typedef void (*ammarkpos_function) (IndexScanDesc scan);
  113. /* restore marked scan position */
  114. typedef void (*amrestrpos_function) (IndexScanDesc scan);
  115. /*
  116. * API struct for an index AM. Note this must be stored in a single palloc'd
  117. * chunk of memory.
  118. */
  119. typedef struct IndexAmRoutine
  120. {
  121. NodeTag type;
  122. /*
  123. * Total number of strategies (operators) by which we can traverse/search
  124. * this AM. Zero if AM does not have a fixed set of strategy assignments.
  125. */
  126. uint16 amstrategies;
  127. /* total number of support functions that this AM uses */
  128. uint16 amsupport;
  129. /* does AM support ORDER BY indexed column's value? */
  130. bool amcanorder;
  131. /* does AM support ORDER BY result of an operator on indexed column? */
  132. bool amcanorderbyop;
  133. /* does AM support backward scanning? */
  134. bool amcanbackward;
  135. /* does AM support UNIQUE indexes? */
  136. bool amcanunique;
  137. /* does AM support multi-column indexes? */
  138. bool amcanmulticol;
  139. /* does AM require scans to have a constraint on the first index column? */
  140. bool amoptionalkey;
  141. /* does AM handle ScalarArrayOpExpr quals? */
  142. bool amsearcharray;
  143. /* does AM handle IS NULL/IS NOT NULL quals? */
  144. bool amsearchnulls;
  145. /* can index storage data type differ from column data type? */
  146. bool amstorage;
  147. /* can an index of this type be clustered on? */
  148. bool amclusterable;
  149. /* does AM handle predicate locks? */
  150. bool ampredlocks;
  151. /* type of data stored in index, or InvalidOid if variable */
  152. Oid amkeytype;
  153. /* interface functions */
  154. ambuild_function ambuild;
  155. ambuildempty_function ambuildempty;
  156. aminsert_function aminsert;
  157. ambulkdelete_function ambulkdelete;
  158. amvacuumcleanup_function amvacuumcleanup;
  159. amcanreturn_function amcanreturn; /* can be NULL */
  160. amcostestimate_function amcostestimate;
  161. amoptions_function amoptions;
  162. amproperty_function amproperty; /* can be NULL */
  163. amvalidate_function amvalidate;
  164. ambeginscan_function ambeginscan;
  165. amrescan_function amrescan;
  166. amgettuple_function amgettuple; /* can be NULL */
  167. amgetbitmap_function amgetbitmap; /* can be NULL */
  168. amendscan_function amendscan;
  169. ammarkpos_function ammarkpos; /* can be NULL */
  170. amrestrpos_function amrestrpos; /* can be NULL */
  171. } IndexAmRoutine;
  172. /* Functions in access/index/amapi.c */
  173. extern IndexAmRoutine *GetIndexAmRoutine(Oid amhandler);
  174. extern IndexAmRoutine *GetIndexAmRoutineByAmId(Oid amoid, bool noerror);
  175. extern Datum amvalidate(PG_FUNCTION_ARGS);
  176. #endif /* AMAPI_H */