spgist.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*-------------------------------------------------------------------------
  2. *
  3. * spgist.h
  4. * Public header file for SP-GiST access method.
  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/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 SPGISTNProc 5
  30. /*
  31. * Argument structs for spg_config method
  32. */
  33. typedef struct spgConfigIn
  34. {
  35. Oid attType; /* Data type to be indexed */
  36. } spgConfigIn;
  37. typedef struct spgConfigOut
  38. {
  39. Oid prefixType; /* Data type of inner-tuple prefixes */
  40. Oid labelType; /* Data type of inner-tuple node labels */
  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 inner tuple with one node */
  84. bool prefixHasPrefix; /* tuple should have a prefix? */
  85. Datum prefixPrefixDatum; /* if so, its value */
  86. Datum nodeLabel; /* node's label */
  87. /* Info to form new lower-level inner tuple with all old nodes */
  88. bool postfixHasPrefix; /* tuple should have a prefix? */
  89. Datum postfixPrefixDatum; /* if so, its value */
  90. } splitTuple;
  91. } result;
  92. } spgChooseOut;
  93. /*
  94. * Argument structs for spg_picksplit method
  95. */
  96. typedef struct spgPickSplitIn
  97. {
  98. int nTuples; /* number of leaf tuples */
  99. Datum *datums; /* their datums (array of length nTuples) */
  100. int level; /* current level (counting from zero) */
  101. } spgPickSplitIn;
  102. typedef struct spgPickSplitOut
  103. {
  104. bool hasPrefix; /* new inner tuple should have a prefix? */
  105. Datum prefixDatum; /* if so, its value */
  106. int nNodes; /* number of nodes for new inner tuple */
  107. Datum *nodeLabels; /* their labels (or NULL for no labels) */
  108. int *mapTuplesToNodes; /* node index for each leaf tuple */
  109. Datum *leafTupleDatums; /* datum to store in each new leaf tuple */
  110. } spgPickSplitOut;
  111. /*
  112. * Argument structs for spg_inner_consistent method
  113. */
  114. typedef struct spgInnerConsistentIn
  115. {
  116. ScanKey scankeys; /* array of operators and comparison values */
  117. int nkeys; /* length of array */
  118. Datum reconstructedValue; /* value reconstructed at parent */
  119. void *traversalValue; /* opclass-specific traverse value */
  120. MemoryContext traversalMemoryContext;
  121. int level; /* current level (counting from zero) */
  122. bool returnData; /* original data must be returned? */
  123. /* Data from current inner tuple */
  124. bool allTheSame; /* tuple is marked all-the-same? */
  125. bool hasPrefix; /* tuple has a prefix? */
  126. Datum prefixDatum; /* if so, the prefix value */
  127. int nNodes; /* number of nodes in the inner tuple */
  128. Datum *nodeLabels; /* node label values (NULL if none) */
  129. } spgInnerConsistentIn;
  130. typedef struct spgInnerConsistentOut
  131. {
  132. int nNodes; /* number of child nodes to be visited */
  133. int *nodeNumbers; /* their indexes in the node array */
  134. int *levelAdds; /* increment level by this much for each */
  135. Datum *reconstructedValues; /* associated reconstructed values */
  136. void **traversalValues; /* opclass-specific traverse values */
  137. } spgInnerConsistentOut;
  138. /*
  139. * Argument structs for spg_leaf_consistent method
  140. */
  141. typedef struct spgLeafConsistentIn
  142. {
  143. ScanKey scankeys; /* array of operators and comparison values */
  144. int nkeys; /* length of array */
  145. void *traversalValue; /* opclass-specific traverse value */
  146. Datum reconstructedValue; /* value reconstructed at parent */
  147. int level; /* current level (counting from zero) */
  148. bool returnData; /* original data must be returned? */
  149. Datum leafDatum; /* datum in leaf tuple */
  150. } spgLeafConsistentIn;
  151. typedef struct spgLeafConsistentOut
  152. {
  153. Datum leafValue; /* reconstructed original data, if any */
  154. bool recheck; /* set true if operator must be rechecked */
  155. } spgLeafConsistentOut;
  156. /* spgutils.c */
  157. extern Datum spghandler(PG_FUNCTION_ARGS);
  158. extern bytea *spgoptions(Datum reloptions, bool validate);
  159. /* spginsert.c */
  160. extern IndexBuildResult *spgbuild(Relation heap, Relation index,
  161. struct IndexInfo *indexInfo);
  162. extern void spgbuildempty(Relation index);
  163. extern bool spginsert(Relation index, Datum *values, bool *isnull,
  164. ItemPointer ht_ctid, Relation heapRel,
  165. IndexUniqueCheck checkUnique);
  166. /* spgscan.c */
  167. extern IndexScanDesc spgbeginscan(Relation rel, int keysz, int orderbysz);
  168. extern void spgendscan(IndexScanDesc scan);
  169. extern void spgrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
  170. ScanKey orderbys, int norderbys);
  171. extern int64 spggetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
  172. extern bool spggettuple(IndexScanDesc scan, ScanDirection dir);
  173. extern bool spgcanreturn(Relation index, int attno);
  174. /* spgvacuum.c */
  175. extern IndexBulkDeleteResult *spgbulkdelete(IndexVacuumInfo *info,
  176. IndexBulkDeleteResult *stats,
  177. IndexBulkDeleteCallback callback,
  178. void *callback_state);
  179. extern IndexBulkDeleteResult *spgvacuumcleanup(IndexVacuumInfo *info,
  180. IndexBulkDeleteResult *stats);
  181. /* spgvalidate.c */
  182. extern bool spgvalidate(Oid opclassoid);
  183. /* spgxlog.c */
  184. extern void spg_redo(XLogReaderState *record);
  185. extern void spg_desc(StringInfo buf, XLogReaderState *record);
  186. extern const char *spg_identify(uint8 info);
  187. extern void spg_xlog_startup(void);
  188. extern void spg_xlog_cleanup(void);
  189. #endif /* SPGIST_H */