gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
7.6KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * spgist.h
  4. * Public header file for SP-GiST access method.
  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/spgist.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef SPGIST_H
  15. #define SPGIST_H
  16. #include "access/amapi.h"
  17. #include "access/xlogreader.h"
  18. #include "fmgr.h"
  19. #include "lib/stringinfo.h"
  20. /* reloption parameters */
  21. #define SPGIST_MIN_FILLFACTOR 10
  22. #define SPGIST_DEFAULT_FILLFACTOR 80
  23. /* SPGiST opclass support function numbers */
  24. #define SPGIST_CONFIG_PROC 1
  25. #define SPGIST_CHOOSE_PROC 2
  26. #define SPGIST_PICKSPLIT_PROC 3
  27. #define SPGIST_INNER_CONSISTENT_PROC 4
  28. #define SPGIST_LEAF_CONSISTENT_PROC 5
  29. #define SPGIST_COMPRESS_PROC 6
  30. #define SPGISTNRequiredProc 5
  31. #define SPGISTNProc 6
  32. /*
  33. * Argument structs for spg_config method
  34. */
  35. typedef struct spgConfigIn
  36. {
  37. Oid attType; /* Data type to be indexed */
  38. } spgConfigIn;
  39. typedef struct spgConfigOut
  40. {
  41. Oid prefixType; /* Data type of inner-tuple prefixes */
  42. Oid labelType; /* Data type of inner-tuple node labels */
  43. Oid leafType; /* Data type of leaf-tuple values */
  44. bool canReturnData; /* Opclass can reconstruct original data */
  45. bool longValuesOK; /* Opclass can cope with values > 1 page */
  46. } spgConfigOut;
  47. /*
  48. * Argument structs for spg_choose method
  49. */
  50. typedef struct spgChooseIn
  51. {
  52. Datum datum; /* original datum to be indexed */
  53. Datum leafDatum; /* current datum to be stored at leaf */
  54. int level; /* current level (counting from zero) */
  55. /* Data from current inner tuple */
  56. bool allTheSame; /* tuple is marked all-the-same? */
  57. bool hasPrefix; /* tuple has a prefix? */
  58. Datum prefixDatum; /* if so, the prefix value */
  59. int nNodes; /* number of nodes in the inner tuple */
  60. Datum *nodeLabels; /* node label values (NULL if none) */
  61. } spgChooseIn;
  62. typedef enum spgChooseResultType
  63. {
  64. spgMatchNode = 1, /* descend into existing node */
  65. spgAddNode, /* add a node to the inner tuple */
  66. spgSplitTuple /* split inner tuple (change its prefix) */
  67. } spgChooseResultType;
  68. typedef struct spgChooseOut
  69. {
  70. spgChooseResultType resultType; /* action code, see above */
  71. union
  72. {
  73. struct /* results for spgMatchNode */
  74. {
  75. int nodeN; /* descend to this node (index from 0) */
  76. int levelAdd; /* increment level by this much */
  77. Datum restDatum; /* new leaf datum */
  78. } matchNode;
  79. struct /* results for spgAddNode */
  80. {
  81. Datum nodeLabel; /* new node's label */
  82. int nodeN; /* where to insert it (index from 0) */
  83. } addNode;
  84. struct /* results for spgSplitTuple */
  85. {
  86. /* Info to form new upper-level inner tuple with one child tuple */
  87. bool prefixHasPrefix; /* tuple should have a prefix? */
  88. Datum prefixPrefixDatum; /* if so, its value */
  89. int prefixNNodes; /* number of nodes */
  90. Datum *prefixNodeLabels; /* their labels (or NULL for no
  91. * labels) */
  92. int childNodeN; /* which node gets child tuple */
  93. /* Info to form new lower-level inner tuple with all old nodes */
  94. bool postfixHasPrefix; /* tuple should have a prefix? */
  95. Datum postfixPrefixDatum; /* if so, its value */
  96. } splitTuple;
  97. } result;
  98. } spgChooseOut;
  99. /*
  100. * Argument structs for spg_picksplit method
  101. */
  102. typedef struct spgPickSplitIn
  103. {
  104. int nTuples; /* number of leaf tuples */
  105. Datum *datums; /* their datums (array of length nTuples) */
  106. int level; /* current level (counting from zero) */
  107. } spgPickSplitIn;
  108. typedef struct spgPickSplitOut
  109. {
  110. bool hasPrefix; /* new inner tuple should have a prefix? */
  111. Datum prefixDatum; /* if so, its value */
  112. int nNodes; /* number of nodes for new inner tuple */
  113. Datum *nodeLabels; /* their labels (or NULL for no labels) */
  114. int *mapTuplesToNodes; /* node index for each leaf tuple */
  115. Datum *leafTupleDatums; /* datum to store in each new leaf tuple */
  116. } spgPickSplitOut;
  117. /*
  118. * Argument structs for spg_inner_consistent method
  119. */
  120. typedef struct spgInnerConsistentIn
  121. {
  122. ScanKey scankeys; /* array of operators and comparison values */
  123. ScanKey orderbys; /* array of ordering operators and comparison
  124. * values */
  125. int nkeys; /* length of scankeys array */
  126. int norderbys; /* length of orderbys array */
  127. Datum reconstructedValue; /* value reconstructed at parent */
  128. void *traversalValue; /* opclass-specific traverse value */
  129. MemoryContext traversalMemoryContext; /* put new traverse values here */
  130. int level; /* current level (counting from zero) */
  131. bool returnData; /* original data must be returned? */
  132. /* Data from current inner tuple */
  133. bool allTheSame; /* tuple is marked all-the-same? */
  134. bool hasPrefix; /* tuple has a prefix? */
  135. Datum prefixDatum; /* if so, the prefix value */
  136. int nNodes; /* number of nodes in the inner tuple */
  137. Datum *nodeLabels; /* node label values (NULL if none) */
  138. } spgInnerConsistentIn;
  139. typedef struct spgInnerConsistentOut
  140. {
  141. int nNodes; /* number of child nodes to be visited */
  142. int *nodeNumbers; /* their indexes in the node array */
  143. int *levelAdds; /* increment level by this much for each */
  144. Datum *reconstructedValues; /* associated reconstructed values */
  145. void **traversalValues; /* opclass-specific traverse values */
  146. double **distances; /* associated distances */
  147. } spgInnerConsistentOut;
  148. /*
  149. * Argument structs for spg_leaf_consistent method
  150. */
  151. typedef struct spgLeafConsistentIn
  152. {
  153. ScanKey scankeys; /* array of operators and comparison values */
  154. ScanKey orderbys; /* array of ordering operators and comparison
  155. * values */
  156. int nkeys; /* length of scankeys array */
  157. int norderbys; /* length of orderbys array */
  158. Datum reconstructedValue; /* value reconstructed at parent */
  159. void *traversalValue; /* opclass-specific traverse value */
  160. int level; /* current level (counting from zero) */
  161. bool returnData; /* original data must be returned? */
  162. Datum leafDatum; /* datum in leaf tuple */
  163. } spgLeafConsistentIn;
  164. typedef struct spgLeafConsistentOut
  165. {
  166. Datum leafValue; /* reconstructed original data, if any */
  167. bool recheck; /* set true if operator must be rechecked */
  168. bool recheckDistances; /* set true if distances must be rechecked */
  169. double *distances; /* associated distances */
  170. } spgLeafConsistentOut;
  171. /* spgutils.c */
  172. extern bytea *spgoptions(Datum reloptions, bool validate);
  173. /* spginsert.c */
  174. extern IndexBuildResult *spgbuild(Relation heap, Relation index,
  175. struct IndexInfo *indexInfo);
  176. extern void spgbuildempty(Relation index);
  177. extern bool spginsert(Relation index, Datum *values, bool *isnull,
  178. ItemPointer ht_ctid, Relation heapRel,
  179. IndexUniqueCheck checkUnique,
  180. struct IndexInfo *indexInfo);
  181. /* spgscan.c */
  182. extern IndexScanDesc spgbeginscan(Relation rel, int keysz, int orderbysz);
  183. extern void spgendscan(IndexScanDesc scan);
  184. extern void spgrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
  185. ScanKey orderbys, int norderbys);
  186. extern int64 spggetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
  187. extern bool spggettuple(IndexScanDesc scan, ScanDirection dir);
  188. extern bool spgcanreturn(Relation index, int attno);
  189. /* spgvacuum.c */
  190. extern IndexBulkDeleteResult *spgbulkdelete(IndexVacuumInfo *info,
  191. IndexBulkDeleteResult *stats,
  192. IndexBulkDeleteCallback callback,
  193. void *callback_state);
  194. extern IndexBulkDeleteResult *spgvacuumcleanup(IndexVacuumInfo *info,
  195. IndexBulkDeleteResult *stats);
  196. /* spgvalidate.c */
  197. extern bool spgvalidate(Oid opclassoid);
  198. #endif /* SPGIST_H */
上海开阖软件有限公司 沪ICP备12045867号-1