gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

226 行
8.7KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * genam.h
  4. * POSTGRES generalized index access method definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2019, 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). It will
  38. * 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_removed is the amount by which the index physically shrank,
  62. * if any (ie the change in its total size on disk). pages_deleted and
  63. * pages_free refer to free space within the index file. Some index AMs
  64. * may compute num_index_tuples by reference to num_heap_tuples, in which
  65. * case they should copy the estimated_count field from IndexVacuumInfo.
  66. */
  67. typedef struct IndexBulkDeleteResult
  68. {
  69. BlockNumber num_pages; /* pages remaining in index */
  70. BlockNumber pages_removed; /* # removed during vacuum operation */
  71. bool estimated_count; /* num_index_tuples is an estimate */
  72. double num_index_tuples; /* tuples remaining */
  73. double tuples_removed; /* # removed during vacuum operation */
  74. BlockNumber pages_deleted; /* # unused pages in index */
  75. BlockNumber pages_free; /* # pages available for reuse */
  76. } IndexBulkDeleteResult;
  77. /* Typedef for callback function to determine if a tuple is bulk-deletable */
  78. typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
  79. /* struct definitions appear in relscan.h */
  80. typedef struct IndexScanDescData *IndexScanDesc;
  81. typedef struct SysScanDescData *SysScanDesc;
  82. typedef struct ParallelIndexScanDescData *ParallelIndexScanDesc;
  83. /*
  84. * Enumeration specifying the type of uniqueness check to perform in
  85. * index_insert().
  86. *
  87. * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
  88. * blocking to see if a conflicting transaction commits.
  89. *
  90. * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
  91. * insertion time. The index AM should test if the tuple is unique, but
  92. * should not throw error, block, or prevent the insertion if the tuple
  93. * appears not to be unique. We'll recheck later when it is time for the
  94. * constraint to be enforced. The AM must return true if the tuple is
  95. * known unique, false if it is possibly non-unique. In the "true" case
  96. * it is safe to omit the later recheck.
  97. *
  98. * When it is time to recheck the deferred constraint, a pseudo-insertion
  99. * call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
  100. * index in this case, so it should not be inserted again. Rather, just
  101. * check for conflicting live tuples (possibly blocking).
  102. */
  103. typedef enum IndexUniqueCheck
  104. {
  105. UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
  106. UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
  107. UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
  108. UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
  109. } IndexUniqueCheck;
  110. /* Nullable "ORDER BY col op const" distance */
  111. typedef struct IndexOrderByDistance
  112. {
  113. double value;
  114. bool isnull;
  115. } IndexOrderByDistance;
  116. /*
  117. * generalized index_ interface routines (in indexam.c)
  118. */
  119. /*
  120. * IndexScanIsValid
  121. * True iff the index scan is valid.
  122. */
  123. #define IndexScanIsValid(scan) PointerIsValid(scan)
  124. extern Relation index_open(Oid relationId, LOCKMODE lockmode);
  125. extern void index_close(Relation relation, LOCKMODE lockmode);
  126. extern bool index_insert(Relation indexRelation,
  127. Datum *values, bool *isnull,
  128. ItemPointer heap_t_ctid,
  129. Relation heapRelation,
  130. IndexUniqueCheck checkUnique,
  131. struct IndexInfo *indexInfo);
  132. extern IndexScanDesc index_beginscan(Relation heapRelation,
  133. Relation indexRelation,
  134. Snapshot snapshot,
  135. int nkeys, int norderbys);
  136. extern IndexScanDesc index_beginscan_bitmap(Relation indexRelation,
  137. Snapshot snapshot,
  138. int nkeys);
  139. extern void index_rescan(IndexScanDesc scan,
  140. ScanKey keys, int nkeys,
  141. ScanKey orderbys, int norderbys);
  142. extern void index_endscan(IndexScanDesc scan);
  143. extern void index_markpos(IndexScanDesc scan);
  144. extern void index_restrpos(IndexScanDesc scan);
  145. extern Size index_parallelscan_estimate(Relation indexrel, Snapshot snapshot);
  146. extern void index_parallelscan_initialize(Relation heaprel, Relation indexrel,
  147. Snapshot snapshot, ParallelIndexScanDesc target);
  148. extern void index_parallelrescan(IndexScanDesc scan);
  149. extern IndexScanDesc index_beginscan_parallel(Relation heaprel,
  150. Relation indexrel, int nkeys, int norderbys,
  151. ParallelIndexScanDesc pscan);
  152. extern ItemPointer index_getnext_tid(IndexScanDesc scan,
  153. ScanDirection direction);
  154. struct TupleTableSlot;
  155. extern bool index_fetch_heap(IndexScanDesc scan, struct TupleTableSlot *slot);
  156. extern bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction,
  157. struct TupleTableSlot *slot);
  158. extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
  159. extern IndexBulkDeleteResult *index_bulk_delete(IndexVacuumInfo *info,
  160. IndexBulkDeleteResult *stats,
  161. IndexBulkDeleteCallback callback,
  162. void *callback_state);
  163. extern IndexBulkDeleteResult *index_vacuum_cleanup(IndexVacuumInfo *info,
  164. IndexBulkDeleteResult *stats);
  165. extern bool index_can_return(Relation indexRelation, int attno);
  166. extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum,
  167. uint16 procnum);
  168. extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
  169. uint16 procnum);
  170. extern void index_store_float8_orderby_distances(IndexScanDesc scan,
  171. Oid *orderByTypes,
  172. IndexOrderByDistance *distances,
  173. bool recheckOrderBy);
  174. /*
  175. * index access method support routines (in genam.c)
  176. */
  177. extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
  178. int nkeys, int norderbys);
  179. extern void IndexScanEnd(IndexScanDesc scan);
  180. extern char *BuildIndexValueDescription(Relation indexRelation,
  181. Datum *values, bool *isnull);
  182. extern TransactionId index_compute_xid_horizon_for_tuples(Relation irel,
  183. Relation hrel,
  184. Buffer ibuf,
  185. OffsetNumber *itemnos,
  186. int nitems);
  187. /*
  188. * heap-or-index access to system catalogs (in genam.c)
  189. */
  190. extern SysScanDesc systable_beginscan(Relation heapRelation,
  191. Oid indexId,
  192. bool indexOK,
  193. Snapshot snapshot,
  194. int nkeys, ScanKey key);
  195. extern HeapTuple systable_getnext(SysScanDesc sysscan);
  196. extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup);
  197. extern void systable_endscan(SysScanDesc sysscan);
  198. extern SysScanDesc systable_beginscan_ordered(Relation heapRelation,
  199. Relation indexRelation,
  200. Snapshot snapshot,
  201. int nkeys, ScanKey key);
  202. extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan,
  203. ScanDirection direction);
  204. extern void systable_endscan_ordered(SysScanDesc sysscan);
  205. #endif /* GENAM_H */
上海开阖软件有限公司 沪ICP备12045867号-1