1 /*-------------------------------------------------------------------------
4 * common declarations for the GiST access method code.
7 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: gist.h,v 1.28 2001/05/31 18:16:55 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "access/itup.h"
18 #include "access/relscan.h"
19 #include "access/sdir.h"
20 #include "access/xlog.h"
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.
27 #define GISTNStrategies 100
30 * amproc indexes for GiST indexes.
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
43 * Page opaque data in a GiST index page.
45 #define F_LEAF (1 << 0)
47 typedef struct GISTPageOpaqueData
52 typedef GISTPageOpaqueData *GISTPageOpaque;
54 #define GIST_LEAF(entry) (((GISTPageOpaque) PageGetSpecialPointer((entry)->page))->flags & F_LEAF)
57 * When we descend a tree, we keep a stack of parent pointers.
59 typedef struct GISTSTACK
61 struct GISTSTACK *gs_parent;
62 OffsetNumber gs_child;
66 typedef struct GISTSTATE
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];
81 * When we're doing a scan, we need to keep track of the parent stack
82 * for the marked and current items.
84 typedef struct GISTScanOpaqueData
86 struct GISTSTACK *s_stack;
87 struct GISTSTACK *s_markstk;
89 struct GISTSTATE *giststate;
92 typedef GISTScanOpaqueData *GISTScanOpaque;
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.
100 #define GS_CURBEFORE ((uint16) (1 << 0))
101 #define GS_MRKBEFORE ((uint16) (1 << 1))
103 /* root page of a gist */
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.
115 #define GISTOP_SPLIT 1
118 * This is the Split Vector to be returned by the PickSplit method.
120 typedef struct GIST_SPLITVEC
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];
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];
135 int *spl_ngrp; /* number in each group */
136 char *spl_grpflag; /* flags of each group */
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.
145 typedef struct GISTENTRY
156 * macro to initialize a GISTENTRY
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)
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,
172 extern StrategyNumber RelationGetGISTStrategy(Relation, AttrNumber,
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);
180 extern Datum gistgettuple(PG_FUNCTION_ARGS);