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