~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/include/access/gist.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * gist.h
 
4
 *        The public API for GiST indexes. This API is exposed to
 
5
 *        individuals implementing GiST indexes, so backward-incompatible
 
6
 *        changes should be made with care.
 
7
 *
 
8
 *
 
9
 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
 
10
 * Portions Copyright (c) 1994, Regents of the University of California
 
11
 *
 
12
 * src/include/access/gist.h
 
13
 *
 
14
 *-------------------------------------------------------------------------
 
15
 */
 
16
#ifndef GIST_H
 
17
#define GIST_H
 
18
 
 
19
#include "access/xlog.h"
 
20
#include "access/xlogdefs.h"
 
21
#include "storage/block.h"
 
22
#include "storage/bufpage.h"
 
23
#include "utils/relcache.h"
 
24
 
 
25
/*
 
26
 * amproc indexes for GiST indexes.
 
27
 */
 
28
#define GIST_CONSISTENT_PROC                    1
 
29
#define GIST_UNION_PROC                                 2
 
30
#define GIST_COMPRESS_PROC                              3
 
31
#define GIST_DECOMPRESS_PROC                    4
 
32
#define GIST_PENALTY_PROC                               5
 
33
#define GIST_PICKSPLIT_PROC                             6
 
34
#define GIST_EQUAL_PROC                                 7
 
35
#define GIST_DISTANCE_PROC                              8
 
36
#define GISTNProcs                                              8
 
37
 
 
38
/*
 
39
 * strategy numbers for GiST opclasses that want to implement the old
 
40
 * RTREE behavior.
 
41
 */
 
42
#define RTLeftStrategyNumber                    1
 
43
#define RTOverLeftStrategyNumber                2
 
44
#define RTOverlapStrategyNumber                 3
 
45
#define RTOverRightStrategyNumber               4
 
46
#define RTRightStrategyNumber                   5
 
47
#define RTSameStrategyNumber                    6
 
48
#define RTContainsStrategyNumber                7               /* for @> */
 
49
#define RTContainedByStrategyNumber             8               /* for <@ */
 
50
#define RTOverBelowStrategyNumber               9
 
51
#define RTBelowStrategyNumber                   10
 
52
#define RTAboveStrategyNumber                   11
 
53
#define RTOverAboveStrategyNumber               12
 
54
#define RTOldContainsStrategyNumber             13              /* for old spelling of @> */
 
55
#define RTOldContainedByStrategyNumber  14              /* for old spelling of <@ */
 
56
#define RTKNNSearchStrategyNumber               15
 
57
 
 
58
/*
 
59
 * Page opaque data in a GiST index page.
 
60
 */
 
61
#define F_LEAF                          (1 << 0)        /* leaf page */
 
62
#define F_DELETED                       (1 << 1)        /* the page has been deleted */
 
63
#define F_TUPLES_DELETED        (1 << 2)        /* some tuples on the page are dead */
 
64
#define F_FOLLOW_RIGHT          (1 << 3)        /* page to the right has no downlink */
 
65
 
 
66
typedef XLogRecPtr GistNSN;
 
67
 
 
68
typedef struct GISTPageOpaqueData
 
69
{
 
70
        GistNSN         nsn;                    /* this value must change on page split */
 
71
        BlockNumber rightlink;          /* next page if any */
 
72
        uint16          flags;                  /* see bit definitions above */
 
73
        uint16          gist_page_id;   /* for identification of GiST indexes */
 
74
} GISTPageOpaqueData;
 
75
 
 
76
typedef GISTPageOpaqueData *GISTPageOpaque;
 
77
 
 
78
/*
 
79
 * The page ID is for the convenience of pg_filedump and similar utilities,
 
80
 * which otherwise would have a hard time telling pages of different index
 
81
 * types apart.  It should be the last 2 bytes on the page.  This is more or
 
82
 * less "free" due to alignment considerations.
 
83
 */
 
84
#define GIST_PAGE_ID            0xFF81
 
85
 
 
86
/*
 
87
 * This is the Split Vector to be returned by the PickSplit method.
 
88
 * PickSplit should check spl_(r|l)datum_exists. If it is 'true',
 
89
 * that corresponding spl_(r|l)datum already defined and
 
90
 * PickSplit should use that value. PickSplit should always set
 
91
 * spl_(r|l)datum_exists to false: GiST will check value to
 
92
 * control supportng this feature by PickSplit...
 
93
 */
 
94
typedef struct GIST_SPLITVEC
 
95
{
 
96
        OffsetNumber *spl_left;         /* array of entries that go left */
 
97
        int                     spl_nleft;              /* size of this array */
 
98
        Datum           spl_ldatum;             /* Union of keys in spl_left */
 
99
        bool            spl_ldatum_exists;              /* true, if spl_ldatum already exists. */
 
100
 
 
101
        OffsetNumber *spl_right;        /* array of entries that go right */
 
102
        int                     spl_nright;             /* size of the array */
 
103
        Datum           spl_rdatum;             /* Union of keys in spl_right */
 
104
        bool            spl_rdatum_exists;              /* true, if spl_rdatum already exists. */
 
105
} GIST_SPLITVEC;
 
106
 
 
107
/*
 
108
 * An entry on a GiST node.  Contains the key, as well as its own
 
109
 * location (rel,page,offset) which can supply the matching pointer.
 
110
 * leafkey is a flag to tell us if the entry is in a leaf node.
 
111
 */
 
112
typedef struct GISTENTRY
 
113
{
 
114
        Datum           key;
 
115
        Relation        rel;
 
116
        Page            page;
 
117
        OffsetNumber offset;
 
118
        bool            leafkey;
 
119
} GISTENTRY;
 
120
 
 
121
#define GistPageGetOpaque(page) ( (GISTPageOpaque) PageGetSpecialPointer(page) )
 
122
 
 
123
#define GistPageIsLeaf(page)    ( GistPageGetOpaque(page)->flags & F_LEAF)
 
124
#define GIST_LEAF(entry) (GistPageIsLeaf((entry)->page))
 
125
#define GistPageSetLeaf(page)   ( GistPageGetOpaque(page)->flags |= F_LEAF)
 
126
#define GistPageSetNonLeaf(page)        ( GistPageGetOpaque(page)->flags &= ~F_LEAF)
 
127
 
 
128
#define GistPageIsDeleted(page) ( GistPageGetOpaque(page)->flags & F_DELETED)
 
129
#define GistPageSetDeleted(page)        ( GistPageGetOpaque(page)->flags |= F_DELETED)
 
130
#define GistPageSetNonDeleted(page) ( GistPageGetOpaque(page)->flags &= ~F_DELETED)
 
131
 
 
132
#define GistTuplesDeleted(page) ( GistPageGetOpaque(page)->flags & F_TUPLES_DELETED)
 
133
#define GistMarkTuplesDeleted(page) ( GistPageGetOpaque(page)->flags |= F_TUPLES_DELETED)
 
134
#define GistClearTuplesDeleted(page)    ( GistPageGetOpaque(page)->flags &= ~F_TUPLES_DELETED)
 
135
 
 
136
#define GistFollowRight(page) ( GistPageGetOpaque(page)->flags & F_FOLLOW_RIGHT)
 
137
#define GistMarkFollowRight(page) ( GistPageGetOpaque(page)->flags |= F_FOLLOW_RIGHT)
 
138
#define GistClearFollowRight(page)      ( GistPageGetOpaque(page)->flags &= ~F_FOLLOW_RIGHT)
 
139
 
 
140
/*
 
141
 * Vector of GISTENTRY structs; user-defined methods union and picksplit
 
142
 * take it as one of their arguments
 
143
 */
 
144
typedef struct
 
145
{
 
146
        int32           n;                              /* number of elements */
 
147
        GISTENTRY       vector[1];              /* variable-length array */
 
148
} GistEntryVector;
 
149
 
 
150
#define GEVHDRSZ        (offsetof(GistEntryVector, vector))
 
151
 
 
152
/*
 
153
 * macro to initialize a GISTENTRY
 
154
 */
 
155
#define gistentryinit(e, k, r, pg, o, l) \
 
156
        do { (e).key = (k); (e).rel = (r); (e).page = (pg); \
 
157
                 (e).offset = (o); (e).leafkey = (l); } while (0)
 
158
 
 
159
#endif   /* GIST_H */