PostgreSQL Source Code  git master
spgist_private.h File Reference
#include "access/itup.h"
#include "access/spgist.h"
#include "catalog/pg_am_d.h"
#include "nodes/tidbitmap.h"
#include "storage/buf.h"
#include "utils/geo_decls.h"
#include "utils/relcache.h"
Include dependency graph for spgist_private.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SpGistOptions
 
struct  SpGistPageOpaqueData
 
struct  SpGistLastUsedPage
 
struct  SpGistLUPCache
 
struct  SpGistMetaPageData
 
struct  SpGistTypeDesc
 
struct  SpGistState
 
struct  SpGistSearchItem
 
struct  SpGistScanOpaqueData
 
struct  SpGistCache
 
struct  SpGistInnerTupleData
 
struct  SpGistLeafTupleData
 
struct  SpGistDeadTupleData
 

Macros

#define SpGistGetFillFactor(relation)
 
#define SpGistGetTargetPageFreeSpace(relation)   (BLCKSZ * (100 - SpGistGetFillFactor(relation)) / 100)
 
#define SPGIST_METAPAGE_BLKNO   (0) /* metapage */
 
#define SPGIST_ROOT_BLKNO   (1) /* root for normal entries */
 
#define SPGIST_NULL_BLKNO   (2) /* root for null-value entries */
 
#define SPGIST_LAST_FIXED_BLKNO   SPGIST_NULL_BLKNO
 
#define SpGistBlockIsRoot(blkno)   ((blkno) == SPGIST_ROOT_BLKNO || (blkno) == SPGIST_NULL_BLKNO)
 
#define SpGistBlockIsFixed(blkno)   ((BlockNumber) (blkno) <= (BlockNumber) SPGIST_LAST_FIXED_BLKNO)
 
#define SPGIST_META   (1<<0)
 
#define SPGIST_DELETED
 
#define SPGIST_LEAF   (1<<2)
 
#define SPGIST_NULLS   (1<<3)
 
#define SpGistPageGetOpaque(page)   ((SpGistPageOpaque) PageGetSpecialPointer(page))
 
#define SpGistPageIsMeta(page)   (SpGistPageGetOpaque(page)->flags & SPGIST_META)
 
#define SpGistPageIsDeleted(page)   (SpGistPageGetOpaque(page)->flags & SPGIST_DELETED)
 
#define SpGistPageIsLeaf(page)   (SpGistPageGetOpaque(page)->flags & SPGIST_LEAF)
 
#define SpGistPageStoresNulls(page)   (SpGistPageGetOpaque(page)->flags & SPGIST_NULLS)
 
#define SPGIST_PAGE_ID   0xFF82
 
#define SPGIST_CACHED_PAGES   8
 
#define SPGIST_MAGIC_NUMBER   (0xBA0BABEE)
 
#define SpGistPageGetMeta(p)   ((SpGistMetaPageData *) PageGetContents(p))
 
#define SizeOfSpGistSearchItem(n_distances)   (offsetof(SpGistSearchItem, distances) + sizeof(double) * (n_distances))
 
#define SPGIST_LIVE   0 /* normal live tuple (either inner or leaf) */
 
#define SPGIST_REDIRECT   1 /* temporary redirection placeholder */
 
#define SPGIST_DEAD   2 /* dead, cannot be removed because of links */
 
#define SPGIST_PLACEHOLDER   3 /* placeholder, used to preserve offsets */
 
#define SGITMAXNNODES   0x1FFF
 
#define SGITMAXPREFIXSIZE   0xFFFF
 
#define SGITMAXSIZE   0xFFFF
 
#define SGITHDRSZ   MAXALIGN(sizeof(SpGistInnerTupleData))
 
#define _SGITDATA(x)   (((char *) (x)) + SGITHDRSZ)
 
#define SGITDATAPTR(x)   ((x)->prefixSize ? _SGITDATA(x) : NULL)
 
#define SGITDATUM(x, s)
 
#define SGITNODEPTR(x)   ((SpGistNodeTuple) (_SGITDATA(x) + (x)->prefixSize))
 
#define SGITITERATE(x, i, nt)
 
#define SGNTHDRSZ   MAXALIGN(sizeof(SpGistNodeTupleData))
 
#define SGNTDATAPTR(x)   (((char *) (x)) + SGNTHDRSZ)
 
#define SGNTDATUM(x, s)
 
#define SGLTHDRSZ   MAXALIGN(sizeof(SpGistLeafTupleData))
 
#define SGLTDATAPTR(x)   (((char *) (x)) + SGLTHDRSZ)
 
#define SGLTDATUM(x, s)
 
#define SGDTSIZE   MAXALIGN(sizeof(SpGistDeadTupleData))
 
#define SPGIST_PAGE_CAPACITY
 
#define SpGistPageGetFreeSpace(p, n)
 
#define STORE_STATE(s, d)
 
#define GBUF_LEAF   0x03
 
#define GBUF_INNER_PARITY(x)   ((x) % 3)
 
#define GBUF_NULLS   0x04
 
#define GBUF_PARITY_MASK   0x03
 
#define GBUF_REQ_LEAF(flags)   (((flags) & GBUF_PARITY_MASK) == GBUF_LEAF)
 
#define GBUF_REQ_NULLS(flags)   ((flags) & GBUF_NULLS)
 
#define SPGIST_MIN_FILLFACTOR   10
 
#define SPGIST_DEFAULT_FILLFACTOR   80
 

Typedefs

typedef struct SpGistOptions SpGistOptions
 
typedef struct SpGistPageOpaqueData SpGistPageOpaqueData
 
typedef SpGistPageOpaqueDataSpGistPageOpaque
 
typedef struct SpGistLastUsedPage SpGistLastUsedPage
 
typedef struct SpGistLUPCache SpGistLUPCache
 
typedef struct SpGistMetaPageData SpGistMetaPageData
 
typedef struct SpGistTypeDesc SpGistTypeDesc
 
typedef struct SpGistState SpGistState
 
typedef struct SpGistSearchItem SpGistSearchItem
 
typedef struct SpGistScanOpaqueData SpGistScanOpaqueData
 
typedef SpGistScanOpaqueDataSpGistScanOpaque
 
typedef struct SpGistCache SpGistCache
 
typedef struct SpGistInnerTupleData SpGistInnerTupleData
 
typedef SpGistInnerTupleDataSpGistInnerTuple
 
typedef IndexTupleData SpGistNodeTupleData
 
typedef SpGistNodeTupleDataSpGistNodeTuple
 
typedef struct SpGistLeafTupleData SpGistLeafTupleData
 
typedef SpGistLeafTupleDataSpGistLeafTuple
 
typedef struct SpGistDeadTupleData SpGistDeadTupleData
 
typedef SpGistDeadTupleDataSpGistDeadTuple
 

Functions

SpGistCachespgGetCache (Relation index)
 
void initSpGistState (SpGistState *state, Relation index)
 
Buffer SpGistNewBuffer (Relation index)
 
void SpGistUpdateMetaPage (Relation index)
 
Buffer SpGistGetBuffer (Relation index, int flags, int needSpace, bool *isNew)
 
void SpGistSetLastUsedPage (Relation index, Buffer buffer)
 
void SpGistInitPage (Page page, uint16 f)
 
void SpGistInitBuffer (Buffer b, uint16 f)
 
void SpGistInitMetapage (Page page)
 
unsigned int SpGistGetTypeSize (SpGistTypeDesc *att, Datum datum)
 
SpGistLeafTuple spgFormLeafTuple (SpGistState *state, ItemPointer heapPtr, Datum datum, bool isnull)
 
SpGistNodeTuple spgFormNodeTuple (SpGistState *state, Datum label, bool isnull)
 
SpGistInnerTuple spgFormInnerTuple (SpGistState *state, bool hasPrefix, Datum prefix, int nNodes, SpGistNodeTuple *nodes)
 
SpGistDeadTuple spgFormDeadTuple (SpGistState *state, int tupstate, BlockNumber blkno, OffsetNumber offnum)
 
DatumspgExtractNodeLabels (SpGistState *state, SpGistInnerTuple innerTuple)
 
OffsetNumber SpGistPageAddNewItem (SpGistState *state, Page page, Item item, Size size, OffsetNumber *startOffset, bool errorOK)
 
bool spgproperty (Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
 
void spgUpdateNodeLink (SpGistInnerTuple tup, int nodeN, BlockNumber blkno, OffsetNumber offset)
 
void spgPageIndexMultiDelete (SpGistState *state, Page page, OffsetNumber *itemnos, int nitems, int firststate, int reststate, BlockNumber blkno, OffsetNumber offnum)
 
bool spgdoinsert (Relation index, SpGistState *state, ItemPointer heapPtr, Datum datum, bool isnull)
 
double * spg_key_orderbys_distances (Datum key, bool isLeaf, ScanKey orderbys, int norderbys)
 
BOXbox_copy (BOX *orig)
 

Macro Definition Documentation

◆ _SGITDATA

#define _SGITDATA (   x)    (((char *) (x)) + SGITHDRSZ)

Definition at line 289 of file spgist_private.h.

◆ GBUF_INNER_PARITY

#define GBUF_INNER_PARITY (   x)    ((x) % 3)

◆ GBUF_LEAF

#define GBUF_LEAF   0x03

Definition at line 434 of file spgist_private.h.

Referenced by doPickSplit(), moveLeafs(), spgdoinsert(), and SpGistSetLastUsedPage().

◆ GBUF_NULLS

#define GBUF_NULLS   0x04

◆ GBUF_PARITY_MASK

#define GBUF_PARITY_MASK   0x03

Definition at line 438 of file spgist_private.h.

Referenced by allocNewBuffer().

◆ GBUF_REQ_LEAF

#define GBUF_REQ_LEAF (   flags)    (((flags) & GBUF_PARITY_MASK) == GBUF_LEAF)

Definition at line 439 of file spgist_private.h.

Referenced by allocNewBuffer(), and SpGistGetBuffer().

◆ GBUF_REQ_NULLS

#define GBUF_REQ_NULLS (   flags)    ((flags) & GBUF_NULLS)

Definition at line 440 of file spgist_private.h.

Referenced by allocNewBuffer(), and SpGistGetBuffer().

◆ SGDTSIZE

◆ SGITDATAPTR

#define SGITDATAPTR (   x)    ((x)->prefixSize ? _SGITDATA(x) : NULL)

Definition at line 290 of file spgist_private.h.

Referenced by spgFormInnerTuple().

◆ SGITDATUM

#define SGITDATUM (   x,
 
)
Value:
((x)->prefixSize ? \
((s)->attPrefixType.attbyval ? \
*(Datum *) _SGITDATA(x) : \
PointerGetDatum(_SGITDATA(x))) \
: (Datum) 0)
#define _SGITDATA(x)
uintptr_t Datum
Definition: postgres.h:367

Definition at line 291 of file spgist_private.h.

Referenced by addNode(), spgdoinsert(), and spgInitInnerConsistentIn().

◆ SGITHDRSZ

#define SGITHDRSZ   MAXALIGN(sizeof(SpGistInnerTupleData))

Definition at line 288 of file spgist_private.h.

Referenced by spgFormInnerTuple().

◆ SGITITERATE

#define SGITITERATE (   x,
  i,
  nt 
)
Value:
for ((i) = 0, (nt) = SGITNODEPTR(x); \
(i) < (x)->nNodes; \
(i)++, (nt) = (SpGistNodeTuple) (((char *) (nt)) + IndexTupleSize(nt)))
#define SGITNODEPTR(x)
int i
#define IndexTupleSize(itup)
Definition: itup.h:71
SpGistNodeTupleData * SpGistNodeTuple

Definition at line 299 of file spgist_private.h.

Referenced by addNode(), doPickSplit(), spgExtractNodeLabels(), spgInnerTest(), spgMatchNodeAction(), spgprocesspending(), spgSplitNodeAction(), and spgUpdateNodeLink().

◆ SGITMAXNNODES

#define SGITMAXNNODES   0x1FFF

Definition at line 284 of file spgist_private.h.

Referenced by spgFormInnerTuple(), and spgSplitNodeAction().

◆ SGITMAXPREFIXSIZE

#define SGITMAXPREFIXSIZE   0xFFFF

Definition at line 285 of file spgist_private.h.

Referenced by spgFormInnerTuple().

◆ SGITMAXSIZE

#define SGITMAXSIZE   0xFFFF

Definition at line 286 of file spgist_private.h.

Referenced by spgFormInnerTuple().

◆ SGITNODEPTR

#define SGITNODEPTR (   x)    ((SpGistNodeTuple) (_SGITDATA(x) + (x)->prefixSize))

Definition at line 296 of file spgist_private.h.

Referenced by spgExtractNodeLabels(), and spgFormInnerTuple().

◆ SGLTDATAPTR

#define SGLTDATAPTR (   x)    (((char *) (x)) + SGLTHDRSZ)

Definition at line 362 of file spgist_private.h.

Referenced by spgFormLeafTuple().

◆ SGLTDATUM

#define SGLTDATUM (   x,
 
)
Value:
((s)->attLeafType.attbyval ? \
*(Datum *) SGLTDATAPTR(x) : \
#define PointerGetDatum(X)
Definition: postgres.h:556
#define SGLTDATAPTR(x)
uintptr_t Datum
Definition: postgres.h:367

Definition at line 363 of file spgist_private.h.

Referenced by doPickSplit(), and spgLeafTest().

◆ SGLTHDRSZ

#define SGLTHDRSZ   MAXALIGN(sizeof(SpGistLeafTupleData))

Definition at line 361 of file spgist_private.h.

Referenced by spgdoinsert(), and spgFormLeafTuple().

◆ SGNTDATAPTR

#define SGNTDATAPTR (   x)    (((char *) (x)) + SGNTHDRSZ)

Definition at line 319 of file spgist_private.h.

Referenced by spgFormNodeTuple().

◆ SGNTDATUM

#define SGNTDATUM (   x,
 
)
Value:
((s)->attLabelType.attbyval ? \
*(Datum *) SGNTDATAPTR(x) : \
#define PointerGetDatum(X)
Definition: postgres.h:556
uintptr_t Datum
Definition: postgres.h:367
#define SGNTDATAPTR(x)

Definition at line 320 of file spgist_private.h.

Referenced by spgExtractNodeLabels().

◆ SGNTHDRSZ

#define SGNTHDRSZ   MAXALIGN(sizeof(SpGistNodeTupleData))

Definition at line 318 of file spgist_private.h.

Referenced by spgFormNodeTuple().

◆ SizeOfSpGistSearchItem

#define SizeOfSpGistSearchItem (   n_distances)    (offsetof(SpGistSearchItem, distances) + sizeof(double) * (n_distances))

Definition at line 168 of file spgist_private.h.

Referenced by spgAllocSearchItem().

◆ SPGIST_CACHED_PAGES

#define SPGIST_CACHED_PAGES   8

Definition at line 102 of file spgist_private.h.

Referenced by SpGistInitMetapage().

◆ SPGIST_DEAD

#define SPGIST_DEAD   2 /* dead, cannot be removed because of links */

◆ SPGIST_DEFAULT_FILLFACTOR

#define SPGIST_DEFAULT_FILLFACTOR   80

Definition at line 446 of file spgist_private.h.

◆ SPGIST_DELETED

#define SPGIST_DELETED
Value:
(1<<1) /* never set, but keep for backwards
* compatibility */

Definition at line 69 of file spgist_private.h.

◆ SPGIST_LAST_FIXED_BLKNO

#define SPGIST_LAST_FIXED_BLKNO   SPGIST_NULL_BLKNO

Definition at line 46 of file spgist_private.h.

Referenced by spgvacuumscan().

◆ SPGIST_LEAF

#define SPGIST_LEAF   (1<<2)

◆ SPGIST_LIVE

#define SPGIST_LIVE   0 /* normal live tuple (either inner or leaf) */

◆ SPGIST_MAGIC_NUMBER

#define SPGIST_MAGIC_NUMBER   (0xBA0BABEE)

Definition at line 118 of file spgist_private.h.

Referenced by spgGetCache(), and SpGistInitMetapage().

◆ SPGIST_META

#define SPGIST_META   (1<<0)

Definition at line 68 of file spgist_private.h.

Referenced by SpGistInitMetapage().

◆ SPGIST_METAPAGE_BLKNO

#define SPGIST_METAPAGE_BLKNO   (0) /* metapage */

◆ SPGIST_MIN_FILLFACTOR

#define SPGIST_MIN_FILLFACTOR   10

Definition at line 445 of file spgist_private.h.

◆ SPGIST_NULL_BLKNO

#define SPGIST_NULL_BLKNO   (2) /* root for null-value entries */

Definition at line 45 of file spgist_private.h.

Referenced by spgAddStartItem(), spgbuild(), spgbuildempty(), and spgdoinsert().

◆ SPGIST_NULLS

#define SPGIST_NULLS   (1<<3)

◆ SPGIST_PAGE_CAPACITY

#define SPGIST_PAGE_CAPACITY
Value:
MAXALIGN_DOWN(BLCKSZ - \
#define SizeOfPageHeaderData
Definition: bufpage.h:216
#define MAXALIGN(LEN)
Definition: c.h:691
#define MAXALIGN_DOWN(LEN)
Definition: c.h:703

Definition at line 399 of file spgist_private.h.

Referenced by doPickSplit(), spgdoinsert(), spgFormInnerTuple(), and SpGistGetBuffer().

◆ SPGIST_PAGE_ID

#define SPGIST_PAGE_ID   0xFF82

Definition at line 88 of file spgist_private.h.

Referenced by SpGistInitPage().

◆ SPGIST_PLACEHOLDER

◆ SPGIST_REDIRECT

◆ SPGIST_ROOT_BLKNO

#define SPGIST_ROOT_BLKNO   (1) /* root for normal entries */

Definition at line 44 of file spgist_private.h.

Referenced by spgAddStartItem(), spgbuild(), spgbuildempty(), and spgdoinsert().

◆ SpGistBlockIsFixed

#define SpGistBlockIsFixed (   blkno)    ((BlockNumber) (blkno) <= (BlockNumber) SPGIST_LAST_FIXED_BLKNO)

Definition at line 50 of file spgist_private.h.

Referenced by SpGistGetBuffer(), SpGistNewBuffer(), and SpGistSetLastUsedPage().

◆ SpGistBlockIsRoot

#define SpGistBlockIsRoot (   blkno)    ((blkno) == SPGIST_ROOT_BLKNO || (blkno) == SPGIST_NULL_BLKNO)

◆ SpGistGetFillFactor

#define SpGistGetFillFactor (   relation)
Value:
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
relation->rd_rel->relam == SPGIST_AM_OID), \
(relation)->rd_options ? \
((SpGistOptions *) (relation)->rd_options)->fillfactor : \
SPGIST_DEFAULT_FILLFACTOR)
#define AssertMacro(condition)
Definition: c.h:739

Definition at line 32 of file spgist_private.h.

◆ SpGistGetTargetPageFreeSpace

#define SpGistGetTargetPageFreeSpace (   relation)    (BLCKSZ * (100 - SpGistGetFillFactor(relation)) / 100)

Definition at line 38 of file spgist_private.h.

Referenced by SpGistGetBuffer().

◆ SpGistPageGetFreeSpace

#define SpGistPageGetFreeSpace (   p,
 
)
Value:
Min(SpGistPageGetOpaque(p)->nPlaceholder, n) * \
(SGDTSIZE + sizeof(ItemIdData)))
#define SGDTSIZE
struct ItemIdData ItemIdData
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:625
#define SpGistPageGetOpaque(page)

Definition at line 408 of file spgist_private.h.

Referenced by doPickSplit(), spgdoinsert(), and spgSplitNodeAction().

◆ SpGistPageGetMeta

#define SpGistPageGetMeta (   p)    ((SpGistMetaPageData *) PageGetContents(p))

Definition at line 120 of file spgist_private.h.

Referenced by spgGetCache(), SpGistInitMetapage(), and SpGistUpdateMetaPage().

◆ SpGistPageGetOpaque

◆ SpGistPageIsDeleted

#define SpGistPageIsDeleted (   page)    (SpGistPageGetOpaque(page)->flags & SPGIST_DELETED)

Definition at line 76 of file spgist_private.h.

Referenced by SpGistGetBuffer(), SpGistNewBuffer(), and spgprocesspending().

◆ SpGistPageIsLeaf

#define SpGistPageIsLeaf (   page)    (SpGistPageGetOpaque(page)->flags & SPGIST_LEAF)

◆ SpGistPageIsMeta

#define SpGistPageIsMeta (   page)    (SpGistPageGetOpaque(page)->flags & SPGIST_META)

Definition at line 75 of file spgist_private.h.

◆ SpGistPageStoresNulls

#define SpGistPageStoresNulls (   page)    (SpGistPageGetOpaque(page)->flags & SPGIST_NULLS)

◆ STORE_STATE

#define STORE_STATE (   s,
 
)
Value:
do { \
(d).myXid = (s)->myXid; \
(d).isBuild = (s)->isBuild; \
} while(0)

Definition at line 417 of file spgist_private.h.

Referenced by doPickSplit(), moveLeafs(), spgAddNodeAction(), vacuumLeafPage(), and vacuumLeafRoot().

Typedef Documentation

◆ SpGistCache

typedef struct SpGistCache SpGistCache

◆ SpGistDeadTuple

Definition at line 387 of file spgist_private.h.

◆ SpGistDeadTupleData

◆ SpGistInnerTuple

Definition at line 281 of file spgist_private.h.

◆ SpGistInnerTupleData

◆ SpGistLastUsedPage

◆ SpGistLeafTuple

Definition at line 359 of file spgist_private.h.

◆ SpGistLeafTupleData

◆ SpGistLUPCache

◆ SpGistMetaPageData

◆ SpGistNodeTuple

Definition at line 316 of file spgist_private.h.

◆ SpGistNodeTupleData

Definition at line 314 of file spgist_private.h.

◆ SpGistOptions

typedef struct SpGistOptions SpGistOptions

◆ SpGistPageOpaque

Definition at line 65 of file spgist_private.h.

◆ SpGistPageOpaqueData

◆ SpGistScanOpaque

Definition at line 230 of file spgist_private.h.

◆ SpGistScanOpaqueData

◆ SpGistSearchItem

◆ SpGistState

typedef struct SpGistState SpGistState

◆ SpGistTypeDesc

Function Documentation

◆ box_copy()

BOX* box_copy ( BOX orig)

Definition at line 82 of file spgproc.c.

References palloc().

Referenced by spg_kd_inner_consistent(), and spg_quad_inner_consistent().

83 {
84  BOX *result = palloc(sizeof(BOX));
85 
86  *result = *orig;
87  return result;
88 }
Definition: geo_decls.h:99
void * palloc(Size size)
Definition: mcxt.c:949

◆ initSpGistState()

void initSpGistState ( SpGistState state,
Relation  index 
)

Definition at line 185 of file spgutils.c.

References SpGistState::attLabelType, SpGistCache::attLabelType, SpGistState::attLeafType, SpGistCache::attLeafType, SpGistState::attPrefixType, SpGistCache::attPrefixType, SpGistState::attType, SpGistCache::attType, SpGistState::config, SpGistCache::config, SpGistState::deadTupleStorage, GetTopTransactionIdIfAny(), SpGistState::isBuild, SpGistState::myXid, palloc0(), SGDTSIZE, and spgGetCache().

Referenced by spgbeginscan(), spgbuild(), spginsert(), and spgvacuumscan().

186 {
187  SpGistCache *cache;
188 
189  /* Get cached static information about index */
190  cache = spgGetCache(index);
191 
192  state->config = cache->config;
193  state->attType = cache->attType;
194  state->attLeafType = cache->attLeafType;
195  state->attPrefixType = cache->attPrefixType;
196  state->attLabelType = cache->attLabelType;
197 
198  /* Make workspace for constructing dead tuples */
200 
201  /* Set XID to use in redirection tuples */
202  state->myXid = GetTopTransactionIdIfAny();
203 
204  /* Assume we're not in an index build (spgbuild will override) */
205  state->isBuild = false;
206 }
SpGistTypeDesc attLeafType
SpGistTypeDesc attPrefixType
SpGistCache * spgGetCache(Relation index)
Definition: spgutils.c:103
#define SGDTSIZE
SpGistTypeDesc attLeafType
SpGistTypeDesc attType
SpGistTypeDesc attLabelType
SpGistTypeDesc attType
spgConfigOut config
TransactionId myXid
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:409
spgConfigOut config
void * palloc0(Size size)
Definition: mcxt.c:980
char * deadTupleStorage
SpGistTypeDesc attLabelType
SpGistTypeDesc attPrefixType

◆ spg_key_orderbys_distances()

double* spg_key_orderbys_distances ( Datum  key,
bool  isLeaf,
ScanKey  orderbys,
int  norderbys 
)

Definition at line 63 of file spgproc.c.

References DatumGetBoxP, DatumGetPointP, palloc(), point_box_distance(), and point_point_distance.

Referenced by spg_box_quad_leaf_consistent(), spg_kd_inner_consistent(), spg_quad_inner_consistent(), and spg_quad_leaf_consistent().

65 {
66  int sk_num;
67  double *distances = (double *) palloc(norderbys * sizeof(double)),
68  *distance = distances;
69 
70  for (sk_num = 0; sk_num < norderbys; ++sk_num, ++orderbys, ++distance)
71  {
72  Point *point = DatumGetPointP(orderbys->sk_argument);
73 
74  *distance = isLeaf ? point_point_distance(point, DatumGetPointP(key))
76  }
77 
78  return distances;
79 }
#define point_point_distance(p1, p2)
Definition: spgproc.c:25
#define DatumGetPointP(X)
Definition: geo_decls.h:134
#define DatumGetBoxP(X)
Definition: geo_decls.h:156
void * palloc(Size size)
Definition: mcxt.c:949
static double point_box_distance(Point *point, BOX *box)
Definition: spgproc.c:31

◆ spgdoinsert()

bool spgdoinsert ( Relation  index,
SpGistState state,
ItemPointer  heapPtr,
Datum  datum,
bool  isnull 
)

Definition at line 1891 of file spgdoinsert.c.

References addLeafTuple(), spgChooseOut::addNode, spgChooseIn::allTheSame, SpGistInnerTupleData::allTheSame, Assert, SpGistState::attLeafType, SpGistTypeDesc::attlen, SpGistState::attType, SPPageDesc::blkno, SPPageDesc::buffer, BUFFER_LOCK_EXCLUSIVE, BufferGetBlockNumber(), BufferGetPage, CHECK_FOR_INTERRUPTS, checkSplitConditions(), ConditionalLockBuffer(), SpGistState::config, spgChooseIn::datum, doPickSplit(), elog, ereport, errcode(), errhint(), errmsg(), ERROR, FirstOffsetNumber, FunctionCall1Coll(), FunctionCall2Coll(), GBUF_LEAF, GBUF_NULLS, spgChooseIn::hasPrefix, index_getprocid(), index_getprocinfo(), InvalidBlockNumber, InvalidBuffer, InvalidOffsetNumber, spgChooseIn::leafDatum, spgChooseIn::level, LockBuffer(), spgConfigOut::longValuesOK, spgChooseOut::matchNode, Min, moveLeafs(), spgChooseIn::nNodes, SpGistInnerTupleData::nNodes, SPPageDesc::node, spgChooseIn::nodeLabels, SPPageDesc::offnum, OidIsValid, SPPageDesc::page, PageGetItem, PageGetItemId, pfree(), PG_DETOAST_DATUM, PointerGetDatum, spgChooseIn::prefixDatum, SpGistInnerTupleData::prefixSize, random(), RelationData::rd_indcollation, ReadBuffer(), RelationGetRelationName, ReleaseBuffer(), spgChooseOut::result, spgChooseOut::resultType, SGDTSIZE, SGITDATUM, SGLTHDRSZ, SpGistLeafTupleData::size, spgAddNode, spgAddNodeAction(), spgExtractNodeLabels(), spgFormLeafTuple(), SPGIST_CHOOSE_PROC, SPGIST_COMPRESS_PROC, SPGIST_NULL_BLKNO, SPGIST_PAGE_CAPACITY, SPGIST_ROOT_BLKNO, SpGistGetBuffer(), SpGistGetTypeSize(), SpGistPageGetFreeSpace, SpGistPageIsLeaf, SpGistPageStoresNulls, SpGistSetLastUsedPage(), spgMatchNode, spgMatchNodeAction(), spgSplitNodeAction(), spgSplitTuple, SpGistTypeDesc::type, and UnlockReleaseBuffer().

Referenced by spginsert(), and spgistBuildCallback().

1893 {
1894  int level = 0;
1895  Datum leafDatum;
1896  int leafSize;
1897  SPPageDesc current,
1898  parent;
1899  FmgrInfo *procinfo = NULL;
1900 
1901  /*
1902  * Look up FmgrInfo of the user-defined choose function once, to save
1903  * cycles in the loop below.
1904  */
1905  if (!isnull)
1906  procinfo = index_getprocinfo(index, 1, SPGIST_CHOOSE_PROC);
1907 
1908  /*
1909  * Prepare the leaf datum to insert.
1910  *
1911  * If an optional "compress" method is provided, then call it to form the
1912  * leaf datum from the input datum. Otherwise store the input datum as
1913  * is. Since we don't use index_form_tuple in this AM, we have to make
1914  * sure value to be inserted is not toasted; FormIndexDatum doesn't
1915  * guarantee that. But we assume the "compress" method to return an
1916  * untoasted value.
1917  */
1918  if (!isnull)
1919  {
1921  {
1922  FmgrInfo *compressProcinfo = NULL;
1923 
1924  compressProcinfo = index_getprocinfo(index, 1, SPGIST_COMPRESS_PROC);
1925  leafDatum = FunctionCall1Coll(compressProcinfo,
1926  index->rd_indcollation[0],
1927  datum);
1928  }
1929  else
1930  {
1931  Assert(state->attLeafType.type == state->attType.type);
1932 
1933  if (state->attType.attlen == -1)
1934  leafDatum = PointerGetDatum(PG_DETOAST_DATUM(datum));
1935  else
1936  leafDatum = datum;
1937  }
1938  }
1939  else
1940  leafDatum = (Datum) 0;
1941 
1942  /*
1943  * Compute space needed for a leaf tuple containing the given datum.
1944  *
1945  * If it isn't gonna fit, and the opclass can't reduce the datum size by
1946  * suffixing, bail out now rather than getting into an endless loop.
1947  */
1948  if (!isnull)
1949  leafSize = SGLTHDRSZ + sizeof(ItemIdData) +
1950  SpGistGetTypeSize(&state->attLeafType, leafDatum);
1951  else
1952  leafSize = SGDTSIZE + sizeof(ItemIdData);
1953 
1954  if (leafSize > SPGIST_PAGE_CAPACITY && !state->config.longValuesOK)
1955  ereport(ERROR,
1956  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1957  errmsg("index row size %zu exceeds maximum %zu for index \"%s\"",
1958  leafSize - sizeof(ItemIdData),
1959  SPGIST_PAGE_CAPACITY - sizeof(ItemIdData),
1960  RelationGetRelationName(index)),
1961  errhint("Values larger than a buffer page cannot be indexed.")));
1962 
1963  /* Initialize "current" to the appropriate root page */
1964  current.blkno = isnull ? SPGIST_NULL_BLKNO : SPGIST_ROOT_BLKNO;
1965  current.buffer = InvalidBuffer;
1966  current.page = NULL;
1967  current.offnum = FirstOffsetNumber;
1968  current.node = -1;
1969 
1970  /* "parent" is invalid for the moment */
1971  parent.blkno = InvalidBlockNumber;
1972  parent.buffer = InvalidBuffer;
1973  parent.page = NULL;
1974  parent.offnum = InvalidOffsetNumber;
1975  parent.node = -1;
1976 
1977  for (;;)
1978  {
1979  bool isNew = false;
1980 
1981  /*
1982  * Bail out if query cancel is pending. We must have this somewhere
1983  * in the loop since a broken opclass could produce an infinite
1984  * picksplit loop.
1985  */
1987 
1988  if (current.blkno == InvalidBlockNumber)
1989  {
1990  /*
1991  * Create a leaf page. If leafSize is too large to fit on a page,
1992  * we won't actually use the page yet, but it simplifies the API
1993  * for doPickSplit to always have a leaf page at hand; so just
1994  * quietly limit our request to a page size.
1995  */
1996  current.buffer =
1997  SpGistGetBuffer(index,
1998  GBUF_LEAF | (isnull ? GBUF_NULLS : 0),
1999  Min(leafSize, SPGIST_PAGE_CAPACITY),
2000  &isNew);
2001  current.blkno = BufferGetBlockNumber(current.buffer);
2002  }
2003  else if (parent.buffer == InvalidBuffer)
2004  {
2005  /* we hold no parent-page lock, so no deadlock is possible */
2006  current.buffer = ReadBuffer(index, current.blkno);
2008  }
2009  else if (current.blkno != parent.blkno)
2010  {
2011  /* descend to a new child page */
2012  current.buffer = ReadBuffer(index, current.blkno);
2013 
2014  /*
2015  * Attempt to acquire lock on child page. We must beware of
2016  * deadlock against another insertion process descending from that
2017  * page to our parent page (see README). If we fail to get lock,
2018  * abandon the insertion and tell our caller to start over.
2019  *
2020  * XXX this could be improved, because failing to get lock on a
2021  * buffer is not proof of a deadlock situation; the lock might be
2022  * held by a reader, or even just background writer/checkpointer
2023  * process. Perhaps it'd be worth retrying after sleeping a bit?
2024  */
2025  if (!ConditionalLockBuffer(current.buffer))
2026  {
2027  ReleaseBuffer(current.buffer);
2028  UnlockReleaseBuffer(parent.buffer);
2029  return false;
2030  }
2031  }
2032  else
2033  {
2034  /* inner tuple can be stored on the same page as parent one */
2035  current.buffer = parent.buffer;
2036  }
2037  current.page = BufferGetPage(current.buffer);
2038 
2039  /* should not arrive at a page of the wrong type */
2040  if (isnull ? !SpGistPageStoresNulls(current.page) :
2041  SpGistPageStoresNulls(current.page))
2042  elog(ERROR, "SPGiST index page %u has wrong nulls flag",
2043  current.blkno);
2044 
2045  if (SpGistPageIsLeaf(current.page))
2046  {
2047  SpGistLeafTuple leafTuple;
2048  int nToSplit,
2049  sizeToSplit;
2050 
2051  leafTuple = spgFormLeafTuple(state, heapPtr, leafDatum, isnull);
2052  if (leafTuple->size + sizeof(ItemIdData) <=
2053  SpGistPageGetFreeSpace(current.page, 1))
2054  {
2055  /* it fits on page, so insert it and we're done */
2056  addLeafTuple(index, state, leafTuple,
2057  &current, &parent, isnull, isNew);
2058  break;
2059  }
2060  else if ((sizeToSplit =
2061  checkSplitConditions(index, state, &current,
2062  &nToSplit)) < SPGIST_PAGE_CAPACITY / 2 &&
2063  nToSplit < 64 &&
2064  leafTuple->size + sizeof(ItemIdData) + sizeToSplit <= SPGIST_PAGE_CAPACITY)
2065  {
2066  /*
2067  * the amount of data is pretty small, so just move the whole
2068  * chain to another leaf page rather than splitting it.
2069  */
2070  Assert(!isNew);
2071  moveLeafs(index, state, &current, &parent, leafTuple, isnull);
2072  break; /* we're done */
2073  }
2074  else
2075  {
2076  /* picksplit */
2077  if (doPickSplit(index, state, &current, &parent,
2078  leafTuple, level, isnull, isNew))
2079  break; /* doPickSplit installed new tuples */
2080 
2081  /* leaf tuple will not be inserted yet */
2082  pfree(leafTuple);
2083 
2084  /*
2085  * current now describes new inner tuple, go insert into it
2086  */
2087  Assert(!SpGistPageIsLeaf(current.page));
2088  goto process_inner_tuple;
2089  }
2090  }
2091  else /* non-leaf page */
2092  {
2093  /*
2094  * Apply the opclass choose function to figure out how to insert
2095  * the given datum into the current inner tuple.
2096  */
2097  SpGistInnerTuple innerTuple;
2098  spgChooseIn in;
2099  spgChooseOut out;
2100 
2101  /*
2102  * spgAddNode and spgSplitTuple cases will loop back to here to
2103  * complete the insertion operation. Just in case the choose
2104  * function is broken and produces add or split requests
2105  * repeatedly, check for query cancel.
2106  */
2107  process_inner_tuple:
2109 
2110  innerTuple = (SpGistInnerTuple) PageGetItem(current.page,
2111  PageGetItemId(current.page, current.offnum));
2112 
2113  in.datum = datum;
2114  in.leafDatum = leafDatum;
2115  in.level = level;
2116  in.allTheSame = innerTuple->allTheSame;
2117  in.hasPrefix = (innerTuple->prefixSize > 0);
2118  in.prefixDatum = SGITDATUM(innerTuple, state);
2119  in.nNodes = innerTuple->nNodes;
2120  in.nodeLabels = spgExtractNodeLabels(state, innerTuple);
2121 
2122  memset(&out, 0, sizeof(out));
2123 
2124  if (!isnull)
2125  {
2126  /* use user-defined choose method */
2127  FunctionCall2Coll(procinfo,
2128  index->rd_indcollation[0],
2129  PointerGetDatum(&in),
2130  PointerGetDatum(&out));
2131  }
2132  else
2133  {
2134  /* force "match" action (to insert to random subnode) */
2135  out.resultType = spgMatchNode;
2136  }
2137 
2138  if (innerTuple->allTheSame)
2139  {
2140  /*
2141  * It's not allowed to do an AddNode at an allTheSame tuple.
2142  * Opclass must say "match", in which case we choose a random
2143  * one of the nodes to descend into, or "split".
2144  */
2145  if (out.resultType == spgAddNode)
2146  elog(ERROR, "cannot add a node to an allTheSame inner tuple");
2147  else if (out.resultType == spgMatchNode)
2148  out.result.matchNode.nodeN = random() % innerTuple->nNodes;
2149  }
2150 
2151  switch (out.resultType)
2152  {
2153  case spgMatchNode:
2154  /* Descend to N'th child node */
2155  spgMatchNodeAction(index, state, innerTuple,
2156  &current, &parent,
2157  out.result.matchNode.nodeN);
2158  /* Adjust level as per opclass request */
2159  level += out.result.matchNode.levelAdd;
2160  /* Replace leafDatum and recompute leafSize */
2161  if (!isnull)
2162  {
2163  leafDatum = out.result.matchNode.restDatum;
2164  leafSize = SGLTHDRSZ + sizeof(ItemIdData) +
2165  SpGistGetTypeSize(&state->attLeafType, leafDatum);
2166  }
2167 
2168  /*
2169  * Loop around and attempt to insert the new leafDatum at
2170  * "current" (which might reference an existing child
2171  * tuple, or might be invalid to force us to find a new
2172  * page for the tuple).
2173  *
2174  * Note: if the opclass sets longValuesOK, we rely on the
2175  * choose function to eventually shorten the leafDatum
2176  * enough to fit on a page. We could add a test here to
2177  * complain if the datum doesn't get visibly shorter each
2178  * time, but that could get in the way of opclasses that
2179  * "simplify" datums in a way that doesn't necessarily
2180  * lead to physical shortening on every cycle.
2181  */
2182  break;
2183  case spgAddNode:
2184  /* AddNode is not sensible if nodes don't have labels */
2185  if (in.nodeLabels == NULL)
2186  elog(ERROR, "cannot add a node to an inner tuple without node labels");
2187  /* Add node to inner tuple, per request */
2188  spgAddNodeAction(index, state, innerTuple,
2189  &current, &parent,
2190  out.result.addNode.nodeN,
2191  out.result.addNode.nodeLabel);
2192 
2193  /*
2194  * Retry insertion into the enlarged node. We assume that
2195  * we'll get a MatchNode result this time.
2196  */
2197  goto process_inner_tuple;
2198  break;
2199  case spgSplitTuple:
2200  /* Split inner tuple, per request */
2201  spgSplitNodeAction(index, state, innerTuple,
2202  &current, &out);
2203 
2204  /* Retry insertion into the split node */
2205  goto process_inner_tuple;
2206  break;
2207  default:
2208  elog(ERROR, "unrecognized SPGiST choose result: %d",
2209  (int) out.resultType);
2210  break;
2211  }
2212  }
2213  } /* end loop */
2214 
2215  /*
2216  * Release any buffers we're still holding. Beware of possibility that
2217  * current and parent reference same buffer.
2218  */
2219  if (current.buffer != InvalidBuffer)
2220  {
2221  SpGistSetLastUsedPage(index, current.buffer);
2222  UnlockReleaseBuffer(current.buffer);
2223  }
2224  if (parent.buffer != InvalidBuffer &&
2225  parent.buffer != current.buffer)
2226  {
2227  SpGistSetLastUsedPage(index, parent.buffer);
2228  UnlockReleaseBuffer(parent.buffer);
2229  }
2230 
2231  return true;
2232 }
Definition: fmgr.h:56
Datum * spgExtractNodeLabels(SpGistState *state, SpGistInnerTuple innerTuple)
Definition: spgutils.c:839
Datum datum
Definition: spgist.h:54
SpGistInnerTupleData * SpGistInnerTuple
#define SpGistPageIsLeaf(page)
bool hasPrefix
Definition: spgist.h:60
int errhint(const char *fmt,...)
Definition: elog.c:1069
#define SpGistPageGetFreeSpace(p, n)
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:794
#define SGDTSIZE
int level
Definition: spgist.h:56
struct spgChooseOut::@48::@49 matchNode
#define PointerGetDatum(X)
Definition: postgres.h:556
long random(void)
Definition: random.c:22
SpGistTypeDesc attLeafType
#define Min(x, y)
Definition: c.h:920
SpGistTypeDesc attType
void SpGistSetLastUsedPage(Relation index, Buffer buffer)
Definition: spgutils.c:503
#define InvalidBuffer
Definition: buf.h:25
Datum prefixDatum
Definition: spgist.h:61
int errcode(int sqlerrcode)
Definition: elog.c:608
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3375
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:88
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1150
#define SPGIST_ROOT_BLKNO
#define OidIsValid(objectId)
Definition: c.h:644
#define SGITDATUM(x, s)
static void addLeafTuple(Relation index, SpGistState *state, SpGistLeafTuple leafTuple, SPPageDesc *current, SPPageDesc *parent, bool isNulls, bool isNew)
Definition: spgdoinsert.c:203
spgConfigOut config
void pfree(void *pointer)
Definition: mcxt.c:1056
unsigned int allTheSame
static bool doPickSplit(Relation index, SpGistState *state, SPPageDesc *current, SPPageDesc *parent, SpGistLeafTuple newLeafTuple, int level, bool isNulls, bool isNew)
Definition: spgdoinsert.c:675
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3398
Oid * rd_indcollation
Definition: rel.h:174
#define ERROR
Definition: elog.h:43
unsigned int prefixSize
#define SPGIST_NULL_BLKNO
#define FirstOffsetNumber
Definition: off.h:27
OffsetNumber offnum
Definition: spgdoinsert.c:39
static void spgSplitNodeAction(Relation index, SpGistState *state, SpGistInnerTuple innerTuple, SPPageDesc *current, spgChooseOut *out)
Definition: spgdoinsert.c:1692
#define RelationGetRelationName(relation)
Definition: rel.h:462
struct ItemIdData ItemIdData
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
#define ereport(elevel, rest)
Definition: elog.h:141
bool ConditionalLockBuffer(Buffer buffer)
Definition: bufmgr.c:3638
int nNodes
Definition: spgist.h:62
#define SGLTHDRSZ
#define GBUF_LEAF
unsigned int SpGistGetTypeSize(SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:610
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
SpGistLeafTuple spgFormLeafTuple(SpGistState *state, ItemPointer heapPtr, Datum datum, bool isnull)
Definition: spgutils.c:647
bool longValuesOK
Definition: spgist.h:46
uintptr_t Datum
Definition: postgres.h:367
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Definition: fmgr.c:1130
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3612
#define SPGIST_PAGE_CAPACITY
spgChooseResultType resultType
Definition: spgist.h:75
#define InvalidOffsetNumber
Definition: off.h:26
#define SpGistPageStoresNulls(page)
static void spgMatchNodeAction(Relation index, SpGistState *state, SpGistInnerTuple innerTuple, SPPageDesc *current, SPPageDesc *parent, int nodeN)
Definition: spgdoinsert.c:1436
#define Assert(condition)
Definition: c.h:738
Datum leafDatum
Definition: spgist.h:55
struct spgChooseOut::@48::@50 addNode
Buffer SpGistGetBuffer(Relation index, int flags, int needSpace, bool *isNew)
Definition: spgutils.c:399
#define SPGIST_COMPRESS_PROC
Definition: spgist.h:28
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:596
#define InvalidBlockNumber
Definition: block.h:33
#define GBUF_NULLS
union spgChooseOut::@48 result
static void spgAddNodeAction(Relation index, SpGistState *state, SpGistInnerTuple innerTuple, SPPageDesc *current, SPPageDesc *parent, int nodeN, Datum nodeLabel)
Definition: spgdoinsert.c:1490
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2623
Datum * nodeLabels
Definition: spgist.h:63
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
bool allTheSame
Definition: spgist.h:59
static int checkSplitConditions(Relation index, SpGistState *state, SPPageDesc *current, int *nToSplit)
Definition: spgdoinsert.c:333
Buffer buffer
Definition: spgdoinsert.c:37
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:235
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
#define SPGIST_CHOOSE_PROC
Definition: spgist.h:24
static void moveLeafs(Relation index, SpGistState *state, SPPageDesc *current, SPPageDesc *parent, SpGistLeafTuple newLeafTuple, bool isNulls)
Definition: spgdoinsert.c:387
#define PageGetItem(page, itemId)
Definition: bufpage.h:340
BlockNumber blkno
Definition: spgdoinsert.c:36
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:760

◆ spgExtractNodeLabels()

Datum* spgExtractNodeLabels ( SpGistState state,
SpGistInnerTuple  innerTuple 
)

Definition at line 839 of file spgutils.c.

References elog, ERROR, i, IndexTupleHasNulls, SpGistInnerTupleData::nNodes, palloc(), SGITITERATE, SGITNODEPTR, and SGNTDATUM.

Referenced by spgdoinsert(), and spgInitInnerConsistentIn().

840 {
841  Datum *nodeLabels;
842  int i;
843  SpGistNodeTuple node;
844 
845  /* Either all the labels must be NULL, or none. */
846  node = SGITNODEPTR(innerTuple);
847  if (IndexTupleHasNulls(node))
848  {
849  SGITITERATE(innerTuple, i, node)
850  {
851  if (!IndexTupleHasNulls(node))
852  elog(ERROR, "some but not all node labels are null in SPGiST inner tuple");
853  }
854  /* They're all null, so just return NULL */
855  return NULL;
856  }
857  else
858  {
859  nodeLabels = (Datum *) palloc(sizeof(Datum) * innerTuple->nNodes);
860  SGITITERATE(innerTuple, i, node)
861  {
862  if (IndexTupleHasNulls(node))
863  elog(ERROR, "some but not all node labels are null in SPGiST inner tuple");
864  nodeLabels[i] = SGNTDATUM(node, state);
865  }
866  return nodeLabels;
867  }
868 }
#define SGITNODEPTR(x)
#define SGITITERATE(x, i, nt)
#define IndexTupleHasNulls(itup)
Definition: itup.h:72
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
void * palloc(Size size)
Definition: mcxt.c:949
#define elog(elevel,...)
Definition: elog.h:228
int i
#define SGNTDATUM(x, s)

◆ spgFormDeadTuple()

SpGistDeadTuple spgFormDeadTuple ( SpGistState state,
int  tupstate,
BlockNumber  blkno,
OffsetNumber  offnum 
)

Definition at line 809 of file spgutils.c.

References Assert, SpGistState::deadTupleStorage, InvalidOffsetNumber, InvalidTransactionId, ItemPointerSet, ItemPointerSetInvalid, SpGistState::myXid, SpGistDeadTupleData::nextOffset, SpGistDeadTupleData::pointer, SGDTSIZE, SpGistDeadTupleData::size, SPGIST_REDIRECT, TransactionIdIsValid, SpGistDeadTupleData::tupstate, and SpGistDeadTupleData::xid.

Referenced by spgAddNodeAction(), spgPageIndexMultiDelete(), and spgRedoAddNode().

811 {
813 
814  tuple->tupstate = tupstate;
815  tuple->size = SGDTSIZE;
817 
818  if (tupstate == SPGIST_REDIRECT)
819  {
820  ItemPointerSet(&tuple->pointer, blkno, offnum);
822  tuple->xid = state->myXid;
823  }
824  else
825  {
827  tuple->xid = InvalidTransactionId;
828  }
829 
830  return tuple;
831 }
#define SGDTSIZE
#define SPGIST_REDIRECT
ItemPointerData pointer
SpGistDeadTupleData * SpGistDeadTuple
#define InvalidTransactionId
Definition: transam.h:31
TransactionId myXid
unsigned int tupstate
char * deadTupleStorage
OffsetNumber nextOffset
#define InvalidOffsetNumber
Definition: off.h:26
#define Assert(condition)
Definition: c.h:738
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127

◆ spgFormInnerTuple()

SpGistInnerTuple spgFormInnerTuple ( SpGistState state,
bool  hasPrefix,
Datum  prefix,
int  nNodes,
SpGistNodeTuple nodes 
)

Definition at line 726 of file spgutils.c.

References SpGistState::attPrefixType, elog, ereport, errcode(), errhint(), errmsg(), ERROR, i, IndexTupleSize, memcpyDatum(), SpGistInnerTupleData::nNodes, palloc0(), SpGistInnerTupleData::prefixSize, SGDTSIZE, SGITDATAPTR, SGITHDRSZ, SGITMAXNNODES, SGITMAXPREFIXSIZE, SGITMAXSIZE, SGITNODEPTR, SpGistInnerTupleData::size, SPGIST_PAGE_CAPACITY, and SpGistGetTypeSize().

Referenced by addNode(), doPickSplit(), and spgSplitNodeAction().

728 {
729  SpGistInnerTuple tup;
730  unsigned int size;
731  unsigned int prefixSize;
732  int i;
733  char *ptr;
734 
735  /* Compute size needed */
736  if (hasPrefix)
737  prefixSize = SpGistGetTypeSize(&state->attPrefixType, prefix);
738  else
739  prefixSize = 0;
740 
741  size = SGITHDRSZ + prefixSize;
742 
743  /* Note: we rely on node tuple sizes to be maxaligned already */
744  for (i = 0; i < nNodes; i++)
745  size += IndexTupleSize(nodes[i]);
746 
747  /*
748  * Ensure that we can replace the tuple with a dead tuple later. This
749  * test is unnecessary given current tuple layouts, but let's be safe.
750  */
751  if (size < SGDTSIZE)
752  size = SGDTSIZE;
753 
754  /*
755  * Inner tuple should be small enough to fit on a page
756  */
757  if (size > SPGIST_PAGE_CAPACITY - sizeof(ItemIdData))
758  ereport(ERROR,
759  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
760  errmsg("SP-GiST inner tuple size %zu exceeds maximum %zu",
761  (Size) size,
762  SPGIST_PAGE_CAPACITY - sizeof(ItemIdData)),
763  errhint("Values larger than a buffer page cannot be indexed.")));
764 
765  /*
766  * Check for overflow of header fields --- probably can't fail if the
767  * above succeeded, but let's be paranoid
768  */
769  if (size > SGITMAXSIZE ||
770  prefixSize > SGITMAXPREFIXSIZE ||
771  nNodes > SGITMAXNNODES)
772  elog(ERROR, "SPGiST inner tuple header field is too small");
773 
774  /* OK, form the tuple */
775  tup = (SpGistInnerTuple) palloc0(size);
776 
777  tup->nNodes = nNodes;
778  tup->prefixSize = prefixSize;
779  tup->size = size;
780 
781  if (hasPrefix)
782  memcpyDatum(SGITDATAPTR(tup), &state->attPrefixType, prefix);
783 
784  ptr = (char *) SGITNODEPTR(tup);
785 
786  for (i = 0; i < nNodes; i++)
787  {
788  SpGistNodeTuple node = nodes[i];
789 
790  memcpy(ptr, node, IndexTupleSize(node));
791  ptr += IndexTupleSize(node);
792  }
793 
794  return tup;
795 }
#define SGITNODEPTR(x)
SpGistTypeDesc attPrefixType
SpGistInnerTupleData * SpGistInnerTuple
int errhint(const char *fmt,...)
Definition: elog.c:1069
#define SGITMAXPREFIXSIZE
#define SGDTSIZE
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
unsigned int prefixSize
#define SGITMAXSIZE
#define SGITDATAPTR(x)
#define SGITMAXNNODES
#define ereport(elevel, rest)
Definition: elog.h:141
unsigned int SpGistGetTypeSize(SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:610
void * palloc0(Size size)
Definition: mcxt.c:980
#define SPGIST_PAGE_CAPACITY
size_t Size
Definition: c.h:466
static void memcpyDatum(void *target, SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:628
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
int i
#define SGITHDRSZ
#define IndexTupleSize(itup)
Definition: itup.h:71

◆ spgFormLeafTuple()

SpGistLeafTuple spgFormLeafTuple ( SpGistState state,
ItemPointer  heapPtr,
Datum  datum,
bool  isnull 
)

Definition at line 647 of file spgutils.c.

References SpGistState::attLeafType, SpGistLeafTupleData::heapPtr, InvalidOffsetNumber, memcpyDatum(), SpGistLeafTupleData::nextOffset, palloc0(), SGDTSIZE, SGLTDATAPTR, SGLTHDRSZ, SpGistLeafTupleData::size, and SpGistGetTypeSize().

Referenced by doPickSplit(), and spgdoinsert().

649 {
650  SpGistLeafTuple tup;
651  unsigned int size;
652 
653  /* compute space needed (note result is already maxaligned) */
654  size = SGLTHDRSZ;
655  if (!isnull)
656  size += SpGistGetTypeSize(&state->attLeafType, datum);
657 
658  /*
659  * Ensure that we can replace the tuple with a dead tuple later. This
660  * test is unnecessary when !isnull, but let's be safe.
661  */
662  if (size < SGDTSIZE)
663  size = SGDTSIZE;
664 
665  /* OK, form the tuple */
666  tup = (SpGistLeafTuple) palloc0(size);
667 
668  tup->size = size;
670  tup->heapPtr = *heapPtr;
671  if (!isnull)
672  memcpyDatum(SGLTDATAPTR(tup), &state->attLeafType, datum);
673 
674  return tup;
675 }
#define SGDTSIZE
SpGistTypeDesc attLeafType
#define SGLTDATAPTR(x)
#define SGLTHDRSZ
unsigned int SpGistGetTypeSize(SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:610
void * palloc0(Size size)
Definition: mcxt.c:980
#define InvalidOffsetNumber
Definition: off.h:26
OffsetNumber nextOffset
static void memcpyDatum(void *target, SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:628
ItemPointerData heapPtr
SpGistLeafTupleData * SpGistLeafTuple

◆ spgFormNodeTuple()

SpGistNodeTuple spgFormNodeTuple ( SpGistState state,
Datum  label,
bool  isnull 
)

Definition at line 684 of file spgutils.c.

References SpGistState::attLabelType, ereport, errcode(), errmsg(), ERROR, INDEX_NULL_MASK, INDEX_SIZE_MASK, ItemPointerSetInvalid, memcpyDatum(), palloc0(), SGNTDATAPTR, SGNTHDRSZ, SpGistGetTypeSize(), IndexTupleData::t_info, and IndexTupleData::t_tid.

Referenced by addNode(), doPickSplit(), and spgSplitNodeAction().

685 {
686  SpGistNodeTuple tup;
687  unsigned int size;
688  unsigned short infomask = 0;
689 
690  /* compute space needed (note result is already maxaligned) */
691  size = SGNTHDRSZ;
692  if (!isnull)
693  size += SpGistGetTypeSize(&state->attLabelType, label);
694 
695  /*
696  * Here we make sure that the size will fit in the field reserved for it
697  * in t_info.
698  */
699  if ((size & INDEX_SIZE_MASK) != size)
700  ereport(ERROR,
701  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
702  errmsg("index row requires %zu bytes, maximum size is %zu",
703  (Size) size, (Size) INDEX_SIZE_MASK)));
704 
705  tup = (SpGistNodeTuple) palloc0(size);
706 
707  if (isnull)
708  infomask |= INDEX_NULL_MASK;
709  /* we don't bother setting the INDEX_VAR_MASK bit */
710  infomask |= size;
711  tup->t_info = infomask;
712 
713  /* The TID field will be filled in later */
715 
716  if (!isnull)
717  memcpyDatum(SGNTDATAPTR(tup), &state->attLabelType, label);
718 
719  return tup;
720 }
ItemPointerData t_tid
Definition: itup.h:37
#define INDEX_SIZE_MASK
Definition: itup.h:65
int errcode(int sqlerrcode)
Definition: elog.c:608
SpGistTypeDesc attLabelType
#define SGNTHDRSZ
#define ERROR
Definition: elog.h:43
#define INDEX_NULL_MASK
Definition: itup.h:69
#define ereport(elevel, rest)
Definition: elog.h:141
unsigned int SpGistGetTypeSize(SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:610
void * palloc0(Size size)
Definition: mcxt.c:980
static char * label
#define SGNTDATAPTR(x)
size_t Size
Definition: c.h:466
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
static void memcpyDatum(void *target, SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:628
int errmsg(const char *fmt,...)
Definition: elog.c:822
unsigned short t_info
Definition: itup.h:49
SpGistNodeTupleData * SpGistNodeTuple

◆ spgGetCache()

SpGistCache* spgGetCache ( Relation  index)

Definition at line 103 of file spgutils.c.

References Assert, SpGistCache::attLabelType, SpGistCache::attLeafType, SpGistCache::attPrefixType, spgConfigIn::attType, SpGistCache::attType, BUFFER_LOCK_SHARE, BufferGetPage, SpGistCache::config, elog, ereport, errcode(), errmsg(), ERROR, fillTypeDesc(), FunctionCall2Coll(), index_getprocid(), index_getprocinfo(), spgConfigOut::labelType, SpGistMetaPageData::lastUsedPages, SpGistCache::lastUsedPages, spgConfigOut::leafType, LockBuffer(), SpGistMetaPageData::magicNumber, MemoryContextAllocZero(), TupleDescData::natts, OidIsValid, PointerGetDatum, spgConfigOut::prefixType, RelationData::rd_amcache, RelationData::rd_att, RelationData::rd_indcollation, RelationData::rd_indexcxt, ReadBuffer(), RelationGetRelationName, SPGIST_COMPRESS_PROC, SPGIST_CONFIG_PROC, SPGIST_MAGIC_NUMBER, SPGIST_METAPAGE_BLKNO, SpGistPageGetMeta, TupleDescAttr, and UnlockReleaseBuffer().

Referenced by allocNewBuffer(), initSpGistState(), spgcanreturn(), SpGistGetBuffer(), and SpGistSetLastUsedPage().

104 {
105  SpGistCache *cache;
106 
107  if (index->rd_amcache == NULL)
108  {
109  Oid atttype;
110  spgConfigIn in;
111  FmgrInfo *procinfo;
112  Buffer metabuffer;
113  SpGistMetaPageData *metadata;
114 
115  cache = MemoryContextAllocZero(index->rd_indexcxt,
116  sizeof(SpGistCache));
117 
118  /* SPGiST doesn't support multi-column indexes */
119  Assert(index->rd_att->natts == 1);
120 
121  /*
122  * Get the actual data type of the indexed column from the index
123  * tupdesc. We pass this to the opclass config function so that
124  * polymorphic opclasses are possible.
125  */
126  atttype = TupleDescAttr(index->rd_att, 0)->atttypid;
127 
128  /* Call the config function to get config info for the opclass */
129  in.attType = atttype;
130 
131  procinfo = index_getprocinfo(index, 1, SPGIST_CONFIG_PROC);
132  FunctionCall2Coll(procinfo,
133  index->rd_indcollation[0],
134  PointerGetDatum(&in),
135  PointerGetDatum(&cache->config));
136 
137  /* Get the information we need about each relevant datatype */
138  fillTypeDesc(&cache->attType, atttype);
139 
140  if (OidIsValid(cache->config.leafType) &&
141  cache->config.leafType != atttype)
142  {
144  ereport(ERROR,
145  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
146  errmsg("compress method must be defined when leaf type is different from input type")));
147 
148  fillTypeDesc(&cache->attLeafType, cache->config.leafType);
149  }
150  else
151  {
152  cache->attLeafType = cache->attType;
153  }
154 
155  fillTypeDesc(&cache->attPrefixType, cache->config.prefixType);
156  fillTypeDesc(&cache->attLabelType, cache->config.labelType);
157 
158  /* Last, get the lastUsedPages data from the metapage */
159  metabuffer = ReadBuffer(index, SPGIST_METAPAGE_BLKNO);
160  LockBuffer(metabuffer, BUFFER_LOCK_SHARE);
161 
162  metadata = SpGistPageGetMeta(BufferGetPage(metabuffer));
163 
164  if (metadata->magicNumber != SPGIST_MAGIC_NUMBER)
165  elog(ERROR, "index \"%s\" is not an SP-GiST index",
166  RelationGetRelationName(index));
167 
168  cache->lastUsedPages = metadata->lastUsedPages;
169 
170  UnlockReleaseBuffer(metabuffer);
171 
172  index->rd_amcache = (void *) cache;
173  }
174  else
175  {
176  /* assume it's up to date */
177  cache = (SpGistCache *) index->rd_amcache;
178  }
179 
180  return cache;
181 }
SpGistTypeDesc attLeafType
Definition: fmgr.h:56
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:794
#define PointerGetDatum(X)
Definition: postgres.h:556
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
int errcode(int sqlerrcode)
Definition: elog.c:608
Oid attType
Definition: spgist.h:37
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1150
unsigned int Oid
Definition: postgres_ext.h:31
SpGistTypeDesc attType
#define OidIsValid(objectId)
Definition: c.h:644
SpGistLUPCache lastUsedPages
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3398
Oid * rd_indcollation
Definition: rel.h:174
#define ERROR
Definition: elog.h:43
#define SPGIST_METAPAGE_BLKNO
#define RelationGetRelationName(relation)
Definition: rel.h:462
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
#define ereport(elevel, rest)
Definition: elog.h:141
#define SPGIST_MAGIC_NUMBER
spgConfigOut config
SpGistLUPCache lastUsedPages
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3612
Oid prefixType
Definition: spgist.h:42
TupleDesc rd_att
Definition: rel.h:85
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:839
#define Assert(condition)
Definition: c.h:738
#define SPGIST_COMPRESS_PROC
Definition: spgist.h:28
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:596
#define SPGIST_CONFIG_PROC
Definition: spgist.h:23
#define SpGistPageGetMeta(p)
SpGistTypeDesc attLabelType
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
MemoryContext rd_indexcxt
Definition: rel.h:161
Oid labelType
Definition: spgist.h:43
Oid leafType
Definition: spgist.h:44
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:87
SpGistTypeDesc attPrefixType
static void fillTypeDesc(SpGistTypeDesc *desc, Oid type)
Definition: spgutils.c:92
void * rd_amcache
Definition: rel.h:185
int Buffer
Definition: buf.h:23
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:760

◆ SpGistGetBuffer()

Buffer SpGistGetBuffer ( Relation  index,
int  flags,
int  needSpace,
bool isNew 
)

Definition at line 399 of file spgutils.c.

References allocNewBuffer(), Assert, SpGistLastUsedPage::blkno, BufferGetPage, ConditionalLockBuffer(), elog, ERROR, SpGistLastUsedPage::freeSpace, GBUF_REQ_LEAF, GBUF_REQ_NULLS, GET_LUP, InvalidBlockNumber, Min, PageGetExactFreeSpace(), PageIsEmpty, PageIsNew, ReadBuffer(), ReleaseBuffer(), spgGetCache(), SPGIST_LEAF, SPGIST_NULLS, SPGIST_PAGE_CAPACITY, SpGistBlockIsFixed, SpGistGetTargetPageFreeSpace, SpGistInitBuffer(), SpGistPageIsDeleted, SpGistPageIsLeaf, SpGistPageStoresNulls, and UnlockReleaseBuffer().

Referenced by doPickSplit(), moveLeafs(), spgAddNodeAction(), spgdoinsert(), and spgSplitNodeAction().

400 {
401  SpGistCache *cache = spgGetCache(index);
402  SpGistLastUsedPage *lup;
403 
404  /* Bail out if even an empty page wouldn't meet the demand */
405  if (needSpace > SPGIST_PAGE_CAPACITY)
406  elog(ERROR, "desired SPGiST tuple size is too big");
407 
408  /*
409  * If possible, increase the space request to include relation's
410  * fillfactor. This ensures that when we add unrelated tuples to a page,
411  * we try to keep 100-fillfactor% available for adding tuples that are
412  * related to the ones already on it. But fillfactor mustn't cause an
413  * error for requests that would otherwise be legal.
414  */
415  needSpace += SpGistGetTargetPageFreeSpace(index);
416  needSpace = Min(needSpace, SPGIST_PAGE_CAPACITY);
417 
418  /* Get the cache entry for this flags setting */
419  lup = GET_LUP(cache, flags);
420 
421  /* If we have nothing cached, just turn it over to allocNewBuffer */
422  if (lup->blkno == InvalidBlockNumber)
423  {
424  *isNew = true;
425  return allocNewBuffer(index, flags);
426  }
427 
428  /* fixed pages should never be in cache */
430 
431  /* If cached freeSpace isn't enough, don't bother looking at the page */
432  if (lup->freeSpace >= needSpace)
433  {
434  Buffer buffer;
435  Page page;
436 
437  buffer = ReadBuffer(index, lup->blkno);
438 
439  if (!ConditionalLockBuffer(buffer))
440  {
441  /*
442  * buffer is locked by another process, so return a new buffer
443  */
444  ReleaseBuffer(buffer);
445  *isNew = true;
446  return allocNewBuffer(index, flags);
447  }
448 
449  page = BufferGetPage(buffer);
450 
451  if (PageIsNew(page) || SpGistPageIsDeleted(page) || PageIsEmpty(page))
452  {
453  /* OK to initialize the page */
454  uint16 pageflags = 0;
455 
456  if (GBUF_REQ_LEAF(flags))
457  pageflags |= SPGIST_LEAF;
458  if (GBUF_REQ_NULLS(flags))
459  pageflags |= SPGIST_NULLS;
460  SpGistInitBuffer(buffer, pageflags);
461  lup->freeSpace = PageGetExactFreeSpace(page) - needSpace;
462  *isNew = true;
463  return buffer;
464  }
465 
466  /*
467  * Check that page is of right type and has enough space. We must
468  * recheck this since our cache isn't necessarily up to date.
469  */
470  if ((GBUF_REQ_LEAF(flags) ? SpGistPageIsLeaf(page) : !SpGistPageIsLeaf(page)) &&
472  {
473  int freeSpace = PageGetExactFreeSpace(page);
474 
475  if (freeSpace >= needSpace)
476  {
477  /* Success, update freespace info and return the buffer */
478  lup->freeSpace = freeSpace - needSpace;
479  *isNew = false;
480  return buffer;
481  }
482  }
483 
484  /*
485  * fallback to allocation of new buffer
486  */
487  UnlockReleaseBuffer(buffer);
488  }
489 
490  /* No success with cache, so return a new buffer */
491  *isNew = true;
492  return allocNewBuffer(index, flags);
493 }
#define PageIsEmpty(page)
Definition: bufpage.h:222
#define SpGistPageIsLeaf(page)
SpGistCache * spgGetCache(Relation index)
Definition: spgutils.c:103
#define GET_LUP(c, f)
Definition: spgutils.c:320
#define Min(x, y)
Definition: c.h:920
#define SPGIST_NULLS
static Buffer allocNewBuffer(Relation index, int flags)
Definition: spgutils.c:343
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3375
#define GBUF_REQ_NULLS(flags)
unsigned short uint16
Definition: c.h:366
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3398
#define ERROR
Definition: elog.h:43
#define SpGistBlockIsFixed(blkno)
void SpGistInitBuffer(Buffer b, uint16 f)
Definition: spgutils.c:553
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
bool ConditionalLockBuffer(Buffer buffer)
Definition: bufmgr.c:3638
#define SPGIST_PAGE_CAPACITY
#define SpGistPageStoresNulls(page)
#define Assert(condition)
Definition: c.h:738
#define SpGistPageIsDeleted(page)
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:596
#define InvalidBlockNumber
Definition: block.h:33
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:625
#define PageIsNew(page)
Definition: bufpage.h:229
#define elog(elevel,...)
Definition: elog.h:228
#define SpGistGetTargetPageFreeSpace(relation)
#define SPGIST_LEAF
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78
#define GBUF_REQ_LEAF(flags)

◆ SpGistGetTypeSize()

unsigned int SpGistGetTypeSize ( SpGistTypeDesc att,
Datum  datum 
)

Definition at line 610 of file spgutils.c.

References SpGistTypeDesc::attbyval, SpGistTypeDesc::attlen, MAXALIGN, and VARSIZE_ANY.

Referenced by spgdoinsert(), spgFormInnerTuple(), spgFormLeafTuple(), and spgFormNodeTuple().

611 {
612  unsigned int size;
613 
614  if (att->attbyval)
615  size = sizeof(Datum);
616  else if (att->attlen > 0)
617  size = att->attlen;
618  else
619  size = VARSIZE_ANY(datum);
620 
621  return MAXALIGN(size);
622 }
uintptr_t Datum
Definition: postgres.h:367
#define VARSIZE_ANY(PTR)
Definition: postgres.h:335
#define MAXALIGN(LEN)
Definition: c.h:691

◆ SpGistInitBuffer()

void SpGistInitBuffer ( Buffer  b,
uint16  f 
)

Definition at line 553 of file spgutils.c.

References Assert, BufferGetPage, BufferGetPageSize, and SpGistInitPage().

Referenced by allocNewBuffer(), doPickSplit(), spgbuild(), SpGistGetBuffer(), spgRedoAddLeaf(), spgRedoAddNode(), spgRedoMoveLeafs(), spgRedoPickSplit(), and spgRedoSplitTuple().

554 {
555  Assert(BufferGetPageSize(b) == BLCKSZ);
557 }
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
#define BufferGetPageSize(buffer)
Definition: bufmgr.h:146
#define Assert(condition)
Definition: c.h:738
void SpGistInitPage(Page page, uint16 f)
Definition: spgutils.c:538

◆ SpGistInitMetapage()

void SpGistInitMetapage ( Page  page)

Definition at line 563 of file spgutils.c.

References SpGistLastUsedPage::blkno, SpGistLUPCache::cachedPage, i, InvalidBlockNumber, SpGistMetaPageData::lastUsedPages, SpGistMetaPageData::magicNumber, SPGIST_CACHED_PAGES, SPGIST_MAGIC_NUMBER, SPGIST_META, SpGistInitPage(), and SpGistPageGetMeta.

Referenced by spgbuild(), and spgbuildempty().

564 {
565  SpGistMetaPageData *metadata;
566  int i;
567 
569  metadata = SpGistPageGetMeta(page);
570  memset(metadata, 0, sizeof(SpGistMetaPageData));
571  metadata->magicNumber = SPGIST_MAGIC_NUMBER;
572 
573  /* initialize last-used-page cache to empty */
574  for (i = 0; i < SPGIST_CACHED_PAGES; i++)
576 
577  /*
578  * Set pd_lower just past the end of the metadata. This is essential,
579  * because without doing so, metadata will be lost if xlog.c compresses
580  * the page.
581  */
582  ((PageHeader) page)->pd_lower =
583  ((char *) metadata + sizeof(SpGistMetaPageData)) - (char *) page;
584 }
SpGistLastUsedPage cachedPage[SPGIST_CACHED_PAGES]
#define SPGIST_META
#define SPGIST_MAGIC_NUMBER
SpGistLUPCache lastUsedPages
#define InvalidBlockNumber
Definition: block.h:33
#define SPGIST_CACHED_PAGES
#define SpGistPageGetMeta(p)
void SpGistInitPage(Page page, uint16 f)
Definition: spgutils.c:538
int i

◆ SpGistInitPage()

void SpGistInitPage ( Page  page,
uint16  f 
)

Definition at line 538 of file spgutils.c.

References SpGistPageOpaqueData::flags, MAXALIGN, PageInit(), SpGistPageOpaqueData::spgist_page_id, SPGIST_PAGE_ID, and SpGistPageGetOpaque.

Referenced by spgbuildempty(), SpGistInitBuffer(), and SpGistInitMetapage().

539 {
540  SpGistPageOpaque opaque;
541 
542  PageInit(page, BLCKSZ, MAXALIGN(sizeof(SpGistPageOpaqueData)));
543  opaque = SpGistPageGetOpaque(page);
544  memset(opaque, 0, sizeof(SpGistPageOpaqueData));
545  opaque->flags = f;
546  opaque->spgist_page_id = SPGIST_PAGE_ID;
547 }
#define SPGIST_PAGE_ID
#define MAXALIGN(LEN)
Definition: c.h:691
#define SpGistPageGetOpaque(page)
void PageInit(Page page, Size pageSize, Size specialSize)
Definition: bufpage.c:42

◆ SpGistNewBuffer()

Buffer SpGistNewBuffer ( Relation  index)

Definition at line 215 of file spgutils.c.

References BUFFER_LOCK_EXCLUSIVE, BUFFER_LOCK_UNLOCK, BufferGetPage, ConditionalLockBuffer(), ExclusiveLock, GetFreeIndexPage(), InvalidBlockNumber, LockBuffer(), LockRelationForExtension(), P_NEW, PageIsEmpty, PageIsNew, ReadBuffer(), RELATION_IS_LOCAL, ReleaseBuffer(), SpGistBlockIsFixed, SpGistPageIsDeleted, and UnlockRelationForExtension().

Referenced by allocNewBuffer(), and spgbuild().

216 {
217  Buffer buffer;
218  bool needLock;
219 
220  /* First, try to get a page from FSM */
221  for (;;)
222  {
223  BlockNumber blkno = GetFreeIndexPage(index);
224 
225  if (blkno == InvalidBlockNumber)
226  break; /* nothing known to FSM */
227 
228  /*
229  * The fixed pages shouldn't ever be listed in FSM, but just in case
230  * one is, ignore it.
231  */
232  if (SpGistBlockIsFixed(blkno))
233  continue;
234 
235  buffer = ReadBuffer(index, blkno);
236 
237  /*
238  * We have to guard against the possibility that someone else already
239  * recycled this page; the buffer may be locked if so.
240  */
241  if (ConditionalLockBuffer(buffer))
242  {
243  Page page = BufferGetPage(buffer);
244 
245  if (PageIsNew(page))
246  return buffer; /* OK to use, if never initialized */
247 
248  if (SpGistPageIsDeleted(page) || PageIsEmpty(page))
249  return buffer; /* OK to use */
250 
252  }
253 
254  /* Can't use it, so release buffer and try again */
255  ReleaseBuffer(buffer);
256  }
257 
258  /* Must extend the file */
259  needLock = !RELATION_IS_LOCAL(index);
260  if (needLock)
262 
263  buffer = ReadBuffer(index, P_NEW);
265 
266  if (needLock)
268 
269  return buffer;
270 }
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:86
#define PageIsEmpty(page)
Definition: bufpage.h:222
#define ExclusiveLock
Definition: lockdefs.h:44
#define RELATION_IS_LOCAL(relation)
Definition: rel.h:548
uint32 BlockNumber
Definition: block.h:31
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3375
#define P_NEW
Definition: bufmgr.h:81
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:88
#define SpGistBlockIsFixed(blkno)
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
bool ConditionalLockBuffer(Buffer buffer)
Definition: bufmgr.c:3638
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:402
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:452
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3612
BlockNumber GetFreeIndexPage(Relation rel)
Definition: indexfsm.c:38
#define SpGistPageIsDeleted(page)
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:596
#define InvalidBlockNumber
Definition: block.h:33
#define PageIsNew(page)
Definition: bufpage.h:229
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78

◆ SpGistPageAddNewItem()

OffsetNumber SpGistPageAddNewItem ( SpGistState state,
Page  page,
Item  item,
Size  size,
OffsetNumber startOffset,
bool  errorOK 
)

Definition at line 882 of file spgutils.c.

References Assert, elog, ERROR, FirstOffsetNumber, i, InvalidOffsetNumber, MAXALIGN, SpGistPageOpaqueData::nPlaceholder, PageAddItem, PageGetExactFreeSpace(), PageGetItem, PageGetItemId, PageGetMaxOffsetNumber, PageIndexTupleDelete(), PANIC, SGDTSIZE, SPGIST_PLACEHOLDER, SpGistPageGetOpaque, and SpGistDeadTupleData::tupstate.

Referenced by addLeafTuple(), doPickSplit(), moveLeafs(), spgAddNodeAction(), and spgSplitNodeAction().

884 {
885  SpGistPageOpaque opaque = SpGistPageGetOpaque(page);
886  OffsetNumber i,
887  maxoff,
888  offnum;
889 
890  if (opaque->nPlaceholder > 0 &&
891  PageGetExactFreeSpace(page) + SGDTSIZE >= MAXALIGN(size))
892  {
893  /* Try to replace a placeholder */
894  maxoff = PageGetMaxOffsetNumber(page);
895  offnum = InvalidOffsetNumber;
896 
897  for (;;)
898  {
899  if (startOffset && *startOffset != InvalidOffsetNumber)
900  i = *startOffset;
901  else
902  i = FirstOffsetNumber;
903  for (; i <= maxoff; i++)
904  {
906  PageGetItemId(page, i));
907 
908  if (it->tupstate == SPGIST_PLACEHOLDER)
909  {
910  offnum = i;
911  break;
912  }
913  }
914 
915  /* Done if we found a placeholder */
916  if (offnum != InvalidOffsetNumber)
917  break;
918 
919  if (startOffset && *startOffset != InvalidOffsetNumber)
920  {
921  /* Hint was no good, re-search from beginning */
922  *startOffset = InvalidOffsetNumber;
923  continue;
924  }
925 
926  /* Hmm, no placeholder found? */
927  opaque->nPlaceholder = 0;
928  break;
929  }
930 
931  if (offnum != InvalidOffsetNumber)
932  {
933  /* Replace the placeholder tuple */
934  PageIndexTupleDelete(page, offnum);
935 
936  offnum = PageAddItem(page, item, size, offnum, false, false);
937 
938  /*
939  * We should not have failed given the size check at the top of
940  * the function, but test anyway. If we did fail, we must PANIC
941  * because we've already deleted the placeholder tuple, and
942  * there's no other way to keep the damage from getting to disk.
943  */
944  if (offnum != InvalidOffsetNumber)
945  {
946  Assert(opaque->nPlaceholder > 0);
947  opaque->nPlaceholder--;
948  if (startOffset)
949  *startOffset = offnum + 1;
950  }
951  else
952  elog(PANIC, "failed to add item of size %u to SPGiST index page",
953  (int) size);
954 
955  return offnum;
956  }
957  }
958 
959  /* No luck in replacing a placeholder, so just add it to the page */
960  offnum = PageAddItem(page, item, size,
961  InvalidOffsetNumber, false, false);
962 
963  if (offnum == InvalidOffsetNumber && !errorOK)
964  elog(ERROR, "failed to add item of size %u to SPGiST index page",
965  (int) size);
966 
967  return offnum;
968 }
#define SGDTSIZE
void PageIndexTupleDelete(Page page, OffsetNumber offnum)
Definition: bufpage.c:719
#define SPGIST_PLACEHOLDER
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
Definition: bufpage.h:416
#define PANIC
Definition: elog.h:53
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
uint16 OffsetNumber
Definition: off.h:24
#define ERROR
Definition: elog.h:43
#define FirstOffsetNumber
Definition: off.h:27
SpGistDeadTupleData * SpGistDeadTuple
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
unsigned int tupstate
#define InvalidOffsetNumber
Definition: off.h:26
#define Assert(condition)
Definition: c.h:738
#define MAXALIGN(LEN)
Definition: c.h:691
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:625
#define SpGistPageGetOpaque(page)
#define elog(elevel,...)
Definition: elog.h:228
int i
#define PageGetItem(page, itemId)
Definition: bufpage.h:340

◆ SpGistSetLastUsedPage()

void SpGistSetLastUsedPage ( Relation  index,
Buffer  buffer 
)

Definition at line 503 of file spgutils.c.

References SpGistLastUsedPage::blkno, BufferGetBlockNumber(), BufferGetPage, SpGistLastUsedPage::freeSpace, GBUF_INNER_PARITY, GBUF_LEAF, GBUF_NULLS, GET_LUP, InvalidBlockNumber, PageGetExactFreeSpace(), spgGetCache(), SpGistBlockIsFixed, SpGistPageIsLeaf, and SpGistPageStoresNulls.

Referenced by doPickSplit(), moveLeafs(), spgAddNodeAction(), spgdoinsert(), spgMatchNodeAction(), spgprocesspending(), spgSplitNodeAction(), and spgvacuumpage().

504 {
505  SpGistCache *cache = spgGetCache(index);
506  SpGistLastUsedPage *lup;
507  int freeSpace;
508  Page page = BufferGetPage(buffer);
509  BlockNumber blkno = BufferGetBlockNumber(buffer);
510  int flags;
511 
512  /* Never enter fixed pages (root pages) in cache, though */
513  if (SpGistBlockIsFixed(blkno))
514  return;
515 
516  if (SpGistPageIsLeaf(page))
517  flags = GBUF_LEAF;
518  else
519  flags = GBUF_INNER_PARITY(blkno);
520  if (SpGistPageStoresNulls(page))
521  flags |= GBUF_NULLS;
522 
523  lup = GET_LUP(cache, flags);
524 
525  freeSpace = PageGetExactFreeSpace(page);
526  if (lup->blkno == InvalidBlockNumber || lup->blkno == blkno ||
527  lup->freeSpace < freeSpace)
528  {
529  lup->blkno = blkno;
530  lup->freeSpace = freeSpace;
531  }
532 }
#define SpGistPageIsLeaf(page)
SpGistCache * spgGetCache(Relation index)
Definition: spgutils.c:103
#define GET_LUP(c, f)
Definition: spgutils.c:320
uint32 BlockNumber
Definition: block.h:31
#define GBUF_INNER_PARITY(x)
#define SpGistBlockIsFixed(blkno)
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
#define GBUF_LEAF
#define SpGistPageStoresNulls(page)
#define InvalidBlockNumber
Definition: block.h:33
#define GBUF_NULLS
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:625
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2623
Pointer Page
Definition: bufpage.h:78

◆ SpGistUpdateMetaPage()

void SpGistUpdateMetaPage ( Relation  index)

Definition at line 280 of file spgutils.c.

References BufferGetPage, ConditionalLockBuffer(), SpGistMetaPageData::lastUsedPages, SpGistCache::lastUsedPages, MarkBufferDirty(), RelationData::rd_amcache, ReadBuffer(), ReleaseBuffer(), SPGIST_METAPAGE_BLKNO, SpGistPageGetMeta, and UnlockReleaseBuffer().

Referenced by spgbuild(), spginsert(), and spgvacuumscan().

281 {
282  SpGistCache *cache = (SpGistCache *) index->rd_amcache;
283 
284  if (cache != NULL)
285  {
286  Buffer metabuffer;
287 
288  metabuffer = ReadBuffer(index, SPGIST_METAPAGE_BLKNO);
289 
290  if (ConditionalLockBuffer(metabuffer))
291  {
292  Page metapage = BufferGetPage(metabuffer);
293  SpGistMetaPageData *metadata = SpGistPageGetMeta(metapage);
294 
295  metadata->lastUsedPages = cache->lastUsedPages;
296 
297  /*
298  * Set pd_lower just past the end of the metadata. This is
299  * essential, because without doing so, metadata will be lost if
300  * xlog.c compresses the page. (We must do this here because
301  * pre-v11 versions of PG did not set the metapage's pd_lower
302  * correctly, so a pg_upgraded index might contain the wrong
303  * value.)
304  */
305  ((PageHeader) metapage)->pd_lower =
306  ((char *) metadata + sizeof(SpGistMetaPageData)) - (char *) metapage;
307 
308  MarkBufferDirty(metabuffer);
309  UnlockReleaseBuffer(metabuffer);
310  }
311  else
312  {
313  ReleaseBuffer(metabuffer);
314  }
315  }
316 }
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1458
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3375
SpGistLUPCache lastUsedPages
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3398
#define SPGIST_METAPAGE_BLKNO
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
bool ConditionalLockBuffer(Buffer buffer)
Definition: bufmgr.c:3638
SpGistLUPCache lastUsedPages
PageHeaderData * PageHeader
Definition: bufpage.h:166
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:596
#define SpGistPageGetMeta(p)
void * rd_amcache
Definition: rel.h:185
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78

◆ spgPageIndexMultiDelete()

void spgPageIndexMultiDelete ( SpGistState state,
Page  page,
OffsetNumber itemnos,
int  nitems,
int  firststate,
int  reststate,
BlockNumber  blkno,
OffsetNumber  offnum 
)

Definition at line 131 of file spgdoinsert.c.

References cmpOffsetNumbers(), elog, ERROR, i, MaxIndexTuplesPerPage, PageAddItem, PageIndexMultiDelete(), qsort, SpGistDeadTupleData::size, spgFormDeadTuple(), SPGIST_PLACEHOLDER, SPGIST_REDIRECT, SpGistPageGetOpaque, and SpGistDeadTupleData::tupstate.

Referenced by doPickSplit(), moveLeafs(), spgRedoMoveLeafs(), spgRedoPickSplit(), spgRedoVacuumLeaf(), and vacuumLeafPage().

135 {
136  OffsetNumber firstItem;
138  SpGistDeadTuple tuple = NULL;
139  int i;
140 
141  if (nitems == 0)
142  return; /* nothing to do */
143 
144  /*
145  * For efficiency we want to use PageIndexMultiDelete, which requires the
146  * targets to be listed in sorted order, so we have to sort the itemnos
147  * array. (This also greatly simplifies the math for reinserting the
148  * replacement tuples.) However, we must not scribble on the caller's
149  * array, so we have to make a copy.
150  */
151  memcpy(sortednos, itemnos, sizeof(OffsetNumber) * nitems);
152  if (nitems > 1)
153  qsort(sortednos, nitems, sizeof(OffsetNumber), cmpOffsetNumbers);
154 
155  PageIndexMultiDelete(page, sortednos, nitems);
156 
157  firstItem = itemnos[0];
158 
159  for (i = 0; i < nitems; i++)
160  {
161  OffsetNumber itemno = sortednos[i];
162  int tupstate;
163 
164  tupstate = (itemno == firstItem) ? firststate : reststate;
165  if (tuple == NULL || tuple->tupstate != tupstate)
166  tuple = spgFormDeadTuple(state, tupstate, blkno, offnum);
167 
168  if (PageAddItem(page, (Item) tuple, tuple->size,
169  itemno, false, false) != itemno)
170  elog(ERROR, "failed to add item of size %u to SPGiST index page",
171  tuple->size);
172 
173  if (tupstate == SPGIST_REDIRECT)
174  SpGistPageGetOpaque(page)->nRedirection++;
175  else if (tupstate == SPGIST_PLACEHOLDER)
176  SpGistPageGetOpaque(page)->nPlaceholder++;
177  }
178 }
SpGistDeadTuple spgFormDeadTuple(SpGistState *state, int tupstate, BlockNumber blkno, OffsetNumber offnum)
Definition: spgutils.c:809
#define SPGIST_REDIRECT
#define SPGIST_PLACEHOLDER
Pointer Item
Definition: item.h:17
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
Definition: bufpage.h:416
uint16 OffsetNumber
Definition: off.h:24
#define ERROR
Definition: elog.h:43
unsigned int tupstate
void PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
Definition: bufpage.c:828
#define SpGistPageGetOpaque(page)
#define MaxIndexTuplesPerPage
Definition: itup.h:145
#define elog(elevel,...)
Definition: elog.h:228
int i
#define qsort(a, b, c, d)
Definition: port.h:474
static int cmpOffsetNumbers(const void *a, const void *b)
Definition: spgdoinsert.c:110

◆ spgproperty()

bool spgproperty ( Oid  index_oid,
int  attno,
IndexAMProperty  prop,
const char *  propname,
bool res,
bool isnull 
)

Definition at line 977 of file spgutils.c.

References AMOPSTRATEGY, AMPROP_DISTANCE_ORDERABLE, get_index_column_opclass(), get_op_rettype(), get_opclass_opfamily_and_input_type(), GETSTRUCT, i, catclist::members, catclist::n_members, ObjectIdGetDatum, OidIsValid, opfamily_can_sort_type(), ReleaseSysCacheList, SearchSysCacheList1, and catctup::tuple.

Referenced by spghandler().

980 {
981  Oid opclass,
982  opfamily,
983  opcintype;
984  CatCList *catlist;
985  int i;
986 
987  /* Only answer column-level inquiries */
988  if (attno == 0)
989  return false;
990 
991  switch (prop)
992  {
994  break;
995  default:
996  return false;
997  }
998 
999  /*
1000  * Currently, SP-GiST distance-ordered scans require that there be a
1001  * distance operator in the opclass with the default types. So we assume
1002  * that if such a operator exists, then there's a reason for it.
1003  */
1004 
1005  /* First we need to know the column's opclass. */
1006  opclass = get_index_column_opclass(index_oid, attno);
1007  if (!OidIsValid(opclass))
1008  {
1009  *isnull = true;
1010  return true;
1011  }
1012 
1013  /* Now look up the opclass family and input datatype. */
1014  if (!get_opclass_opfamily_and_input_type(opclass, &opfamily, &opcintype))
1015  {
1016  *isnull = true;
1017  return true;
1018  }
1019 
1020  /* And now we can check whether the operator is provided. */
1022  ObjectIdGetDatum(opfamily));
1023 
1024  *res = false;
1025 
1026  for (i = 0; i < catlist->n_members; i++)
1027  {
1028  HeapTuple amoptup = &catlist->members[i]->tuple;
1029  Form_pg_amop amopform = (Form_pg_amop) GETSTRUCT(amoptup);
1030 
1031  if (amopform->amoppurpose == AMOP_ORDER &&
1032  (amopform->amoplefttype == opcintype ||
1033  amopform->amoprighttype == opcintype) &&
1034  opfamily_can_sort_type(amopform->amopsortfamily,
1035  get_op_rettype(amopform->amopopr)))
1036  {
1037  *res = true;
1038  break;
1039  }
1040  }
1041 
1042  ReleaseSysCacheList(catlist);
1043 
1044  *isnull = false;
1045 
1046  return true;
1047 }
int n_members
Definition: catcache.h:176
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
bool opfamily_can_sort_type(Oid opfamilyoid, Oid datatypeoid)
Definition: amvalidate.c:217
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
Oid get_op_rettype(Oid opno)
Definition: lsyscache.c:1140
CatCTup * members[FLEXIBLE_ARRAY_MEMBER]
Definition: catcache.h:178
bool get_opclass_opfamily_and_input_type(Oid opclass, Oid *opfamily, Oid *opcintype)
Definition: lsyscache.c:1064
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define SearchSysCacheList1(cacheId, key1)
Definition: syscache.h:210
#define ReleaseSysCacheList(x)
Definition: syscache.h:217
Oid get_index_column_opclass(Oid index_oid, int attno)
Definition: lsyscache.c:3190
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
int i
HeapTupleData tuple
Definition: catcache.h:121

◆ spgUpdateNodeLink()

void spgUpdateNodeLink ( SpGistInnerTuple  tup,
int  nodeN,
BlockNumber  blkno,
OffsetNumber  offset 
)

Definition at line 50 of file spgdoinsert.c.

References elog, ERROR, i, ItemPointerSet, SPPageDesc::node, SGITITERATE, and IndexTupleData::t_tid.

Referenced by saveNodeLink(), spgRedoAddLeaf(), spgRedoAddNode(), spgRedoMoveLeafs(), spgRedoPickSplit(), and spgSplitNodeAction().

52 {
53  int i;
54  SpGistNodeTuple node;
55 
56  SGITITERATE(tup, i, node)
57  {
58  if (i == nodeN)
59  {
60  ItemPointerSet(&node->t_tid, blkno, offset);
61  return;
62  }
63  }
64 
65  elog(ERROR, "failed to find requested node %d in SPGiST inner tuple",
66  nodeN);
67 }
#define SGITITERATE(x, i, nt)
ItemPointerData t_tid
Definition: itup.h:37
#define ERROR
Definition: elog.h:43
#define elog(elevel,...)
Definition: elog.h:228
int i
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127