PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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-2017, 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 "fmgr.h"
20 #include "lib/stringinfo.h"
21 
22 
23 /* reloption parameters */
24 #define SPGIST_MIN_FILLFACTOR 10
25 #define SPGIST_DEFAULT_FILLFACTOR 80
26 
27 /* SPGiST opclass support function numbers */
28 #define SPGIST_CONFIG_PROC 1
29 #define SPGIST_CHOOSE_PROC 2
30 #define SPGIST_PICKSPLIT_PROC 3
31 #define SPGIST_INNER_CONSISTENT_PROC 4
32 #define SPGIST_LEAF_CONSISTENT_PROC 5
33 #define SPGISTNProc 5
34 
35 /*
36  * Argument structs for spg_config method
37  */
38 typedef struct spgConfigIn
39 {
40  Oid attType; /* Data type to be indexed */
41 } spgConfigIn;
42 
43 typedef struct spgConfigOut
44 {
45  Oid prefixType; /* Data type of inner-tuple prefixes */
46  Oid labelType; /* Data type of inner-tuple node labels */
47  bool canReturnData; /* Opclass can reconstruct original data */
48  bool longValuesOK; /* Opclass can cope with values > 1 page */
49 } spgConfigOut;
50 
51 /*
52  * Argument structs for spg_choose method
53  */
54 typedef struct spgChooseIn
55 {
56  Datum datum; /* original datum to be indexed */
57  Datum leafDatum; /* current datum to be stored at leaf */
58  int level; /* current level (counting from zero) */
59 
60  /* Data from current inner tuple */
61  bool allTheSame; /* tuple is marked all-the-same? */
62  bool hasPrefix; /* tuple has a prefix? */
63  Datum prefixDatum; /* if so, the prefix value */
64  int nNodes; /* number of nodes in the inner tuple */
65  Datum *nodeLabels; /* node label values (NULL if none) */
66 } spgChooseIn;
67 
68 typedef enum spgChooseResultType
69 {
70  spgMatchNode = 1, /* descend into existing node */
71  spgAddNode, /* add a node to the inner tuple */
72  spgSplitTuple /* split inner tuple (change its prefix) */
74 
75 typedef struct spgChooseOut
76 {
77  spgChooseResultType resultType; /* action code, see above */
78  union
79  {
80  struct /* results for spgMatchNode */
81  {
82  int nodeN; /* descend to this node (index from 0) */
83  int levelAdd; /* increment level by this much */
84  Datum restDatum; /* new leaf datum */
85  } matchNode;
86  struct /* results for spgAddNode */
87  {
88  Datum nodeLabel; /* new node's label */
89  int nodeN; /* where to insert it (index from 0) */
90  } addNode;
91  struct /* results for spgSplitTuple */
92  {
93  /* Info to form new upper-level inner tuple with one child tuple */
94  bool prefixHasPrefix; /* tuple should have a prefix? */
95  Datum prefixPrefixDatum; /* if so, its value */
96  int prefixNNodes; /* number of nodes */
97  Datum *prefixNodeLabels; /* their labels (or NULL for
98  * no labels) */
99  int childNodeN; /* which node gets child tuple */
100 
101  /* Info to form new lower-level inner tuple with all old nodes */
102  bool postfixHasPrefix; /* tuple should have a prefix? */
103  Datum postfixPrefixDatum; /* if so, its value */
104  } splitTuple;
105  } result;
106 } spgChooseOut;
107 
108 /*
109  * Argument structs for spg_picksplit method
110  */
111 typedef struct spgPickSplitIn
112 {
113  int nTuples; /* number of leaf tuples */
114  Datum *datums; /* their datums (array of length nTuples) */
115  int level; /* current level (counting from zero) */
117 
118 typedef struct spgPickSplitOut
119 {
120  bool hasPrefix; /* new inner tuple should have a prefix? */
121  Datum prefixDatum; /* if so, its value */
122 
123  int nNodes; /* number of nodes for new inner tuple */
124  Datum *nodeLabels; /* their labels (or NULL for no labels) */
125 
126  int *mapTuplesToNodes; /* node index for each leaf tuple */
127  Datum *leafTupleDatums; /* datum to store in each new leaf tuple */
129 
130 /*
131  * Argument structs for spg_inner_consistent method
132  */
133 typedef struct spgInnerConsistentIn
134 {
135  ScanKey scankeys; /* array of operators and comparison values */
136  int nkeys; /* length of array */
137 
138  Datum reconstructedValue; /* value reconstructed at parent */
139  void *traversalValue; /* opclass-specific traverse value */
140  MemoryContext traversalMemoryContext; /* put new traverse values
141  * 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 */
161 
162 /*
163  * Argument structs for spg_leaf_consistent method
164  */
165 typedef struct spgLeafConsistentIn
166 {
167  ScanKey scankeys; /* array of operators and comparison values */
168  int nkeys; /* length of array */
169 
170  Datum reconstructedValue; /* value reconstructed at parent */
171  void *traversalValue; /* opclass-specific traverse value */
172  int level; /* current level (counting from zero) */
173  bool returnData; /* original data must be returned? */
174 
175  Datum leafDatum; /* datum in leaf tuple */
177 
178 typedef struct spgLeafConsistentOut
179 {
180  Datum leafValue; /* reconstructed original data, if any */
181  bool recheck; /* set true if operator must be rechecked */
183 
184 
185 /* spgutils.c */
186 extern bytea *spgoptions(Datum reloptions, bool validate);
187 
188 /* spginsert.c */
190  struct IndexInfo *indexInfo);
191 extern void spgbuildempty(Relation index);
192 extern bool spginsert(Relation index, Datum *values, bool *isnull,
193  ItemPointer ht_ctid, Relation heapRel,
194  IndexUniqueCheck checkUnique,
195  struct IndexInfo *indexInfo);
196 
197 /* spgscan.c */
198 extern IndexScanDesc spgbeginscan(Relation rel, int keysz, int orderbysz);
199 extern void spgendscan(IndexScanDesc scan);
200 extern void spgrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
201  ScanKey orderbys, int norderbys);
202 extern int64 spggetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
203 extern bool spggettuple(IndexScanDesc scan, ScanDirection dir);
204 extern bool spgcanreturn(Relation index, int attno);
205 
206 /* spgvacuum.c */
208  IndexBulkDeleteResult *stats,
210  void *callback_state);
212  IndexBulkDeleteResult *stats);
213 
214 /* spgvalidate.c */
215 extern bool spgvalidate(Oid opclassoid);
216 
217 #endif /* SPGIST_H */
Datum reconstructedValue
Definition: spgist.h:170
struct spgInnerConsistentOut spgInnerConsistentOut
Datum prefixPrefixDatum
Definition: spgist.h:95
Datum datum
Definition: spgist.h:56
bool hasPrefix
Definition: spgist.h:62
struct spgChooseOut::@41::@42 matchNode
int level
Definition: spgist.h:58
bool canReturnData
Definition: spgist.h:47
bool spginsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, struct IndexInfo *indexInfo)
Definition: spginsert.c:208
Datum * leafTupleDatums
Definition: spgist.h:127
Datum * datums
Definition: spgist.h:114
struct spgChooseOut spgChooseOut
void * traversalValue
Definition: spgist.h:139
struct spgPickSplitOut spgPickSplitOut
Datum prefixDatum
Definition: spgist.h:63
Datum * prefixNodeLabels
Definition: spgist.h:97
IndexBulkDeleteResult * spgbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition: spgvacuum.c:886
Oid attType
Definition: spgist.h:40
unsigned int Oid
Definition: postgres_ext.h:31
bool spgcanreturn(Relation index, int attno)
Definition: spgscan.c:648
void spgendscan(IndexScanDesc scan)
Definition: spgscan.c:227
Datum reconstructedValue
Definition: spgist.h:138
struct spgChooseOut::@41::@43 addNode
Definition: type.h:90
IndexScanDesc spgbeginscan(Relation rel, int keysz, int orderbysz)
Definition: spgscan.c:181
IndexUniqueCheck
Definition: genam.h:111
int nodeN
Definition: spgist.h:82
MemoryContext traversalMemoryContext
Definition: spgist.h:140
Datum * nodeLabels
Definition: spgist.h:124
int childNodeN
Definition: spgist.h:99
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:49
ScanKey scankeys
Definition: spgist.h:167
struct spgConfigIn spgConfigIn
ScanDirection
Definition: sdir.h:22
struct spgLeafConsistentIn spgLeafConsistentIn
struct spgChooseOut::@41::@44 splitTuple
void ** traversalValues
Definition: spgist.h:159
int levelAdd
Definition: spgist.h:83
int nNodes
Definition: spgist.h:64
bool postfixHasPrefix
Definition: spgist.h:102
struct spgConfigOut spgConfigOut
Datum restDatum
Definition: spgist.h:84
bytea * spgoptions(Datum reloptions, bool validate)
Definition: spgutils.c:543
int64 spggetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
Definition: spgscan.c:568
bool longValuesOK
Definition: spgist.h:48
uintptr_t Datum
Definition: postgres.h:374
spgChooseResultType
Definition: spgist.h:68
int prefixNNodes
Definition: spgist.h:96
struct spgLeafConsistentOut spgLeafConsistentOut
Oid prefixType
Definition: spgist.h:45
Datum * nodeLabels
Definition: spgist.h:150
spgChooseResultType resultType
Definition: spgist.h:77
Datum postfixPrefixDatum
Definition: spgist.h:103
bool spggettuple(IndexScanDesc scan, ScanDirection dir)
Definition: spgscan.c:605
struct spgChooseIn spgChooseIn
Datum leafDatum
Definition: spgist.h:57
bool hasPrefix
Definition: spgist.h:120
void spgrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
Definition: spgscan.c:207
Datum nodeLabel
Definition: spgist.h:88
Datum * reconstructedValues
Definition: spgist.h:158
ScanKey scankeys
Definition: spgist.h:135
static Datum values[MAXATTR]
Definition: bootstrap.c:162
Datum * nodeLabels
Definition: spgist.h:65
struct spgInnerConsistentIn spgInnerConsistentIn
Oid labelType
Definition: spgist.h:46
int * mapTuplesToNodes
Definition: spgist.h:126
union spgChooseOut::@41 result
bool prefixHasPrefix
Definition: spgist.h:94
bool allTheSame
Definition: spgist.h:61
void * traversalValue
Definition: spgist.h:171
Datum prefixDatum
Definition: spgist.h:121
Definition: c.h:435
IndexBulkDeleteResult * spgvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: spgvacuum.c:917
struct spgPickSplitIn spgPickSplitIn
bool spgvalidate(Oid opclassoid)
Definition: spgvalidate.c:38
void spgbuildempty(Relation index)
Definition: spginsert.c:157
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition: genam.h:83
IndexBuildResult * spgbuild(Relation heap, Relation index, struct IndexInfo *indexInfo)
Definition: spginsert.c:70