spgist.h 7.7 KB

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