genam.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*-------------------------------------------------------------------------
  2. *
  3. * genam.h
  4. * POSTGRES generalized index access method definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2016, 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. /*
  23. * Struct for statistics returned by ambuild
  24. */
  25. typedef struct IndexBuildResult
  26. {
  27. double heap_tuples; /* # of tuples seen in parent table */
  28. double index_tuples; /* # of tuples inserted into index */
  29. } IndexBuildResult;
  30. /*
  31. * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
  32. *
  33. * num_heap_tuples is accurate only when estimated_count is false;
  34. * otherwise it's just an estimate (currently, the estimate is the
  35. * prior value of the relation's pg_class.reltuples field). It will
  36. * always just be an estimate during ambulkdelete.
  37. */
  38. typedef struct IndexVacuumInfo
  39. {
  40. Relation index; /* the index being vacuumed */
  41. bool analyze_only; /* ANALYZE (without any actual vacuum) */
  42. bool estimated_count; /* num_heap_tuples is an estimate */
  43. int message_level; /* ereport level for progress messages */
  44. double num_heap_tuples; /* tuples remaining in heap */
  45. BufferAccessStrategy strategy; /* access strategy for reads */
  46. } IndexVacuumInfo;
  47. /*
  48. * Struct for statistics returned by ambulkdelete and amvacuumcleanup
  49. *
  50. * This struct is normally allocated by the first ambulkdelete call and then
  51. * passed along through subsequent ones until amvacuumcleanup; however,
  52. * amvacuumcleanup must be prepared to allocate it in the case where no
  53. * ambulkdelete calls were made (because no tuples needed deletion).
  54. * Note that an index AM could choose to return a larger struct
  55. * of which this is just the first field; this provides a way for ambulkdelete
  56. * to communicate additional private data to amvacuumcleanup.
  57. *
  58. * Note: pages_removed is the amount by which the index physically shrank,
  59. * if any (ie the change in its total size on disk). pages_deleted and
  60. * pages_free refer to free space within the index file. Some index AMs
  61. * may compute num_index_tuples by reference to num_heap_tuples, in which
  62. * case they should copy the estimated_count field from IndexVacuumInfo.
  63. */
  64. typedef struct IndexBulkDeleteResult
  65. {
  66. BlockNumber num_pages; /* pages remaining in index */
  67. BlockNumber pages_removed; /* # removed during vacuum operation */
  68. bool estimated_count; /* num_index_tuples is an estimate */
  69. double num_index_tuples; /* tuples remaining */
  70. double tuples_removed; /* # removed during vacuum operation */
  71. BlockNumber pages_deleted; /* # unused pages in index */
  72. BlockNumber pages_free; /* # pages available for reuse */
  73. } IndexBulkDeleteResult;
  74. /* Typedef for callback function to determine if a tuple is bulk-deletable */
  75. typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
  76. /* struct definitions appear in relscan.h */
  77. typedef struct IndexScanDescData *IndexScanDesc;
  78. typedef struct SysScanDescData *SysScanDesc;
  79. /*
  80. * Enumeration specifying the type of uniqueness check to perform in
  81. * index_insert().
  82. *
  83. * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
  84. * blocking to see if a conflicting transaction commits.
  85. *
  86. * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
  87. * insertion time. The index AM should test if the tuple is unique, but
  88. * should not throw error, block, or prevent the insertion if the tuple
  89. * appears not to be unique. We'll recheck later when it is time for the
  90. * constraint to be enforced. The AM must return true if the tuple is
  91. * known unique, false if it is possibly non-unique. In the "true" case
  92. * it is safe to omit the later recheck.
  93. *
  94. * When it is time to recheck the deferred constraint, a pseudo-insertion
  95. * call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
  96. * index in this case, so it should not be inserted again. Rather, just
  97. * check for conflicting live tuples (possibly blocking).
  98. */
  99. typedef enum IndexUniqueCheck
  100. {
  101. UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
  102. UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
  103. UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
  104. UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
  105. } IndexUniqueCheck;
  106. /*
  107. * generalized index_ interface routines (in indexam.c)
  108. */
  109. /*
  110. * IndexScanIsValid
  111. * True iff the index scan is valid.
  112. */
  113. #define IndexScanIsValid(scan) PointerIsValid(scan)
  114. extern Relation index_open(Oid relationId, LOCKMODE lockmode);
  115. extern void index_close(Relation relation, LOCKMODE lockmode);
  116. extern bool index_insert(Relation indexRelation,
  117. Datum *values, bool *isnull,
  118. ItemPointer heap_t_ctid,
  119. Relation heapRelation,
  120. IndexUniqueCheck checkUnique);
  121. extern IndexScanDesc index_beginscan(Relation heapRelation,
  122. Relation indexRelation,
  123. Snapshot snapshot,
  124. int nkeys, int norderbys);
  125. extern IndexScanDesc index_beginscan_bitmap(Relation indexRelation,
  126. Snapshot snapshot,
  127. int nkeys);
  128. extern void index_rescan(IndexScanDesc scan,
  129. ScanKey keys, int nkeys,
  130. ScanKey orderbys, int norderbys);
  131. extern void index_endscan(IndexScanDesc scan);
  132. extern void index_markpos(IndexScanDesc scan);
  133. extern void index_restrpos(IndexScanDesc scan);
  134. extern ItemPointer index_getnext_tid(IndexScanDesc scan,
  135. ScanDirection direction);
  136. extern HeapTuple index_fetch_heap(IndexScanDesc scan);
  137. extern HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction);
  138. extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
  139. extern IndexBulkDeleteResult *index_bulk_delete(IndexVacuumInfo *info,
  140. IndexBulkDeleteResult *stats,
  141. IndexBulkDeleteCallback callback,
  142. void *callback_state);
  143. extern IndexBulkDeleteResult *index_vacuum_cleanup(IndexVacuumInfo *info,
  144. IndexBulkDeleteResult *stats);
  145. extern bool index_can_return(Relation indexRelation, int attno);
  146. extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum,
  147. uint16 procnum);
  148. extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
  149. uint16 procnum);
  150. /*
  151. * index access method support routines (in genam.c)
  152. */
  153. extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
  154. int nkeys, int norderbys);
  155. extern void IndexScanEnd(IndexScanDesc scan);
  156. extern char *BuildIndexValueDescription(Relation indexRelation,
  157. Datum *values, bool *isnull);
  158. /*
  159. * heap-or-index access to system catalogs (in genam.c)
  160. */
  161. extern SysScanDesc systable_beginscan(Relation heapRelation,
  162. Oid indexId,
  163. bool indexOK,
  164. Snapshot snapshot,
  165. int nkeys, ScanKey key);
  166. extern HeapTuple systable_getnext(SysScanDesc sysscan);
  167. extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup);
  168. extern void systable_endscan(SysScanDesc sysscan);
  169. extern SysScanDesc systable_beginscan_ordered(Relation heapRelation,
  170. Relation indexRelation,
  171. Snapshot snapshot,
  172. int nkeys, ScanKey key);
  173. extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan,
  174. ScanDirection direction);
  175. extern void systable_endscan_ordered(SysScanDesc sysscan);
  176. #endif /* GENAM_H */