]> granicus.if.org Git - postgresql/blob - src/include/access/gist.h
Updates to make GIST work with multi-key indexes (from Oleg Bartunov
[postgresql] / src / include / access / gist.h
1 /*-------------------------------------------------------------------------
2  *
3  * gist.h
4  *        common declarations for the GiST access method code.
5  *
6  *
7  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: gist.h,v 1.28 2001/05/31 18:16:55 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef GIST_H
15 #define GIST_H
16
17 #include "access/itup.h"
18 #include "access/relscan.h"
19 #include "access/sdir.h"
20 #include "access/xlog.h"
21
22 /*
23  * You can have as many strategies as you please in GiSTs,
24  * as long as your consistent method can handle them.
25  * The system doesn't really care what they are.
26  */
27 #define GISTNStrategies                                 100
28
29 /*
30  * amproc indexes for GiST indexes.
31  */
32 #define GIST_CONSISTENT_PROC                    1
33 #define GIST_UNION_PROC                                 2
34 #define GIST_COMPRESS_PROC                              3
35 #define GIST_DECOMPRESS_PROC                    4
36 #define GIST_PENALTY_PROC                               5
37 #define GIST_PICKSPLIT_PROC                             6
38 #define GIST_EQUAL_PROC                                 7
39 #define GISTNProcs                                              7
40
41
42 /*
43  * Page opaque data in a GiST index page.
44  */
45 #define F_LEAF                  (1 << 0)
46
47 typedef struct GISTPageOpaqueData
48 {
49         uint32          flags;
50 } GISTPageOpaqueData;
51
52 typedef GISTPageOpaqueData *GISTPageOpaque;
53
54 #define GIST_LEAF(entry) (((GISTPageOpaque) PageGetSpecialPointer((entry)->page))->flags & F_LEAF)
55
56 /*
57  *      When we descend a tree, we keep a stack of parent pointers.
58  */
59 typedef struct GISTSTACK
60 {
61         struct GISTSTACK *gs_parent;
62         OffsetNumber gs_child;
63         BlockNumber gs_blk;
64 } GISTSTACK;
65
66 typedef struct GISTSTATE
67 {
68         FmgrInfo        consistentFn[INDEX_MAX_KEYS];
69         FmgrInfo        unionFn[INDEX_MAX_KEYS];
70         FmgrInfo        compressFn[INDEX_MAX_KEYS];
71         FmgrInfo        decompressFn[INDEX_MAX_KEYS];
72         FmgrInfo        penaltyFn[INDEX_MAX_KEYS];
73         FmgrInfo        picksplitFn[INDEX_MAX_KEYS];
74         FmgrInfo        equalFn[INDEX_MAX_KEYS];
75         bool            haskeytype;
76         bool            keytypbyval;
77 } GISTSTATE;
78
79
80 /*
81  *      When we're doing a scan, we need to keep track of the parent stack
82  *      for the marked and current items.
83  */
84 typedef struct GISTScanOpaqueData
85 {
86         struct GISTSTACK *s_stack;
87         struct GISTSTACK *s_markstk;
88         uint16          s_flags;
89         struct GISTSTATE *giststate;
90 } GISTScanOpaqueData;
91
92 typedef GISTScanOpaqueData *GISTScanOpaque;
93
94 /*
95  *      When we're doing a scan and updating a tree at the same time, the
96  *      updates may affect the scan.  We use the flags entry of the scan's
97  *      opaque space to record our actual position in response to updates
98  *      that we can't handle simply by adjusting pointers.
99  */
100 #define GS_CURBEFORE    ((uint16) (1 << 0))
101 #define GS_MRKBEFORE    ((uint16) (1 << 1))
102
103 /* root page of a gist */
104 #define GISTP_ROOT                              0
105
106 /*
107  *      When we update a relation on which we're doing a scan, we need to
108  *      check the scan and fix it if the update affected any of the pages it
109  *      touches.  Otherwise, we can miss records that we should see.  The only
110  *      times we need to do this are for deletions and splits.  See the code in
111  *      gistscan.c for how the scan is fixed. These two constants tell us what sort
112  *      of operation changed the index.
113  */
114 #define GISTOP_DEL              0
115 #define GISTOP_SPLIT    1
116
117 /*
118  * This is the Split Vector to be returned by the PickSplit method.
119  */
120 typedef struct GIST_SPLITVEC
121 {
122         OffsetNumber *spl_left;         /* array of entries that go left */
123         int                     spl_nleft;              /* size of this array */
124         Datum           spl_ldatum;             /* Union of keys in spl_left */
125         Datum           spl_lattr[INDEX_MAX_KEYS];  /* Union of subkeys in spl_left */
126         int        spl_lattrsize[INDEX_MAX_KEYS];
127
128         OffsetNumber *spl_right;        /* array of entries that go right */
129         int                     spl_nright;             /* size of the array */
130         Datum           spl_rdatum;             /* Union of keys in spl_right */
131         Datum           spl_rattr[INDEX_MAX_KEYS];  /* Union of subkeys in spl_right */
132         int        spl_rattrsize[INDEX_MAX_KEYS];
133
134         int     *spl_idgrp;
135         int     *spl_ngrp;                 /* number in each group */
136         char    *spl_grpflag;              /* flags of each group */
137 } GIST_SPLITVEC;
138
139 /*
140  * An entry on a GiST node.  Contains the key, as well as
141  * its own location (rel,page,offset) which can supply the matching
142  * pointer.  The size of the key is in bytes, and leafkey is a flag to
143  * tell us if the entry is in a leaf node.
144  */
145 typedef struct GISTENTRY
146 {
147         Datum           key;
148         Relation        rel;
149         Page            page;
150         OffsetNumber offset;
151         int                     bytes;
152         bool            leafkey;
153 } GISTENTRY;
154
155 /*
156  * macro to initialize a GISTENTRY
157  */
158 #define gistentryinit(e, k, r, pg, o, b, l) \
159         do { (e).key = (k); (e).rel = (r); (e).page = (pg); \
160                  (e).offset = (o); (e).bytes = (b); (e).leafkey = (l); } while (0)
161
162 /* gist.c */
163 extern Datum gistbuild(PG_FUNCTION_ARGS);
164 extern Datum gistinsert(PG_FUNCTION_ARGS);
165 extern Datum gistdelete(PG_FUNCTION_ARGS);
166 extern void _gistdump(Relation r);
167 extern void gistfreestack(GISTSTACK *s);
168 extern void initGISTstate(GISTSTATE *giststate, Relation index);
169 extern void gistdentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e,
170                                                    Datum k, Relation r, Page pg, OffsetNumber o,
171                                                    int b, bool l);
172 extern StrategyNumber RelationGetGISTStrategy(Relation, AttrNumber,
173                                                                                           RegProcedure);
174
175 extern void gist_redo(XLogRecPtr lsn, XLogRecord *record);
176 extern void gist_undo(XLogRecPtr lsn, XLogRecord *record);
177 extern void gist_desc(char *buf, uint8 xl_info, char *rec);
178
179 /* gistget.c */
180 extern Datum gistgettuple(PG_FUNCTION_ARGS);
181
182 #endif   /* GIST_H */