2
0

genam.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*-------------------------------------------------------------------------
  2. *
  3. * genam.h
  4. * POSTGRES generalized index access method definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/access/genam.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef GENAM_H
  15. #define GENAM_H
  16. #include "access/sdir.h"
  17. #include "access/skey.h"
  18. #include "nodes/tidbitmap.h"
  19. #include "storage/lockdefs.h"
  20. #include "utils/relcache.h"
  21. #include "utils/snapshot.h"
  22. /* We don't want this file to depend on execnodes.h. */
  23. struct IndexInfo;
  24. /*
  25. * Struct for statistics returned by ambuild
  26. */
  27. typedef struct IndexBuildResult
  28. {
  29. double heap_tuples; /* # of tuples seen in parent table */
  30. double index_tuples; /* # of tuples inserted into index */
  31. } IndexBuildResult;
  32. /*
  33. * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
  34. *
  35. * num_heap_tuples is accurate only when estimated_count is false;
  36. * otherwise it's just an estimate (currently, the estimate is the
  37. * prior value of the relation's pg_class.reltuples field, so it could
  38. * even be -1). It will always just be an estimate during ambulkdelete.
  39. */
  40. typedef struct IndexVacuumInfo
  41. {
  42. Relation index; /* the index being vacuumed */
  43. bool analyze_only; /* ANALYZE (without any actual vacuum) */
  44. bool report_progress; /* emit progress.h status reports */
  45. bool estimated_count; /* num_heap_tuples is an estimate */
  46. int message_level; /* ereport level for progress messages */
  47. double num_heap_tuples; /* tuples remaining in heap */
  48. BufferAccessStrategy strategy; /* access strategy for reads */
  49. } IndexVacuumInfo;
  50. /*
  51. * Struct for statistics returned by ambulkdelete and amvacuumcleanup
  52. *
  53. * This struct is normally allocated by the first ambulkdelete call and then
  54. * passed along through subsequent ones until amvacuumcleanup; however,
  55. * amvacuumcleanup must be prepared to allocate it in the case where no
  56. * ambulkdelete calls were made (because no tuples needed deletion).
  57. * Note that an index AM could choose to return a larger struct
  58. * of which this is just the first field; this provides a way for ambulkdelete
  59. * to communicate additional private data to amvacuumcleanup.
  60. *
  61. * Note: pages_newly_deleted is the number of pages in the index that were
  62. * deleted by the current vacuum operation. pages_deleted and pages_free
  63. * refer to free space within the index file.
  64. *
  65. * Note: Some index AMs may compute num_index_tuples by reference to
  66. * num_heap_tuples, in which case they should copy the estimated_count field
  67. * from IndexVacuumInfo.
  68. */
  69. typedef struct IndexBulkDeleteResult
  70. {
  71. BlockNumber num_pages; /* pages remaining in index */
  72. bool estimated_count; /* num_index_tuples is an estimate */
  73. double num_index_tuples; /* tuples remaining */
  74. double tuples_removed; /* # removed during vacuum operation */
  75. BlockNumber pages_newly_deleted; /* # pages marked deleted by us */
  76. BlockNumber pages_deleted; /* # pages marked deleted (could be by us) */
  77. BlockNumber pages_free; /* # pages available for reuse */
  78. } IndexBulkDeleteResult;
  79. /* Typedef for callback function to determine if a tuple is bulk-deletable */
  80. typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
  81. /* struct definitions appear in relscan.h */
  82. typedef struct IndexScanDescData *IndexScanDesc;
  83. typedef struct SysScanDescData *SysScanDesc;
  84. typedef struct ParallelIndexScanDescData *ParallelIndexScanDesc;
  85. /*
  86. * Enumeration specifying the type of uniqueness check to perform in
  87. * index_insert().
  88. *
  89. * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
  90. * blocking to see if a conflicting transaction commits.
  91. *
  92. * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
  93. * insertion time. The index AM should test if the tuple is unique, but
  94. * should not throw error, block, or prevent the insertion if the tuple
  95. * appears not to be unique. We'll recheck later when it is time for the
  96. * constraint to be enforced. The AM must return true if the tuple is
  97. * known unique, false if it is possibly non-unique. In the "true" case
  98. * it is safe to omit the later recheck.
  99. *
  100. * When it is time to recheck the deferred constraint, a pseudo-insertion
  101. * call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
  102. * index in this case, so it should not be inserted again. Rather, just
  103. * check for conflicting live tuples (possibly blocking).
  104. */
  105. typedef enum IndexUniqueCheck
  106. {
  107. UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
  108. UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
  109. UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
  110. UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
  111. } IndexUniqueCheck;
  112. /* Nullable "ORDER BY col op const" distance */
  113. typedef struct IndexOrderByDistance
  114. {
  115. double value;
  116. bool isnull;
  117. } IndexOrderByDistance;
  118. /*
  119. * generalized index_ interface routines (in indexam.c)
  120. */
  121. /*
  122. * IndexScanIsValid
  123. * True iff the index scan is valid.
  124. */
  125. #define IndexScanIsValid(scan) PointerIsValid(scan)
  126. extern Relation index_open(Oid relationId, LOCKMODE lockmode);
  127. extern void index_close(Relation relation, LOCKMODE lockmode);
  128. extern bool index_insert(Relation indexRelation,
  129. Datum *values, bool *isnull,
  130. ItemPointer heap_t_ctid,
  131. Relation heapRelation,
  132. IndexUniqueCheck checkUnique,
  133. bool indexUnchanged,
  134. struct IndexInfo *indexInfo);
  135. extern IndexScanDesc index_beginscan(Relation heapRelation,
  136. Relation indexRelation,
  137. Snapshot snapshot,
  138. int nkeys, int norderbys);
  139. extern IndexScanDesc index_beginscan_bitmap(Relation indexRelation,
  140. Snapshot snapshot,
  141. int nkeys);
  142. extern void index_rescan(IndexScanDesc scan,
  143. ScanKey keys, int nkeys,
  144. ScanKey orderbys, int norderbys);
  145. extern void index_endscan(IndexScanDesc scan);
  146. extern void index_markpos(IndexScanDesc scan);
  147. extern void index_restrpos(IndexScanDesc scan);
  148. extern Size index_parallelscan_estimate(Relation indexrel, Snapshot snapshot);
  149. extern void index_parallelscan_initialize(Relation heaprel, Relation indexrel,
  150. Snapshot snapshot, ParallelIndexScanDesc target);
  151. extern void index_parallelrescan(IndexScanDesc scan);
  152. extern IndexScanDesc index_beginscan_parallel(Relation heaprel,
  153. Relation indexrel, int nkeys, int norderbys,
  154. ParallelIndexScanDesc pscan);
  155. extern ItemPointer index_getnext_tid(IndexScanDesc scan,
  156. ScanDirection direction);
  157. struct TupleTableSlot;
  158. extern bool index_fetch_heap(IndexScanDesc scan, struct TupleTableSlot *slot);
  159. extern bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction,
  160. struct TupleTableSlot *slot);
  161. extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
  162. extern IndexBulkDeleteResult *index_bulk_delete(IndexVacuumInfo *info,
  163. IndexBulkDeleteResult *istat,
  164. IndexBulkDeleteCallback callback,
  165. void *callback_state);
  166. extern IndexBulkDeleteResult *index_vacuum_cleanup(IndexVacuumInfo *info,
  167. IndexBulkDeleteResult *istat);
  168. extern bool index_can_return(Relation indexRelation, int attno);
  169. extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum,
  170. uint16 procnum);
  171. extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
  172. uint16 procnum);
  173. extern void index_store_float8_orderby_distances(IndexScanDesc scan,
  174. Oid *orderByTypes,
  175. IndexOrderByDistance *distances,
  176. bool recheckOrderBy);
  177. extern bytea *index_opclass_options(Relation relation, AttrNumber attnum,
  178. Datum attoptions, bool validate);
  179. /*
  180. * index access method support routines (in genam.c)
  181. */
  182. extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
  183. int nkeys, int norderbys);
  184. extern void IndexScanEnd(IndexScanDesc scan);
  185. extern char *BuildIndexValueDescription(Relation indexRelation,
  186. Datum *values, bool *isnull);
  187. extern TransactionId index_compute_xid_horizon_for_tuples(Relation irel,
  188. Relation hrel,
  189. Buffer ibuf,
  190. OffsetNumber *itemnos,
  191. int nitems);
  192. /*
  193. * heap-or-index access to system catalogs (in genam.c)
  194. */
  195. extern SysScanDesc systable_beginscan(Relation heapRelation,
  196. Oid indexId,
  197. bool indexOK,
  198. Snapshot snapshot,
  199. int nkeys, ScanKey key);
  200. extern HeapTuple systable_getnext(SysScanDesc sysscan);
  201. extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup);
  202. extern void systable_endscan(SysScanDesc sysscan);
  203. extern SysScanDesc systable_beginscan_ordered(Relation heapRelation,
  204. Relation indexRelation,
  205. Snapshot snapshot,
  206. int nkeys, ScanKey key);
  207. extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan,
  208. ScanDirection direction);
  209. extern void systable_endscan_ordered(SysScanDesc sysscan);
  210. #endif /* GENAM_H */