PostgreSQL Source Code git master
Loading...
Searching...
No Matches
gist.h File Reference
#include "access/itup.h"
#include "access/stratnum.h"
#include "access/transam.h"
#include "access/xlog.h"
#include "access/xlogdefs.h"
#include "nodes/primnodes.h"
#include "storage/block.h"
#include "storage/bufpage.h"
#include "utils/relcache.h"
Include dependency graph for gist.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GISTPageOpaqueData
 
struct  GIST_SPLITVEC
 
struct  GISTENTRY
 
struct  GISTDeletedPageContents
 
struct  GistEntryVector
 

Macros

#define GIST_CONSISTENT_PROC   1
 
#define GIST_UNION_PROC   2
 
#define GIST_COMPRESS_PROC   3
 
#define GIST_DECOMPRESS_PROC   4
 
#define GIST_PENALTY_PROC   5
 
#define GIST_PICKSPLIT_PROC   6
 
#define GIST_EQUAL_PROC   7
 
#define GIST_DISTANCE_PROC   8
 
#define GIST_FETCH_PROC   9
 
#define GIST_OPTIONS_PROC   10
 
#define GIST_SORTSUPPORT_PROC   11
 
#define GIST_TRANSLATE_CMPTYPE_PROC   12
 
#define GISTNProcs   12
 
#define F_LEAF   (1 << 0) /* leaf page */
 
#define F_DELETED   (1 << 1) /* the page has been deleted */
 
#define F_TUPLES_DELETED
 
#define F_FOLLOW_RIGHT   (1 << 3) /* page to the right has no downlink */
 
#define F_HAS_GARBAGE
 
#define GistBuildLSN   ((XLogRecPtr) 1)
 
#define GISTMaxIndexTupleSize
 
#define GISTMaxIndexKeySize    (GISTMaxIndexTupleSize - MAXALIGN(sizeof(IndexTupleData)))
 
#define GIST_PAGE_ID   0xFF81
 
#define GistPageGetOpaque(page)   ( (GISTPageOpaque) PageGetSpecialPointer(page) )
 
#define GistPageIsLeaf(page)   ( GistPageGetOpaque(page)->flags & F_LEAF)
 
#define GIST_LEAF(entry)   (GistPageIsLeaf((entry)->page))
 
#define GistPageIsDeleted(page)   ( GistPageGetOpaque(page)->flags & F_DELETED)
 
#define GistTuplesDeleted(page)   ( GistPageGetOpaque(page)->flags & F_TUPLES_DELETED)
 
#define GistMarkTuplesDeleted(page)   ( GistPageGetOpaque(page)->flags |= F_TUPLES_DELETED)
 
#define GistClearTuplesDeleted(page)   ( GistPageGetOpaque(page)->flags &= ~F_TUPLES_DELETED)
 
#define GistPageHasGarbage(page)   ( GistPageGetOpaque(page)->flags & F_HAS_GARBAGE)
 
#define GistMarkPageHasGarbage(page)   ( GistPageGetOpaque(page)->flags |= F_HAS_GARBAGE)
 
#define GistClearPageHasGarbage(page)   ( GistPageGetOpaque(page)->flags &= ~F_HAS_GARBAGE)
 
#define GistFollowRight(page)   ( GistPageGetOpaque(page)->flags & F_FOLLOW_RIGHT)
 
#define GistMarkFollowRight(page)   ( GistPageGetOpaque(page)->flags |= F_FOLLOW_RIGHT)
 
#define GistClearFollowRight(page)   ( GistPageGetOpaque(page)->flags &= ~F_FOLLOW_RIGHT)
 
#define GistPageGetNSN(page)   ( PageXLogRecPtrGet(GistPageGetOpaque(page)->nsn))
 
#define GistPageSetNSN(page, val)   ( PageXLogRecPtrSet(GistPageGetOpaque(page)->nsn, val))
 
#define GEVHDRSZ   (offsetof(GistEntryVector, vector))
 
#define gistentryinit(e, k, r, pg, o, l)
 

Typedefs

typedef XLogRecPtr GistNSN
 
typedef PageXLogRecPtr PageGistNSN
 
typedef struct GISTPageOpaqueData GISTPageOpaqueData
 
typedef GISTPageOpaqueDataGISTPageOpaque
 
typedef struct GIST_SPLITVEC GIST_SPLITVEC
 
typedef struct GISTENTRY GISTENTRY
 
typedef struct GISTDeletedPageContents GISTDeletedPageContents
 

Functions

static void GistPageSetDeleted (Page page, FullTransactionId deletexid)
 
static FullTransactionId GistPageGetDeleteXid (Page page)
 
StrategyNumber gisttranslatecmptype (CompareType cmptype, Oid opfamily)
 

Macro Definition Documentation

◆ F_DELETED

#define F_DELETED   (1 << 1) /* the page has been deleted */

Definition at line 50 of file gist.h.

◆ F_FOLLOW_RIGHT

#define F_FOLLOW_RIGHT   (1 << 3) /* page to the right has no downlink */

Definition at line 52 of file gist.h.

◆ F_HAS_GARBAGE

#define F_HAS_GARBAGE
Value:
(1 << 4) /* some tuples on the page are dead,
* but not deleted yet */

Definition at line 53 of file gist.h.

81{
82 PageGistNSN nsn; /* this value must change on page split */
83 BlockNumber rightlink; /* next page if any */
84 uint16 flags; /* see bit definitions above */
85 uint16 gist_page_id; /* for identification of GiST indexes */
87
89
90/*
91 * Maximum possible sizes for GiST index tuple and index key. Calculation is
92 * based on assumption that GiST page should fit at least 4 tuples. In theory,
93 * GiST index can be functional when page can fit 3 tuples. But that seems
94 * rather inefficient, so we use a bit conservative estimate.
95 *
96 * The maximum size of index key is true for unicolumn index. Therefore, this
97 * estimation should be used to figure out which maximum size of GiST index key
98 * makes sense at all. For multicolumn indexes, user might be able to tune
99 * key size using opclass parameters.
100 */
101#define GISTMaxIndexTupleSize \
102 MAXALIGN_DOWN((BLCKSZ - SizeOfPageHeaderData - sizeof(GISTPageOpaqueData)) / \
103 4 - sizeof(ItemIdData))
104
105#define GISTMaxIndexKeySize \
106 (GISTMaxIndexTupleSize - MAXALIGN(sizeof(IndexTupleData)))
107
108/*
109 * The page ID is for the convenience of pg_filedump and similar utilities,
110 * which otherwise would have a hard time telling pages of different index
111 * types apart. It should be the last 2 bytes on the page. This is more or
112 * less "free" due to alignment considerations.
113 */
114#define GIST_PAGE_ID 0xFF81
115
116/*
117 * This is the Split Vector to be returned by the PickSplit method.
118 * PickSplit should fill the indexes of tuples to go to the left side into
119 * spl_left[], and those to go to the right into spl_right[] (note the method
120 * is responsible for palloc'ing both of these arrays!). The tuple counts
121 * go into spl_nleft/spl_nright, and spl_ldatum/spl_rdatum must be set to
122 * the union keys for each side.
123 *
124 * If spl_ldatum_exists and spl_rdatum_exists are true, then we are performing
125 * a "secondary split" using a non-first index column. In this case some
126 * decisions have already been made about a page split, and the set of tuples
127 * being passed to PickSplit is just the tuples about which we are undecided.
128 * spl_ldatum/spl_rdatum then contain the union keys for the tuples already
129 * chosen to go left or right. Ideally the PickSplit method should take those
130 * keys into account while deciding what to do with the remaining tuples, ie
131 * it should try to "build out" from those unions so as to minimally expand
132 * them. If it does so, it should union the given tuples' keys into the
133 * existing spl_ldatum/spl_rdatum values rather than just setting those values
134 * from scratch, and then set spl_ldatum_exists/spl_rdatum_exists to false to
135 * show it has done this.
136 *
137 * If the PickSplit method fails to clear spl_ldatum_exists/spl_rdatum_exists,
138 * the core GiST code will make its own decision about how to merge the
139 * secondary-split results with the previously-chosen tuples, and will then
140 * recompute the union keys from scratch. This is a workable though often not
141 * optimal approach.
142 */
143typedef struct GIST_SPLITVEC
144{
145 OffsetNumber *spl_left; /* array of entries that go left */
146 int spl_nleft; /* size of this array */
147 Datum spl_ldatum; /* Union of keys in spl_left */
148 bool spl_ldatum_exists; /* true, if spl_ldatum already exists. */
149
150 OffsetNumber *spl_right; /* array of entries that go right */
151 int spl_nright; /* size of the array */
152 Datum spl_rdatum; /* Union of keys in spl_right */
153 bool spl_rdatum_exists; /* true, if spl_rdatum already exists. */
155
156/*
157 * An entry on a GiST node. Contains the key, as well as its own
158 * location (rel,page,offset) which can supply the matching pointer.
159 * leafkey is a flag to tell us if the entry is in a leaf node.
160 */
161typedef struct GISTENTRY
162{
163 Datum key;
165 Page page;
167 bool leafkey;
168} GISTENTRY;
169
170#define GistPageGetOpaque(page) ( (GISTPageOpaque) PageGetSpecialPointer(page) )
171
172#define GistPageIsLeaf(page) ( GistPageGetOpaque(page)->flags & F_LEAF)
173#define GIST_LEAF(entry) (GistPageIsLeaf((entry)->page))
174
175#define GistPageIsDeleted(page) ( GistPageGetOpaque(page)->flags & F_DELETED)
176
177#define GistTuplesDeleted(page) ( GistPageGetOpaque(page)->flags & F_TUPLES_DELETED)
178#define GistMarkTuplesDeleted(page) ( GistPageGetOpaque(page)->flags |= F_TUPLES_DELETED)
179#define GistClearTuplesDeleted(page) ( GistPageGetOpaque(page)->flags &= ~F_TUPLES_DELETED)
180
181#define GistPageHasGarbage(page) ( GistPageGetOpaque(page)->flags & F_HAS_GARBAGE)
182#define GistMarkPageHasGarbage(page) ( GistPageGetOpaque(page)->flags |= F_HAS_GARBAGE)
183#define GistClearPageHasGarbage(page) ( GistPageGetOpaque(page)->flags &= ~F_HAS_GARBAGE)
184
185#define GistFollowRight(page) ( GistPageGetOpaque(page)->flags & F_FOLLOW_RIGHT)
186#define GistMarkFollowRight(page) ( GistPageGetOpaque(page)->flags |= F_FOLLOW_RIGHT)
187#define GistClearFollowRight(page) ( GistPageGetOpaque(page)->flags &= ~F_FOLLOW_RIGHT)
188
189#define GistPageGetNSN(page) ( PageXLogRecPtrGet(GistPageGetOpaque(page)->nsn))
190#define GistPageSetNSN(page, val) ( PageXLogRecPtrSet(GistPageGetOpaque(page)->nsn, val))
191
192
193/*
194 * On a deleted page, we store this struct. A deleted page doesn't contain any
195 * tuples, so we don't use the normal page layout with line pointers. Instead,
196 * this struct is stored right after the standard page header. pd_lower points
197 * to the end of this struct. If we add fields to this struct in the future, we
198 * can distinguish the old and new formats by pd_lower.
199 */
200typedef struct GISTDeletedPageContents
201{
202 /* last xid which could see the page in a scan */
205
206static inline void
208{
209 Assert(PageIsEmpty(page));
210
211 GistPageGetOpaque(page)->flags |= F_DELETED;
212 ((PageHeader) page)->pd_lower = MAXALIGN(SizeOfPageHeaderData) + sizeof(GISTDeletedPageContents);
213
214 ((GISTDeletedPageContents *) PageGetContents(page))->deleteXid = deletexid;
215}
216
217static inline FullTransactionId
219{
221
222 /* Is the deleteXid field present? */
223 if (((PageHeader) page)->pd_lower >= MAXALIGN(SizeOfPageHeaderData) +
225 {
226 return ((GISTDeletedPageContents *) PageGetContents(page))->deleteXid;
227 }
228 else
230}
231
232/*
233 * Vector of GISTENTRY structs; user-defined methods union and picksplit
234 * take it as one of their arguments
235 */
236typedef struct
237{
238 int32 n; /* number of elements */
241
242#define GEVHDRSZ (offsetof(GistEntryVector, vector))
243
244/*
245 * macro to initialize a GISTENTRY
246 */
247#define gistentryinit(e, k, r, pg, o, l) \
248 do { (e).key = (k); (e).rel = (r); (e).page = (pg); \
249 (e).offset = (o); (e).leafkey = (l); } while (0)
250
251extern StrategyNumber gisttranslatecmptype(CompareType cmptype, Oid opfamily);
252
253#endif /* GIST_H */
uint32 BlockNumber
Definition block.h:31
static bool PageIsEmpty(const PageData *page)
Definition bufpage.h:223
PageHeaderData * PageHeader
Definition bufpage.h:173
#define SizeOfPageHeaderData
Definition bufpage.h:216
static char * PageGetContents(Page page)
Definition bufpage.h:257
PageData * Page
Definition bufpage.h:81
#define MAXALIGN(LEN)
Definition c.h:826
#define Assert(condition)
Definition c.h:873
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:480
int32_t int32
Definition c.h:542
uint16_t uint16
Definition c.h:545
CompareType
Definition cmptype.h:32
GISTPageOpaqueData * GISTPageOpaque
Definition gist.h:86
static void GistPageSetDeleted(Page page, FullTransactionId deletexid)
Definition gist.h:205
static FullTransactionId GistPageGetDeleteXid(Page page)
Definition gist.h:216
#define GistPageIsDeleted(page)
Definition gist.h:173
#define GistPageGetOpaque(page)
Definition gist.h:168
StrategyNumber gisttranslatecmptype(CompareType cmptype, Oid opfamily)
Definition gistutil.c:1098
#define F_DELETED
Definition gist.h:50
uint16 OffsetNumber
Definition off.h:24
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
static int fb(int x)
uint16 StrategyNumber
Definition stratnum.h:22
FullTransactionId deleteXid
Definition gist.h:201
OffsetNumber offset
Definition gist.h:164
Datum key
Definition gist.h:161
Page page
Definition gist.h:163
Relation rel
Definition gist.h:162
bool leafkey
Definition gist.h:165
bool spl_ldatum_exists
Definition gist.h:146
bool spl_rdatum_exists
Definition gist.h:151
int spl_nleft
Definition gist.h:144
OffsetNumber * spl_right
Definition gist.h:148
Datum spl_ldatum
Definition gist.h:145
Datum spl_rdatum
Definition gist.h:150
int spl_nright
Definition gist.h:149
OffsetNumber * spl_left
Definition gist.h:143
#define FirstNormalTransactionId
Definition transam.h:34
static FullTransactionId FullTransactionIdFromEpochAndXid(uint32 epoch, TransactionId xid)
Definition transam.h:71

◆ F_LEAF

#define F_LEAF   (1 << 0) /* leaf page */

Definition at line 49 of file gist.h.

◆ F_TUPLES_DELETED

#define F_TUPLES_DELETED
Value:
(1 << 2) /* some tuples on the page were
* deleted */

Definition at line 51 of file gist.h.

◆ GEVHDRSZ

#define GEVHDRSZ   (offsetof(GistEntryVector, vector))

Definition at line 240 of file gist.h.

◆ GIST_COMPRESS_PROC

#define GIST_COMPRESS_PROC   3

Definition at line 34 of file gist.h.

◆ GIST_CONSISTENT_PROC

#define GIST_CONSISTENT_PROC   1

Definition at line 32 of file gist.h.

◆ GIST_DECOMPRESS_PROC

#define GIST_DECOMPRESS_PROC   4

Definition at line 35 of file gist.h.

◆ GIST_DISTANCE_PROC

#define GIST_DISTANCE_PROC   8

Definition at line 39 of file gist.h.

◆ GIST_EQUAL_PROC

#define GIST_EQUAL_PROC   7

Definition at line 38 of file gist.h.

◆ GIST_FETCH_PROC

#define GIST_FETCH_PROC   9

Definition at line 40 of file gist.h.

◆ GIST_LEAF

#define GIST_LEAF (   entry)    (GistPageIsLeaf((entry)->page))

Definition at line 171 of file gist.h.

◆ GIST_OPTIONS_PROC

#define GIST_OPTIONS_PROC   10

Definition at line 41 of file gist.h.

◆ GIST_PAGE_ID

#define GIST_PAGE_ID   0xFF81

Definition at line 112 of file gist.h.

◆ GIST_PENALTY_PROC

#define GIST_PENALTY_PROC   5

Definition at line 36 of file gist.h.

◆ GIST_PICKSPLIT_PROC

#define GIST_PICKSPLIT_PROC   6

Definition at line 37 of file gist.h.

◆ GIST_SORTSUPPORT_PROC

#define GIST_SORTSUPPORT_PROC   11

Definition at line 42 of file gist.h.

◆ GIST_TRANSLATE_CMPTYPE_PROC

#define GIST_TRANSLATE_CMPTYPE_PROC   12

Definition at line 43 of file gist.h.

◆ GIST_UNION_PROC

#define GIST_UNION_PROC   2

Definition at line 33 of file gist.h.

◆ GistBuildLSN

#define GistBuildLSN   ((XLogRecPtr) 1)

Definition at line 70 of file gist.h.

◆ GistClearFollowRight

#define GistClearFollowRight (   page)    ( GistPageGetOpaque(page)->flags &= ~F_FOLLOW_RIGHT)

Definition at line 185 of file gist.h.

◆ GistClearPageHasGarbage

#define GistClearPageHasGarbage (   page)    ( GistPageGetOpaque(page)->flags &= ~F_HAS_GARBAGE)

Definition at line 181 of file gist.h.

◆ GistClearTuplesDeleted

#define GistClearTuplesDeleted (   page)    ( GistPageGetOpaque(page)->flags &= ~F_TUPLES_DELETED)

Definition at line 177 of file gist.h.

◆ gistentryinit

#define gistentryinit (   e,
  k,
  r,
  pg,
  o,
 
)
Value:
do { (e).key = (k); (e).rel = (r); (e).page = (pg); \
(e).offset = (o); (e).leafkey = (l); } while (0)
e

Definition at line 245 of file gist.h.

◆ GistFollowRight

#define GistFollowRight (   page)    ( GistPageGetOpaque(page)->flags & F_FOLLOW_RIGHT)

Definition at line 183 of file gist.h.

◆ GistMarkFollowRight

#define GistMarkFollowRight (   page)    ( GistPageGetOpaque(page)->flags |= F_FOLLOW_RIGHT)

Definition at line 184 of file gist.h.

◆ GistMarkPageHasGarbage

#define GistMarkPageHasGarbage (   page)    ( GistPageGetOpaque(page)->flags |= F_HAS_GARBAGE)

Definition at line 180 of file gist.h.

◆ GistMarkTuplesDeleted

#define GistMarkTuplesDeleted (   page)    ( GistPageGetOpaque(page)->flags |= F_TUPLES_DELETED)

Definition at line 176 of file gist.h.

◆ GISTMaxIndexKeySize

#define GISTMaxIndexKeySize    (GISTMaxIndexTupleSize - MAXALIGN(sizeof(IndexTupleData)))

Definition at line 103 of file gist.h.

◆ GISTMaxIndexTupleSize

#define GISTMaxIndexTupleSize
Value:
4 - sizeof(ItemIdData))
#define MAXALIGN_DOWN(LEN)
Definition c.h:838

Definition at line 99 of file gist.h.

◆ GISTNProcs

#define GISTNProcs   12

Definition at line 44 of file gist.h.

◆ GistPageGetNSN

#define GistPageGetNSN (   page)    ( PageXLogRecPtrGet(GistPageGetOpaque(page)->nsn))

Definition at line 187 of file gist.h.

◆ GistPageGetOpaque

#define GistPageGetOpaque (   page)    ( (GISTPageOpaque) PageGetSpecialPointer(page) )

Definition at line 168 of file gist.h.

◆ GistPageHasGarbage

#define GistPageHasGarbage (   page)    ( GistPageGetOpaque(page)->flags & F_HAS_GARBAGE)

Definition at line 179 of file gist.h.

◆ GistPageIsDeleted

#define GistPageIsDeleted (   page)    ( GistPageGetOpaque(page)->flags & F_DELETED)

Definition at line 173 of file gist.h.

◆ GistPageIsLeaf

#define GistPageIsLeaf (   page)    ( GistPageGetOpaque(page)->flags & F_LEAF)

Definition at line 170 of file gist.h.

◆ GistPageSetNSN

#define GistPageSetNSN (   page,
  val 
)    ( PageXLogRecPtrSet(GistPageGetOpaque(page)->nsn, val))

Definition at line 188 of file gist.h.

◆ GistTuplesDeleted

#define GistTuplesDeleted (   page)    ( GistPageGetOpaque(page)->flags & F_TUPLES_DELETED)

Definition at line 175 of file gist.h.

Typedef Documentation

◆ GIST_SPLITVEC

◆ GISTDeletedPageContents

◆ GISTENTRY

◆ GistNSN

Definition at line 63 of file gist.h.

◆ GISTPageOpaque

Definition at line 86 of file gist.h.

◆ GISTPageOpaqueData

◆ PageGistNSN

Definition at line 76 of file gist.h.

Function Documentation

◆ GistPageGetDeleteXid()

static FullTransactionId GistPageGetDeleteXid ( Page  page)
inlinestatic

Definition at line 216 of file gist.h.

219{
221
222 /* Is the deleteXid field present? */
223 if (((PageHeader) page)->pd_lower >= MAXALIGN(SizeOfPageHeaderData) +
225 {
226 return ((GISTDeletedPageContents *) PageGetContents(page))->deleteXid;
227 }
228 else

References Assert, fb(), FirstNormalTransactionId, FullTransactionIdFromEpochAndXid(), GistPageIsDeleted, MAXALIGN, PageGetContents(), and SizeOfPageHeaderData.

Referenced by gistNewBuffer(), and gistPageRecyclable().

◆ GistPageSetDeleted()

static void GistPageSetDeleted ( Page  page,
FullTransactionId  deletexid 
)
inlinestatic

Definition at line 205 of file gist.h.

208{
209 Assert(PageIsEmpty(page));
210
211 GistPageGetOpaque(page)->flags |= F_DELETED;
212 ((PageHeader) page)->pd_lower = MAXALIGN(SizeOfPageHeaderData) + sizeof(GISTDeletedPageContents);
213

References Assert, F_DELETED, fb(), GistPageGetOpaque, MAXALIGN, PageGetContents(), PageIsEmpty(), and SizeOfPageHeaderData.

Referenced by gistdeletepage(), and gistRedoPageDelete().

◆ gisttranslatecmptype()

StrategyNumber gisttranslatecmptype ( CompareType  cmptype,
Oid  opfamily 
)
extern

Definition at line 1098 of file gistutil.c.

1099{
1100 Oid funcid;
1101 Datum result;
1102
1103 /* Check whether the function is provided. */
1105 if (!OidIsValid(funcid))
1106 return InvalidStrategy;
1107
1108 /* Ask the translation function */
1109 result = OidFunctionCall1Coll(funcid, InvalidOid, Int32GetDatum(cmptype));
1110 return DatumGetUInt16(result);
1111}
#define OidIsValid(objectId)
Definition c.h:788
Datum OidFunctionCall1Coll(Oid functionId, Oid collation, Datum arg1)
Definition fmgr.c:1412
#define GIST_TRANSLATE_CMPTYPE_PROC
Definition gist.h:43
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
Definition lsyscache.c:872
static uint16 DatumGetUInt16(Datum X)
Definition postgres.h:192
static Datum Int32GetDatum(int32 X)
Definition postgres.h:222
#define InvalidOid
#define InvalidStrategy
Definition stratnum.h:24

References DatumGetUInt16(), fb(), get_opfamily_proc(), GIST_TRANSLATE_CMPTYPE_PROC, Int32GetDatum(), InvalidOid, InvalidStrategy, OidFunctionCall1Coll(), and OidIsValid.

Referenced by gisthandler().