PostgreSQL Source Code  git master
spgutils.c File Reference
#include "postgres.h"
#include "access/amvalidate.h"
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "access/spgist_private.h"
#include "access/toast_compression.h"
#include "access/transam.h"
#include "access/xact.h"
#include "catalog/pg_amop.h"
#include "commands/vacuum.h"
#include "nodes/nodeFuncs.h"
#include "parser/parse_coerce.h"
#include "storage/bufmgr.h"
#include "storage/indexfsm.h"
#include "storage/lmgr.h"
#include "utils/builtins.h"
#include "utils/catcache.h"
#include "utils/index_selfuncs.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
Include dependency graph for spgutils.c:

Go to the source code of this file.

Macros

#define GET_LUP(c, f)   (&(c)->lastUsedPages.cachedPage[((unsigned int) (f)) % SPGIST_CACHED_PAGES])
 

Functions

Datum spghandler (PG_FUNCTION_ARGS)
 
static Oid GetIndexInputType (Relation index, AttrNumber indexcol)
 
static void fillTypeDesc (SpGistTypeDesc *desc, Oid type)
 
SpGistCachespgGetCache (Relation index)
 
TupleDesc getSpGistTupleDesc (Relation index, SpGistTypeDesc *keyType)
 
void initSpGistState (SpGistState *state, Relation index)
 
Buffer SpGistNewBuffer (Relation index)
 
void SpGistUpdateMetaPage (Relation index)
 
static Buffer allocNewBuffer (Relation index, int flags)
 
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)
 
byteaspgoptions (Datum reloptions, bool validate)
 
unsigned int SpGistGetInnerTypeSize (SpGistTypeDesc *att, Datum datum)
 
static void memcpyInnerDatum (void *target, SpGistTypeDesc *att, Datum datum)
 
Size SpGistGetLeafTupleSize (TupleDesc tupleDescriptor, Datum *datums, bool *isnulls)
 
SpGistLeafTuple spgFormLeafTuple (SpGistState *state, ItemPointer heapPtr, Datum *datums, bool *isnulls)
 
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)
 
void spgDeformLeafTuple (SpGistLeafTuple tup, TupleDesc tupleDescriptor, Datum *datums, bool *isnulls, bool keyColumnIsNull)
 
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)
 

Macro Definition Documentation

◆ GET_LUP

#define GET_LUP (   c,
 
)    (&(c)->lastUsedPages.cachedPage[((unsigned int) (f)) % SPGIST_CACHED_PAGES])

Definition at line 470 of file spgutils.c.

Function Documentation

◆ allocNewBuffer()

static Buffer allocNewBuffer ( Relation  index,
int  flags 
)
static

Definition at line 493 of file spgutils.c.

494 {
495  SpGistCache *cache = spgGetCache(index);
496  uint16 pageflags = 0;
497 
498  if (GBUF_REQ_LEAF(flags))
499  pageflags |= SPGIST_LEAF;
500  if (GBUF_REQ_NULLS(flags))
501  pageflags |= SPGIST_NULLS;
502 
503  for (;;)
504  {
505  Buffer buffer;
506 
507  buffer = SpGistNewBuffer(index);
508  SpGistInitBuffer(buffer, pageflags);
509 
510  if (pageflags & SPGIST_LEAF)
511  {
512  /* Leaf pages have no parity concerns, so just use it */
513  return buffer;
514  }
515  else
516  {
517  BlockNumber blkno = BufferGetBlockNumber(buffer);
518  int blkFlags = GBUF_INNER_PARITY(blkno);
519 
520  if ((flags & GBUF_PARITY_MASK) == blkFlags)
521  {
522  /* Page has right parity, use it */
523  return buffer;
524  }
525  else
526  {
527  /* Page has wrong parity, record it in cache and try again */
528  if (pageflags & SPGIST_NULLS)
529  blkFlags |= GBUF_NULLS;
530  cache->lastUsedPages.cachedPage[blkFlags].blkno = blkno;
531  cache->lastUsedPages.cachedPage[blkFlags].freeSpace =
533  UnlockReleaseBuffer(buffer);
534  }
535  }
536  }
537 }
uint32 BlockNumber
Definition: block.h:31
int Buffer
Definition: buf.h:23
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2763
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3954
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:280
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:958
unsigned short uint16
Definition: c.h:441
#define GBUF_NULLS
#define GBUF_PARITY_MASK
#define SPGIST_NULLS
#define GBUF_REQ_NULLS(flags)
#define GBUF_INNER_PARITY(x)
#define GBUF_REQ_LEAF(flags)
#define SPGIST_LEAF
Buffer SpGistNewBuffer(Relation index)
Definition: spgutils.c:365
void SpGistInitBuffer(Buffer b, uint16 f)
Definition: spgutils.c:702
SpGistCache * spgGetCache(Relation index)
Definition: spgutils.c:179
SpGistLUPCache lastUsedPages
SpGistLastUsedPage cachedPage[SPGIST_CACHED_PAGES]
Definition: type.h:95

References SpGistLastUsedPage::blkno, BufferGetBlockNumber(), BufferGetPage(), SpGistLUPCache::cachedPage, SpGistLastUsedPage::freeSpace, GBUF_INNER_PARITY, GBUF_NULLS, GBUF_PARITY_MASK, GBUF_REQ_LEAF, GBUF_REQ_NULLS, SpGistCache::lastUsedPages, PageGetExactFreeSpace(), spgGetCache(), SPGIST_LEAF, SPGIST_NULLS, SpGistInitBuffer(), SpGistNewBuffer(), and UnlockReleaseBuffer().

Referenced by SpGistGetBuffer().

◆ fillTypeDesc()

static void fillTypeDesc ( SpGistTypeDesc desc,
Oid  type 
)
static

Definition at line 157 of file spgutils.c.

158 {
159  HeapTuple tp;
160  Form_pg_type typtup;
161 
162  desc->type = type;
164  if (!HeapTupleIsValid(tp))
165  elog(ERROR, "cache lookup failed for type %u", type);
166  typtup = (Form_pg_type) GETSTRUCT(tp);
167  desc->attlen = typtup->typlen;
168  desc->attbyval = typtup->typbyval;
169  desc->attalign = typtup->typalign;
170  desc->attstorage = typtup->typstorage;
171  ReleaseSysCache(tp);
172 }
#define ERROR
Definition: elog.h:35
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:600
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1221
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1173
@ TYPEOID
Definition: syscache.h:114

References SpGistTypeDesc::attalign, SpGistTypeDesc::attbyval, SpGistTypeDesc::attlen, SpGistTypeDesc::attstorage, elog(), ERROR, GETSTRUCT, HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), generate_unaccent_rules::type, SpGistTypeDesc::type, and TYPEOID.

Referenced by spgGetCache().

◆ GetIndexInputType()

static Oid GetIndexInputType ( Relation  index,
AttrNumber  indexcol 
)
static

Definition at line 112 of file spgutils.c.

113 {
114  Oid opcintype;
115  AttrNumber heapcol;
116  List *indexprs;
117  ListCell *indexpr_item;
118 
119  Assert(index->rd_index != NULL);
120  Assert(indexcol > 0 && indexcol <= index->rd_index->indnkeyatts);
121  opcintype = index->rd_opcintype[indexcol - 1];
122  if (!IsPolymorphicType(opcintype))
123  return opcintype;
124  heapcol = index->rd_index->indkey.values[indexcol - 1];
125  if (heapcol != 0) /* Simple index column? */
126  return getBaseType(get_atttype(index->rd_index->indrelid, heapcol));
127 
128  /*
129  * If the index expressions are already cached, skip calling
130  * RelationGetIndexExpressions, as it will make a copy which is overkill.
131  * We're not going to modify the trees, and we're not going to do anything
132  * that would invalidate the relcache entry before we're done.
133  */
134  if (index->rd_indexprs)
135  indexprs = index->rd_indexprs;
136  else
138  indexpr_item = list_head(indexprs);
139  for (int i = 1; i <= index->rd_index->indnkeyatts; i++)
140  {
141  if (index->rd_index->indkey.values[i - 1] == 0)
142  {
143  /* expression column */
144  if (indexpr_item == NULL)
145  elog(ERROR, "wrong number of index expressions");
146  if (i == indexcol)
147  return getBaseType(exprType((Node *) lfirst(indexpr_item)));
148  indexpr_item = lnext(indexprs, indexpr_item);
149  }
150  }
151  elog(ERROR, "wrong number of index expressions");
152  return InvalidOid; /* keep compiler quiet */
153 }
int16 AttrNumber
Definition: attnum.h:21
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2479
Oid get_atttype(Oid relid, AttrNumber attnum)
Definition: lsyscache.c:939
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
#define lfirst(lc)
Definition: pg_list.h:170
static ListCell * list_head(const List *l)
Definition: pg_list.h:126
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:341
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
List * RelationGetIndexExpressions(Relation relation)
Definition: relcache.c:4972
Definition: pg_list.h:52
Definition: nodes.h:118

References Assert(), elog(), ERROR, exprType(), get_atttype(), getBaseType(), i, InvalidOid, lfirst, list_head(), lnext(), and RelationGetIndexExpressions().

Referenced by spgGetCache().

◆ getSpGistTupleDesc()

TupleDesc getSpGistTupleDesc ( Relation  index,
SpGistTypeDesc keyType 
)

Definition at line 299 of file spgutils.c.

300 {
301  TupleDesc outTupDesc;
302  Form_pg_attribute att;
303 
304  if (keyType->type ==
306  outTupDesc = RelationGetDescr(index);
307  else
308  {
310  att = TupleDescAttr(outTupDesc, spgKeyColumn);
311  /* It's sufficient to update the type-dependent fields of the column */
312  att->atttypid = keyType->type;
313  att->atttypmod = -1;
314  att->attlen = keyType->attlen;
315  att->attbyval = keyType->attbyval;
316  att->attalign = keyType->attalign;
317  att->attstorage = keyType->attstorage;
318  /* We shouldn't need to bother with making these valid: */
319  att->attcompression = InvalidCompressionMethod;
320  att->attcollation = InvalidOid;
321  /* In case we changed typlen, we'd better reset following offsets */
322  for (int i = spgFirstIncludeColumn; i < outTupDesc->natts; i++)
323  TupleDescAttr(outTupDesc, i)->attcacheoff = -1;
324  }
325  return outTupDesc;
326 }
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
#define RelationGetDescr(relation)
Definition: rel.h:527
#define spgFirstIncludeColumn
#define spgKeyColumn
#define InvalidCompressionMethod
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

References SpGistTypeDesc::attalign, SpGistTypeDesc::attbyval, SpGistTypeDesc::attlen, SpGistTypeDesc::attstorage, CreateTupleDescCopy(), i, InvalidCompressionMethod, InvalidOid, TupleDescData::natts, RelationGetDescr, spgFirstIncludeColumn, spgKeyColumn, TupleDescAttr, and SpGistTypeDesc::type.

Referenced by initSpGistState(), and spgbeginscan().

◆ initSpGistState()

void initSpGistState ( SpGistState state,
Relation  index 
)

Definition at line 330 of file spgutils.c.

331 {
332  SpGistCache *cache;
333 
334  state->index = index;
335 
336  /* Get cached static information about index */
337  cache = spgGetCache(index);
338 
339  state->config = cache->config;
340  state->attType = cache->attType;
341  state->attLeafType = cache->attLeafType;
342  state->attPrefixType = cache->attPrefixType;
343  state->attLabelType = cache->attLabelType;
344 
345  /* Ensure we have a valid descriptor for leaf tuples */
346  state->leafTupDesc = getSpGistTupleDesc(state->index, &state->attLeafType);
347 
348  /* Make workspace for constructing dead tuples */
349  state->deadTupleStorage = palloc0(SGDTSIZE);
350 
351  /* Set XID to use in redirection tuples */
352  state->myXid = GetTopTransactionIdIfAny();
353 
354  /* Assume we're not in an index build (spgbuild will override) */
355  state->isBuild = false;
356 }
void * palloc0(Size size)
Definition: mcxt.c:1230
#define SGDTSIZE
TupleDesc getSpGistTupleDesc(Relation index, SpGistTypeDesc *keyType)
Definition: spgutils.c:299
SpGistTypeDesc attPrefixType
SpGistTypeDesc attLeafType
SpGistTypeDesc attType
spgConfigOut config
SpGistTypeDesc attLabelType
Definition: regguts.h:318
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:431

References SpGistCache::attLabelType, SpGistCache::attLeafType, SpGistCache::attPrefixType, SpGistCache::attType, SpGistCache::config, getSpGistTupleDesc(), GetTopTransactionIdIfAny(), palloc0(), SGDTSIZE, and spgGetCache().

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

◆ memcpyInnerDatum()

static void memcpyInnerDatum ( void *  target,
SpGistTypeDesc att,
Datum  datum 
)
static

Definition at line 777 of file spgutils.c.

778 {
779  unsigned int size;
780 
781  if (att->attbyval)
782  {
783  memcpy(target, &datum, sizeof(Datum));
784  }
785  else
786  {
787  size = (att->attlen > 0) ? att->attlen : VARSIZE_ANY(datum);
788  memcpy(target, DatumGetPointer(datum), size);
789  }
790 }
uintptr_t Datum
Definition: postgres.h:412
#define VARSIZE_ANY(PTR)
Definition: postgres.h:349
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:660

References SpGistTypeDesc::attbyval, SpGistTypeDesc::attlen, DatumGetPointer(), and VARSIZE_ANY.

Referenced by spgFormInnerTuple(), and spgFormNodeTuple().

◆ spgDeformLeafTuple()

void spgDeformLeafTuple ( SpGistLeafTuple  tup,
TupleDesc  tupleDescriptor,
Datum datums,
bool isnulls,
bool  keyColumnIsNull 
)

Definition at line 1096 of file spgutils.c.

1098 {
1099  bool hasNullsMask = SGLT_GET_HASNULLMASK(tup);
1100  char *tp; /* ptr to tuple data */
1101  bits8 *bp; /* ptr to null bitmap in tuple */
1102 
1103  if (keyColumnIsNull && tupleDescriptor->natts == 1)
1104  {
1105  /*
1106  * Trivial case: there is only the key attribute and we're in a nulls
1107  * tree. The hasNullsMask bit in the tuple header should not be set
1108  * (and thus we can't use index_deform_tuple_internal), but
1109  * nonetheless the result is NULL.
1110  *
1111  * Note: currently this is dead code, because noplace calls this when
1112  * there is only the key attribute. But we should cover the case.
1113  */
1114  Assert(!hasNullsMask);
1115 
1116  datums[spgKeyColumn] = (Datum) 0;
1117  isnulls[spgKeyColumn] = true;
1118  return;
1119  }
1120 
1121  tp = (char *) tup + SGLTHDRSZ(hasNullsMask);
1122  bp = (bits8 *) ((char *) tup + sizeof(SpGistLeafTupleData));
1123 
1124  index_deform_tuple_internal(tupleDescriptor,
1125  datums, isnulls,
1126  tp, bp, hasNullsMask);
1127 
1128  /*
1129  * Key column isnull value from the tuple should be consistent with
1130  * keyColumnIsNull flag from the caller.
1131  */
1132  Assert(keyColumnIsNull == isnulls[spgKeyColumn]);
1133 }
uint8 bits8
Definition: c.h:449
void index_deform_tuple_internal(TupleDesc tupleDescriptor, Datum *values, bool *isnull, char *tp, bits8 *bp, int hasnulls)
Definition: indextuple.c:479
#define SGLT_GET_HASNULLMASK(spgLeafTuple)
#define SGLTHDRSZ(hasnulls)
struct SpGistLeafTupleData SpGistLeafTupleData

References Assert(), index_deform_tuple_internal(), TupleDescData::natts, SGLT_GET_HASNULLMASK, SGLTHDRSZ, and spgKeyColumn.

Referenced by doPickSplit(), and storeGettuple().

◆ spgExtractNodeLabels()

Datum* spgExtractNodeLabels ( SpGistState state,
SpGistInnerTuple  innerTuple 
)

Definition at line 1141 of file spgutils.c.

1142 {
1143  Datum *nodeLabels;
1144  int i;
1145  SpGistNodeTuple node;
1146 
1147  /* Either all the labels must be NULL, or none. */
1148  node = SGITNODEPTR(innerTuple);
1149  if (IndexTupleHasNulls(node))
1150  {
1151  SGITITERATE(innerTuple, i, node)
1152  {
1153  if (!IndexTupleHasNulls(node))
1154  elog(ERROR, "some but not all node labels are null in SPGiST inner tuple");
1155  }
1156  /* They're all null, so just return NULL */
1157  return NULL;
1158  }
1159  else
1160  {
1161  nodeLabels = (Datum *) palloc(sizeof(Datum) * innerTuple->nNodes);
1162  SGITITERATE(innerTuple, i, node)
1163  {
1164  if (IndexTupleHasNulls(node))
1165  elog(ERROR, "some but not all node labels are null in SPGiST inner tuple");
1166  nodeLabels[i] = SGNTDATUM(node, state);
1167  }
1168  return nodeLabels;
1169  }
1170 }
#define IndexTupleHasNulls(itup)
Definition: itup.h:71
void * palloc(Size size)
Definition: mcxt.c:1199
#define SGITITERATE(x, i, nt)
#define SGNTDATUM(x, s)
#define SGITNODEPTR(x)

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

Referenced by spgdoinsert(), and spgInitInnerConsistentIn().

◆ spgFormDeadTuple()

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

Definition at line 1065 of file spgutils.c.

1067 {
1068  SpGistDeadTuple tuple = (SpGistDeadTuple) state->deadTupleStorage;
1069 
1070  tuple->tupstate = tupstate;
1071  tuple->size = SGDTSIZE;
1073 
1074  if (tupstate == SPGIST_REDIRECT)
1075  {
1076  ItemPointerSet(&tuple->pointer, blkno, offnum);
1078  tuple->xid = state->myXid;
1079  }
1080  else
1081  {
1082  ItemPointerSetInvalid(&tuple->pointer);
1083  tuple->xid = InvalidTransactionId;
1084  }
1085 
1086  return tuple;
1087 }
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
Definition: itemptr.h:135
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
#define InvalidOffsetNumber
Definition: off.h:26
SpGistDeadTupleData * SpGistDeadTuple
#define SPGIST_REDIRECT
#define SGLT_SET_NEXTOFFSET(spgLeafTuple, offsetNumber)
unsigned int tupstate
ItemPointerData pointer
#define InvalidTransactionId
Definition: transam.h:31
#define TransactionIdIsValid(xid)
Definition: transam.h:41

References Assert(), InvalidOffsetNumber, InvalidTransactionId, ItemPointerSet(), ItemPointerSetInvalid(), SpGistDeadTupleData::pointer, SGDTSIZE, SGLT_SET_NEXTOFFSET, SpGistDeadTupleData::size, SPGIST_REDIRECT, TransactionIdIsValid, SpGistDeadTupleData::tupstate, and SpGistDeadTupleData::xid.

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

◆ spgFormInnerTuple()

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

Definition at line 982 of file spgutils.c.

984 {
985  SpGistInnerTuple tup;
986  unsigned int size;
987  unsigned int prefixSize;
988  int i;
989  char *ptr;
990 
991  /* Compute size needed */
992  if (hasPrefix)
993  prefixSize = SpGistGetInnerTypeSize(&state->attPrefixType, prefix);
994  else
995  prefixSize = 0;
996 
997  size = SGITHDRSZ + prefixSize;
998 
999  /* Note: we rely on node tuple sizes to be maxaligned already */
1000  for (i = 0; i < nNodes; i++)
1001  size += IndexTupleSize(nodes[i]);
1002 
1003  /*
1004  * Ensure that we can replace the tuple with a dead tuple later. This
1005  * test is unnecessary given current tuple layouts, but let's be safe.
1006  */
1007  if (size < SGDTSIZE)
1008  size = SGDTSIZE;
1009 
1010  /*
1011  * Inner tuple should be small enough to fit on a page
1012  */
1013  if (size > SPGIST_PAGE_CAPACITY - sizeof(ItemIdData))
1014  ereport(ERROR,
1015  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1016  errmsg("SP-GiST inner tuple size %zu exceeds maximum %zu",
1017  (Size) size,
1018  SPGIST_PAGE_CAPACITY - sizeof(ItemIdData)),
1019  errhint("Values larger than a buffer page cannot be indexed.")));
1020 
1021  /*
1022  * Check for overflow of header fields --- probably can't fail if the
1023  * above succeeded, but let's be paranoid
1024  */
1025  if (size > SGITMAXSIZE ||
1026  prefixSize > SGITMAXPREFIXSIZE ||
1027  nNodes > SGITMAXNNODES)
1028  elog(ERROR, "SPGiST inner tuple header field is too small");
1029 
1030  /* OK, form the tuple */
1031  tup = (SpGistInnerTuple) palloc0(size);
1032 
1033  tup->nNodes = nNodes;
1034  tup->prefixSize = prefixSize;
1035  tup->size = size;
1036 
1037  if (hasPrefix)
1038  memcpyInnerDatum(SGITDATAPTR(tup), &state->attPrefixType, prefix);
1039 
1040  ptr = (char *) SGITNODEPTR(tup);
1041 
1042  for (i = 0; i < nNodes; i++)
1043  {
1044  SpGistNodeTuple node = nodes[i];
1045 
1046  memcpy(ptr, node, IndexTupleSize(node));
1047  ptr += IndexTupleSize(node);
1048  }
1049 
1050  return tup;
1051 }
size_t Size
Definition: c.h:541
int errhint(const char *fmt,...)
Definition: elog.c:1153
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ereport(elevel,...)
Definition: elog.h:145
#define IndexTupleSize(itup)
Definition: itup.h:70
SpGistInnerTupleData * SpGistInnerTuple
#define SGITDATAPTR(x)
#define SGITMAXSIZE
#define SGITMAXPREFIXSIZE
#define SGITHDRSZ
#define SPGIST_PAGE_CAPACITY
#define SGITMAXNNODES
static void memcpyInnerDatum(void *target, SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:777
unsigned int SpGistGetInnerTypeSize(SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:759
unsigned int prefixSize

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

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

◆ spgFormLeafTuple()

SpGistLeafTuple spgFormLeafTuple ( SpGistState state,
ItemPointer  heapPtr,
Datum datums,
bool isnulls 
)

Definition at line 851 of file spgutils.c.

853 {
854  SpGistLeafTuple tup;
855  TupleDesc tupleDescriptor = state->leafTupDesc;
856  Size size;
857  Size hoff;
858  Size data_size;
859  bool needs_null_mask = false;
860  int natts = tupleDescriptor->natts;
861  char *tp; /* ptr to tuple data */
862  uint16 tupmask = 0; /* unused heap_fill_tuple output */
863 
864  /*
865  * Decide whether we need a nulls bitmask.
866  *
867  * If there is only a key attribute (natts == 1), never use a bitmask, for
868  * compatibility with the pre-v14 layout of leaf tuples. Otherwise, we
869  * need one if any attribute is null.
870  */
871  if (natts > 1)
872  {
873  for (int i = 0; i < natts; i++)
874  {
875  if (isnulls[i])
876  {
877  needs_null_mask = true;
878  break;
879  }
880  }
881  }
882 
883  /*
884  * Calculate size of the data part; same as for heap tuples.
885  */
886  data_size = heap_compute_data_size(tupleDescriptor, datums, isnulls);
887 
888  /*
889  * Compute total size.
890  */
891  hoff = SGLTHDRSZ(needs_null_mask);
892  size = hoff + data_size;
893  size = MAXALIGN(size);
894 
895  /*
896  * Ensure that we can replace the tuple with a dead tuple later. This test
897  * is unnecessary when there are any non-null attributes, but be safe.
898  */
899  if (size < SGDTSIZE)
900  size = SGDTSIZE;
901 
902  /* OK, form the tuple */
903  tup = (SpGistLeafTuple) palloc0(size);
904 
905  tup->size = size;
907  tup->heapPtr = *heapPtr;
908 
909  tp = (char *) tup + hoff;
910 
911  if (needs_null_mask)
912  {
913  bits8 *bp; /* ptr to null bitmap in tuple */
914 
915  /* Set nullmask presence bit in SpGistLeafTuple header */
916  SGLT_SET_HASNULLMASK(tup, true);
917  /* Fill the data area and null mask */
918  bp = (bits8 *) ((char *) tup + sizeof(SpGistLeafTupleData));
919  heap_fill_tuple(tupleDescriptor, datums, isnulls, tp, data_size,
920  &tupmask, bp);
921  }
922  else if (natts > 1 || !isnulls[spgKeyColumn])
923  {
924  /* Fill data area only */
925  heap_fill_tuple(tupleDescriptor, datums, isnulls, tp, data_size,
926  &tupmask, (bits8 *) NULL);
927  }
928  /* otherwise we have no data, nor a bitmap, to fill */
929 
930  return tup;
931 }
#define MAXALIGN(LEN)
Definition: c.h:747
Size heap_compute_data_size(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:119
void heap_fill_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull, char *data, Size data_size, uint16 *infomask, bits8 *bit)
Definition: heaptuple.c:304
#define SGLT_SET_HASNULLMASK(spgLeafTuple, hasnulls)
struct SpGistLeafTupleData * SpGistLeafTuple
ItemPointerData heapPtr

References heap_compute_data_size(), heap_fill_tuple(), SpGistLeafTupleData::heapPtr, i, InvalidOffsetNumber, MAXALIGN, TupleDescData::natts, palloc0(), SGDTSIZE, SGLT_SET_HASNULLMASK, SGLT_SET_NEXTOFFSET, SGLTHDRSZ, SpGistLeafTupleData::size, and spgKeyColumn.

Referenced by doPickSplit(), and spgdoinsert().

◆ spgFormNodeTuple()

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

Definition at line 940 of file spgutils.c.

941 {
942  SpGistNodeTuple tup;
943  unsigned int size;
944  unsigned short infomask = 0;
945 
946  /* compute space needed (note result is already maxaligned) */
947  size = SGNTHDRSZ;
948  if (!isnull)
949  size += SpGistGetInnerTypeSize(&state->attLabelType, label);
950 
951  /*
952  * Here we make sure that the size will fit in the field reserved for it
953  * in t_info.
954  */
955  if ((size & INDEX_SIZE_MASK) != size)
956  ereport(ERROR,
957  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
958  errmsg("index row requires %zu bytes, maximum size is %zu",
959  (Size) size, (Size) INDEX_SIZE_MASK)));
960 
961  tup = (SpGistNodeTuple) palloc0(size);
962 
963  if (isnull)
964  infomask |= INDEX_NULL_MASK;
965  /* we don't bother setting the INDEX_VAR_MASK bit */
966  infomask |= size;
967  tup->t_info = infomask;
968 
969  /* The TID field will be filled in later */
971 
972  if (!isnull)
973  memcpyInnerDatum(SGNTDATAPTR(tup), &state->attLabelType, label);
974 
975  return tup;
976 }
#define INDEX_NULL_MASK
Definition: itup.h:68
#define INDEX_SIZE_MASK
Definition: itup.h:65
static char * label
#define SGNTDATAPTR(x)
SpGistNodeTupleData * SpGistNodeTuple
#define SGNTHDRSZ
ItemPointerData t_tid
Definition: itup.h:37
unsigned short t_info
Definition: itup.h:49

References ereport, errcode(), errmsg(), ERROR, INDEX_NULL_MASK, INDEX_SIZE_MASK, ItemPointerSetInvalid(), label, memcpyInnerDatum(), palloc0(), SGNTDATAPTR, SGNTHDRSZ, SpGistGetInnerTypeSize(), IndexTupleData::t_info, and IndexTupleData::t_tid.

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

◆ spgGetCache()

SpGistCache* spgGetCache ( Relation  index)

Definition at line 179 of file spgutils.c.

180 {
181  SpGistCache *cache;
182 
183  if (index->rd_amcache == NULL)
184  {
185  Oid atttype;
186  spgConfigIn in;
187  FmgrInfo *procinfo;
188  Buffer metabuffer;
189  SpGistMetaPageData *metadata;
190 
191  cache = MemoryContextAllocZero(index->rd_indexcxt,
192  sizeof(SpGistCache));
193 
194  /* SPGiST must have one key column and can also have INCLUDE columns */
197 
198  /*
199  * Get the actual (well, nominal) data type of the key column. We
200  * pass this to the opclass config function so that polymorphic
201  * opclasses are possible.
202  */
203  atttype = GetIndexInputType(index, spgKeyColumn + 1);
204 
205  /* Call the config function to get config info for the opclass */
206  in.attType = atttype;
207 
209  FunctionCall2Coll(procinfo,
210  index->rd_indcollation[spgKeyColumn],
211  PointerGetDatum(&in),
212  PointerGetDatum(&cache->config));
213 
214  /*
215  * If leafType isn't specified, use the declared index column type,
216  * which index.c will have derived from the opclass's opcintype.
217  * (Although we now make spgvalidate.c warn if these aren't the same,
218  * old user-defined opclasses may not set the STORAGE parameter
219  * correctly, so believe leafType if it's given.)
220  */
221  if (!OidIsValid(cache->config.leafType))
222  {
223  cache->config.leafType =
225 
226  /*
227  * If index column type is binary-coercible to atttype (for
228  * example, it's a domain over atttype), treat it as plain atttype
229  * to avoid thinking we need to compress.
230  */
231  if (cache->config.leafType != atttype &&
232  IsBinaryCoercible(cache->config.leafType, atttype))
233  cache->config.leafType = atttype;
234  }
235 
236  /* Get the information we need about each relevant datatype */
237  fillTypeDesc(&cache->attType, atttype);
238 
239  if (cache->config.leafType != atttype)
240  {
242  ereport(ERROR,
243  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
244  errmsg("compress method must be defined when leaf type is different from input type")));
245 
246  fillTypeDesc(&cache->attLeafType, cache->config.leafType);
247  }
248  else
249  {
250  /* Save lookups in this common case */
251  cache->attLeafType = cache->attType;
252  }
253 
254  fillTypeDesc(&cache->attPrefixType, cache->config.prefixType);
255  fillTypeDesc(&cache->attLabelType, cache->config.labelType);
256 
257  /* Last, get the lastUsedPages data from the metapage */
258  metabuffer = ReadBuffer(index, SPGIST_METAPAGE_BLKNO);
259  LockBuffer(metabuffer, BUFFER_LOCK_SHARE);
260 
261  metadata = SpGistPageGetMeta(BufferGetPage(metabuffer));
262 
263  if (metadata->magicNumber != SPGIST_MAGIC_NUMBER)
264  elog(ERROR, "index \"%s\" is not an SP-GiST index",
266 
267  cache->lastUsedPages = metadata->lastUsedPages;
268 
269  UnlockReleaseBuffer(metabuffer);
270 
271  index->rd_amcache = (void *) cache;
272  }
273  else
274  {
275  /* assume it's up to date */
276  cache = (SpGistCache *) index->rd_amcache;
277  }
278 
279  return cache;
280 }
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4172
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:712
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:106
#define OidIsValid(objectId)
Definition: c.h:711
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1134
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:811
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:777
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1037
bool IsBinaryCoercible(Oid srctype, Oid targettype)
#define INDEX_MAX_KEYS
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:670
#define RelationGetRelationName(relation)
Definition: rel.h:535
#define IndexRelationGetNumberOfAttributes(relation)
Definition: rel.h:513
#define IndexRelationGetNumberOfKeyAttributes(relation)
Definition: rel.h:520
#define SPGIST_COMPRESS_PROC
Definition: spgist.h:28
#define SPGIST_CONFIG_PROC
Definition: spgist.h:23
#define SpGistPageGetMeta(p)
#define SPGIST_METAPAGE_BLKNO
#define SPGIST_MAGIC_NUMBER
static Oid GetIndexInputType(Relation index, AttrNumber indexcol)
Definition: spgutils.c:112
static void fillTypeDesc(SpGistTypeDesc *desc, Oid type)
Definition: spgutils.c:157
Definition: fmgr.h:57
SpGistLUPCache lastUsedPages
Oid attType
Definition: spgist.h:38
Oid leafType
Definition: spgist.h:45
Oid labelType
Definition: spgist.h:44
Oid prefixType
Definition: spgist.h:43

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(), GetIndexInputType(), index_getprocid(), index_getprocinfo(), INDEX_MAX_KEYS, IndexRelationGetNumberOfAttributes, IndexRelationGetNumberOfKeyAttributes, IsBinaryCoercible(), spgConfigOut::labelType, SpGistMetaPageData::lastUsedPages, SpGistCache::lastUsedPages, spgConfigOut::leafType, LockBuffer(), SpGistMetaPageData::magicNumber, MemoryContextAllocZero(), OidIsValid, PointerGetDatum(), spgConfigOut::prefixType, ReadBuffer(), RelationGetDescr, RelationGetRelationName, SPGIST_COMPRESS_PROC, SPGIST_CONFIG_PROC, SPGIST_MAGIC_NUMBER, SPGIST_METAPAGE_BLKNO, SpGistPageGetMeta, spgKeyColumn, TupleDescAttr, and UnlockReleaseBuffer().

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

◆ spghandler()

Datum spghandler ( PG_FUNCTION_ARGS  )

Definition at line 44 of file spgutils.c.

45 {
47 
48  amroutine->amstrategies = 0;
49  amroutine->amsupport = SPGISTNProc;
51  amroutine->amcanorder = false;
52  amroutine->amcanorderbyop = true;
53  amroutine->amcanbackward = false;
54  amroutine->amcanunique = false;
55  amroutine->amcanmulticol = false;
56  amroutine->amoptionalkey = true;
57  amroutine->amsearcharray = false;
58  amroutine->amsearchnulls = true;
59  amroutine->amstorage = true;
60  amroutine->amclusterable = false;
61  amroutine->ampredlocks = false;
62  amroutine->amcanparallel = false;
63  amroutine->amcaninclude = true;
64  amroutine->amusemaintenanceworkmem = false;
65  amroutine->amparallelvacuumoptions =
67  amroutine->amkeytype = InvalidOid;
68 
69  amroutine->ambuild = spgbuild;
70  amroutine->ambuildempty = spgbuildempty;
71  amroutine->aminsert = spginsert;
72  amroutine->ambulkdelete = spgbulkdelete;
73  amroutine->amvacuumcleanup = spgvacuumcleanup;
74  amroutine->amcanreturn = spgcanreturn;
75  amroutine->amcostestimate = spgcostestimate;
76  amroutine->amoptions = spgoptions;
77  amroutine->amproperty = spgproperty;
78  amroutine->ambuildphasename = NULL;
79  amroutine->amvalidate = spgvalidate;
80  amroutine->amadjustmembers = spgadjustmembers;
81  amroutine->ambeginscan = spgbeginscan;
82  amroutine->amrescan = spgrescan;
83  amroutine->amgettuple = spggettuple;
84  amroutine->amgetbitmap = spggetbitmap;
85  amroutine->amendscan = spgendscan;
86  amroutine->ammarkpos = NULL;
87  amroutine->amrestrpos = NULL;
88  amroutine->amestimateparallelscan = NULL;
89  amroutine->aminitparallelscan = NULL;
90  amroutine->amparallelrescan = NULL;
91 
92  PG_RETURN_POINTER(amroutine);
93 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define makeNode(_type_)
Definition: nodes.h:165
void spgcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Definition: selfuncs.c:7075
bool spginsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
Definition: spginsert.c:207
void spgbuildempty(Relation index)
Definition: spginsert.c:156
IndexBuildResult * spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
Definition: spginsert.c:75
#define SPGIST_OPTIONS_PROC
Definition: spgist.h:29
#define SPGISTNProc
Definition: spgist.h:31
IndexScanDesc spgbeginscan(Relation rel, int keysz, int orderbysz)
Definition: spgscan.c:304
bool spgcanreturn(Relation index, int attno)
Definition: spgscan.c:1085
bool spggettuple(IndexScanDesc scan, ScanDirection dir)
Definition: spgscan.c:1027
void spgendscan(IndexScanDesc scan)
Definition: spgscan.c:429
void spgrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
Definition: spgscan.c:380
int64 spggetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
Definition: spgscan.c:943
bytea * spgoptions(Datum reloptions, bool validate)
Definition: spgutils.c:739
bool spgproperty(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
Definition: spgutils.c:1279
IndexBulkDeleteResult * spgvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: spgvacuum.c:937
IndexBulkDeleteResult * spgbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition: spgvacuum.c:906
bool spgvalidate(Oid opclassoid)
Definition: spgvalidate.c:39
void spgadjustmembers(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
Definition: spgvalidate.c:332
ambuildphasename_function ambuildphasename
Definition: amapi.h:268
ambuildempty_function ambuildempty
Definition: amapi.h:260
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:263
bool amclusterable
Definition: amapi.h:238
amoptions_function amoptions
Definition: amapi.h:266
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:280
amrestrpos_function amrestrpos
Definition: amapi.h:277
aminsert_function aminsert
Definition: amapi.h:261
amendscan_function amendscan
Definition: amapi.h:275
uint16 amoptsprocnum
Definition: amapi.h:218
amparallelrescan_function amparallelrescan
Definition: amapi.h:282
Oid amkeytype
Definition: amapi.h:250
bool ampredlocks
Definition: amapi.h:240
uint16 amsupport
Definition: amapi.h:216
amcostestimate_function amcostestimate
Definition: amapi.h:265
bool amcanorderbyop
Definition: amapi.h:222
amadjustmembers_function amadjustmembers
Definition: amapi.h:270
ambuild_function ambuild
Definition: amapi.h:259
bool amstorage
Definition: amapi.h:236
uint16 amstrategies
Definition: amapi.h:214
bool amoptionalkey
Definition: amapi.h:230
amgettuple_function amgettuple
Definition: amapi.h:273
amcanreturn_function amcanreturn
Definition: amapi.h:264
bool amcanunique
Definition: amapi.h:226
amgetbitmap_function amgetbitmap
Definition: amapi.h:274
amproperty_function amproperty
Definition: amapi.h:267
ambulkdelete_function ambulkdelete
Definition: amapi.h:262
bool amsearcharray
Definition: amapi.h:232
amvalidate_function amvalidate
Definition: amapi.h:269
ammarkpos_function ammarkpos
Definition: amapi.h:276
bool amcanmulticol
Definition: amapi.h:228
bool amusemaintenanceworkmem
Definition: amapi.h:246
ambeginscan_function ambeginscan
Definition: amapi.h:271
bool amcanparallel
Definition: amapi.h:242
amrescan_function amrescan
Definition: amapi.h:272
bool amcanorder
Definition: amapi.h:220
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:281
uint8 amparallelvacuumoptions
Definition: amapi.h:248
bool amcanbackward
Definition: amapi.h:224
bool amcaninclude
Definition: amapi.h:244
bool amsearchnulls
Definition: amapi.h:234
#define VACUUM_OPTION_PARALLEL_BULKDEL
Definition: vacuum.h:47
#define VACUUM_OPTION_PARALLEL_COND_CLEANUP
Definition: vacuum.h:54

References IndexAmRoutine::amadjustmembers, IndexAmRoutine::ambeginscan, IndexAmRoutine::ambuild, IndexAmRoutine::ambuildempty, IndexAmRoutine::ambuildphasename, IndexAmRoutine::ambulkdelete, IndexAmRoutine::amcanbackward, IndexAmRoutine::amcaninclude, IndexAmRoutine::amcanmulticol, IndexAmRoutine::amcanorder, IndexAmRoutine::amcanorderbyop, IndexAmRoutine::amcanparallel, IndexAmRoutine::amcanreturn, IndexAmRoutine::amcanunique, IndexAmRoutine::amclusterable, IndexAmRoutine::amcostestimate, IndexAmRoutine::amendscan, IndexAmRoutine::amestimateparallelscan, IndexAmRoutine::amgetbitmap, IndexAmRoutine::amgettuple, IndexAmRoutine::aminitparallelscan, IndexAmRoutine::aminsert, IndexAmRoutine::amkeytype, IndexAmRoutine::ammarkpos, IndexAmRoutine::amoptionalkey, IndexAmRoutine::amoptions, IndexAmRoutine::amoptsprocnum, IndexAmRoutine::amparallelrescan, IndexAmRoutine::amparallelvacuumoptions, IndexAmRoutine::ampredlocks, IndexAmRoutine::amproperty, IndexAmRoutine::amrescan, IndexAmRoutine::amrestrpos, IndexAmRoutine::amsearcharray, IndexAmRoutine::amsearchnulls, IndexAmRoutine::amstorage, IndexAmRoutine::amstrategies, IndexAmRoutine::amsupport, IndexAmRoutine::amusemaintenanceworkmem, IndexAmRoutine::amvacuumcleanup, IndexAmRoutine::amvalidate, InvalidOid, makeNode, PG_RETURN_POINTER, spgadjustmembers(), spgbeginscan(), spgbuild(), spgbuildempty(), spgbulkdelete(), spgcanreturn(), spgcostestimate(), spgendscan(), spggetbitmap(), spggettuple(), spginsert(), SPGIST_OPTIONS_PROC, SPGISTNProc, spgoptions(), spgproperty(), spgrescan(), spgvacuumcleanup(), spgvalidate(), VACUUM_OPTION_PARALLEL_BULKDEL, and VACUUM_OPTION_PARALLEL_COND_CLEANUP.

◆ SpGistGetBuffer()

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

Definition at line 549 of file spgutils.c.

550 {
551  SpGistCache *cache = spgGetCache(index);
552  SpGistLastUsedPage *lup;
553 
554  /* Bail out if even an empty page wouldn't meet the demand */
555  if (needSpace > SPGIST_PAGE_CAPACITY)
556  elog(ERROR, "desired SPGiST tuple size is too big");
557 
558  /*
559  * If possible, increase the space request to include relation's
560  * fillfactor. This ensures that when we add unrelated tuples to a page,
561  * we try to keep 100-fillfactor% available for adding tuples that are
562  * related to the ones already on it. But fillfactor mustn't cause an
563  * error for requests that would otherwise be legal.
564  */
565  needSpace += SpGistGetTargetPageFreeSpace(index);
566  needSpace = Min(needSpace, SPGIST_PAGE_CAPACITY);
567 
568  /* Get the cache entry for this flags setting */
569  lup = GET_LUP(cache, flags);
570 
571  /* If we have nothing cached, just turn it over to allocNewBuffer */
572  if (lup->blkno == InvalidBlockNumber)
573  {
574  *isNew = true;
575  return allocNewBuffer(index, flags);
576  }
577 
578  /* fixed pages should never be in cache */
580 
581  /* If cached freeSpace isn't enough, don't bother looking at the page */
582  if (lup->freeSpace >= needSpace)
583  {
584  Buffer buffer;
585  Page page;
586 
587  buffer = ReadBuffer(index, lup->blkno);
588 
589  if (!ConditionalLockBuffer(buffer))
590  {
591  /*
592  * buffer is locked by another process, so return a new buffer
593  */
594  ReleaseBuffer(buffer);
595  *isNew = true;
596  return allocNewBuffer(index, flags);
597  }
598 
599  page = BufferGetPage(buffer);
600 
601  if (PageIsNew(page) || SpGistPageIsDeleted(page) || PageIsEmpty(page))
602  {
603  /* OK to initialize the page */
604  uint16 pageflags = 0;
605 
606  if (GBUF_REQ_LEAF(flags))
607  pageflags |= SPGIST_LEAF;
608  if (GBUF_REQ_NULLS(flags))
609  pageflags |= SPGIST_NULLS;
610  SpGistInitBuffer(buffer, pageflags);
611  lup->freeSpace = PageGetExactFreeSpace(page) - needSpace;
612  *isNew = true;
613  return buffer;
614  }
615 
616  /*
617  * Check that page is of right type and has enough space. We must
618  * recheck this since our cache isn't necessarily up to date.
619  */
620  if ((GBUF_REQ_LEAF(flags) ? SpGistPageIsLeaf(page) : !SpGistPageIsLeaf(page)) &&
622  {
623  int freeSpace = PageGetExactFreeSpace(page);
624 
625  if (freeSpace >= needSpace)
626  {
627  /* Success, update freespace info and return the buffer */
628  lup->freeSpace = freeSpace - needSpace;
629  *isNew = false;
630  return buffer;
631  }
632  }
633 
634  /*
635  * fallback to allocation of new buffer
636  */
637  UnlockReleaseBuffer(buffer);
638  }
639 
640  /* No success with cache, so return a new buffer */
641  *isNew = true;
642  return allocNewBuffer(index, flags);
643 }
#define InvalidBlockNumber
Definition: block.h:33
bool ConditionalLockBuffer(Buffer buffer)
Definition: bufmgr.c:4198
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3931
static bool PageIsEmpty(Page page)
Definition: bufpage.h:220
Pointer Page
Definition: bufpage.h:78
static bool PageIsNew(Page page)
Definition: bufpage.h:230
#define Min(x, y)
Definition: c.h:937
#define SpGistPageStoresNulls(page)
#define SpGistGetTargetPageFreeSpace(relation)
#define SpGistPageIsLeaf(page)
#define SpGistPageIsDeleted(page)
#define SpGistBlockIsFixed(blkno)
static Buffer allocNewBuffer(Relation index, int flags)
Definition: spgutils.c:493
#define GET_LUP(c, f)
Definition: spgutils.c:470

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().

◆ SpGistGetInnerTypeSize()

unsigned int SpGistGetInnerTypeSize ( SpGistTypeDesc att,
Datum  datum 
)

Definition at line 759 of file spgutils.c.

760 {
761  unsigned int size;
762 
763  if (att->attbyval)
764  size = sizeof(Datum);
765  else if (att->attlen > 0)
766  size = att->attlen;
767  else
768  size = VARSIZE_ANY(datum);
769 
770  return MAXALIGN(size);
771 }

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

Referenced by spgFormInnerTuple(), and spgFormNodeTuple().

◆ SpGistGetLeafTupleSize()

Size SpGistGetLeafTupleSize ( TupleDesc  tupleDescriptor,
Datum datums,
bool isnulls 
)

Definition at line 798 of file spgutils.c.

800 {
801  Size size;
802  Size data_size;
803  bool needs_null_mask = false;
804  int natts = tupleDescriptor->natts;
805 
806  /*
807  * Decide whether we need a nulls bitmask.
808  *
809  * If there is only a key attribute (natts == 1), never use a bitmask, for
810  * compatibility with the pre-v14 layout of leaf tuples. Otherwise, we
811  * need one if any attribute is null.
812  */
813  if (natts > 1)
814  {
815  for (int i = 0; i < natts; i++)
816  {
817  if (isnulls[i])
818  {
819  needs_null_mask = true;
820  break;
821  }
822  }
823  }
824 
825  /*
826  * Calculate size of the data part; same as for heap tuples.
827  */
828  data_size = heap_compute_data_size(tupleDescriptor, datums, isnulls);
829 
830  /*
831  * Compute total size.
832  */
833  size = SGLTHDRSZ(needs_null_mask);
834  size += data_size;
835  size = MAXALIGN(size);
836 
837  /*
838  * Ensure that we can replace the tuple with a dead tuple later. This test
839  * is unnecessary when there are any non-null attributes, but be safe.
840  */
841  if (size < SGDTSIZE)
842  size = SGDTSIZE;
843 
844  return size;
845 }

References heap_compute_data_size(), i, MAXALIGN, TupleDescData::natts, SGDTSIZE, and SGLTHDRSZ.

Referenced by spgdoinsert().

◆ SpGistInitBuffer()

void SpGistInitBuffer ( Buffer  b,
uint16  f 
)

Definition at line 702 of file spgutils.c.

703 {
704  Assert(BufferGetPageSize(b) == BLCKSZ);
706 }
static Size BufferGetPageSize(Buffer buffer)
Definition: bufmgr.h:266
int b
Definition: isn.c:70
void SpGistInitPage(Page page, uint16 f)
Definition: spgutils.c:688

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

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

◆ SpGistInitMetapage()

void SpGistInitMetapage ( Page  page)

Definition at line 712 of file spgutils.c.

713 {
714  SpGistMetaPageData *metadata;
715  int i;
716 
718  metadata = SpGistPageGetMeta(page);
719  memset(metadata, 0, sizeof(SpGistMetaPageData));
720  metadata->magicNumber = SPGIST_MAGIC_NUMBER;
721 
722  /* initialize last-used-page cache to empty */
723  for (i = 0; i < SPGIST_CACHED_PAGES; i++)
725 
726  /*
727  * Set pd_lower just past the end of the metadata. This is essential,
728  * because without doing so, metadata will be lost if xlog.c compresses
729  * the page.
730  */
731  ((PageHeader) page)->pd_lower =
732  ((char *) metadata + sizeof(SpGistMetaPageData)) - (char *) page;
733 }
#define SPGIST_META
#define SPGIST_CACHED_PAGES

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().

◆ SpGistInitPage()

void SpGistInitPage ( Page  page,
uint16  f 
)

Definition at line 688 of file spgutils.c.

689 {
690  SpGistPageOpaque opaque;
691 
692  PageInit(page, BLCKSZ, sizeof(SpGistPageOpaqueData));
693  opaque = SpGistPageGetOpaque(page);
694  opaque->flags = f;
695  opaque->spgist_page_id = SPGIST_PAGE_ID;
696 }
void PageInit(Page page, Size pageSize, Size specialSize)
Definition: bufpage.c:42
#define SpGistPageGetOpaque(page)
#define SPGIST_PAGE_ID

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

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

◆ SpGistNewBuffer()

Buffer SpGistNewBuffer ( Relation  index)

Definition at line 365 of file spgutils.c.

366 {
367  Buffer buffer;
368  bool needLock;
369 
370  /* First, try to get a page from FSM */
371  for (;;)
372  {
374 
375  if (blkno == InvalidBlockNumber)
376  break; /* nothing known to FSM */
377 
378  /*
379  * The fixed pages shouldn't ever be listed in FSM, but just in case
380  * one is, ignore it.
381  */
382  if (SpGistBlockIsFixed(blkno))
383  continue;
384 
385  buffer = ReadBuffer(index, blkno);
386 
387  /*
388  * We have to guard against the possibility that someone else already
389  * recycled this page; the buffer may be locked if so.
390  */
391  if (ConditionalLockBuffer(buffer))
392  {
393  Page page = BufferGetPage(buffer);
394 
395  if (PageIsNew(page))
396  return buffer; /* OK to use, if never initialized */
397 
398  if (SpGistPageIsDeleted(page) || PageIsEmpty(page))
399  return buffer; /* OK to use */
400 
402  }
403 
404  /* Can't use it, so release buffer and try again */
405  ReleaseBuffer(buffer);
406  }
407 
408  /* Must extend the file */
409  needLock = !RELATION_IS_LOCAL(index);
410  if (needLock)
412 
413  buffer = ReadBuffer(index, P_NEW);
415 
416  if (needLock)
418 
419  return buffer;
420 }
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:105
#define P_NEW
Definition: bufmgr.h:100
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:107
BlockNumber GetFreeIndexPage(Relation rel)
Definition: indexfsm.c:38
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:431
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:481
#define ExclusiveLock
Definition: lockdefs.h:42
#define RELATION_IS_LOCAL(relation)
Definition: rel.h:646

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().

◆ SpGistPageAddNewItem()

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

Definition at line 1184 of file spgutils.c.

1186 {
1187  SpGistPageOpaque opaque = SpGistPageGetOpaque(page);
1188  OffsetNumber i,
1189  maxoff,
1190  offnum;
1191 
1192  if (opaque->nPlaceholder > 0 &&
1193  PageGetExactFreeSpace(page) + SGDTSIZE >= MAXALIGN(size))
1194  {
1195  /* Try to replace a placeholder */
1196  maxoff = PageGetMaxOffsetNumber(page);
1197  offnum = InvalidOffsetNumber;
1198 
1199  for (;;)
1200  {
1201  if (startOffset && *startOffset != InvalidOffsetNumber)
1202  i = *startOffset;
1203  else
1204  i = FirstOffsetNumber;
1205  for (; i <= maxoff; i++)
1206  {
1208  PageGetItemId(page, i));
1209 
1210  if (it->tupstate == SPGIST_PLACEHOLDER)
1211  {
1212  offnum = i;
1213  break;
1214  }
1215  }
1216 
1217  /* Done if we found a placeholder */
1218  if (offnum != InvalidOffsetNumber)
1219  break;
1220 
1221  if (startOffset && *startOffset != InvalidOffsetNumber)
1222  {
1223  /* Hint was no good, re-search from beginning */
1224  *startOffset = InvalidOffsetNumber;
1225  continue;
1226  }
1227 
1228  /* Hmm, no placeholder found? */
1229  opaque->nPlaceholder = 0;
1230  break;
1231  }
1232 
1233  if (offnum != InvalidOffsetNumber)
1234  {
1235  /* Replace the placeholder tuple */
1236  PageIndexTupleDelete(page, offnum);
1237 
1238  offnum = PageAddItem(page, item, size, offnum, false, false);
1239 
1240  /*
1241  * We should not have failed given the size check at the top of
1242  * the function, but test anyway. If we did fail, we must PANIC
1243  * because we've already deleted the placeholder tuple, and
1244  * there's no other way to keep the damage from getting to disk.
1245  */
1246  if (offnum != InvalidOffsetNumber)
1247  {
1248  Assert(opaque->nPlaceholder > 0);
1249  opaque->nPlaceholder--;
1250  if (startOffset)
1251  *startOffset = offnum + 1;
1252  }
1253  else
1254  elog(PANIC, "failed to add item of size %zu to SPGiST index page",
1255  size);
1256 
1257  return offnum;
1258  }
1259  }
1260 
1261  /* No luck in replacing a placeholder, so just add it to the page */
1262  offnum = PageAddItem(page, item, size,
1263  InvalidOffsetNumber, false, false);
1264 
1265  if (offnum == InvalidOffsetNumber && !errorOK)
1266  elog(ERROR, "failed to add item of size %zu to SPGiST index page",
1267  size);
1268 
1269  return offnum;
1270 }
void PageIndexTupleDelete(Page page, OffsetNumber offnum)
Definition: bufpage.c:1052
static Item PageGetItem(Page page, ItemId itemId)
Definition: bufpage.h:351
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
Definition: bufpage.h:240
static OffsetNumber PageGetMaxOffsetNumber(Page page)
Definition: bufpage.h:369
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
Definition: bufpage.h:468
#define PANIC
Definition: elog.h:38
uint16 OffsetNumber
Definition: off.h:24
#define FirstOffsetNumber
Definition: off.h:27
#define SPGIST_PLACEHOLDER

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().

◆ SpGistSetLastUsedPage()

void SpGistSetLastUsedPage ( Relation  index,
Buffer  buffer 
)

Definition at line 653 of file spgutils.c.

654 {
655  SpGistCache *cache = spgGetCache(index);
656  SpGistLastUsedPage *lup;
657  int freeSpace;
658  Page page = BufferGetPage(buffer);
659  BlockNumber blkno = BufferGetBlockNumber(buffer);
660  int flags;
661 
662  /* Never enter fixed pages (root pages) in cache, though */
663  if (SpGistBlockIsFixed(blkno))
664  return;
665 
666  if (SpGistPageIsLeaf(page))
667  flags = GBUF_LEAF;
668  else
669  flags = GBUF_INNER_PARITY(blkno);
670  if (SpGistPageStoresNulls(page))
671  flags |= GBUF_NULLS;
672 
673  lup = GET_LUP(cache, flags);
674 
675  freeSpace = PageGetExactFreeSpace(page);
676  if (lup->blkno == InvalidBlockNumber || lup->blkno == blkno ||
677  lup->freeSpace < freeSpace)
678  {
679  lup->blkno = blkno;
680  lup->freeSpace = freeSpace;
681  }
682 }
#define GBUF_LEAF

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().

◆ SpGistUpdateMetaPage()

void SpGistUpdateMetaPage ( Relation  index)

Definition at line 430 of file spgutils.c.

431 {
432  SpGistCache *cache = (SpGistCache *) index->rd_amcache;
433 
434  if (cache != NULL)
435  {
436  Buffer metabuffer;
437 
438  metabuffer = ReadBuffer(index, SPGIST_METAPAGE_BLKNO);
439 
440  if (ConditionalLockBuffer(metabuffer))
441  {
442  Page metapage = BufferGetPage(metabuffer);
443  SpGistMetaPageData *metadata = SpGistPageGetMeta(metapage);
444 
445  metadata->lastUsedPages = cache->lastUsedPages;
446 
447  /*
448  * Set pd_lower just past the end of the metadata. This is
449  * essential, because without doing so, metadata will be lost if
450  * xlog.c compresses the page. (We must do this here because
451  * pre-v11 versions of PG did not set the metapage's pd_lower
452  * correctly, so a pg_upgraded index might contain the wrong
453  * value.)
454  */
455  ((PageHeader) metapage)->pd_lower =
456  ((char *) metadata + sizeof(SpGistMetaPageData)) - (char *) metapage;
457 
458  MarkBufferDirty(metabuffer);
459  UnlockReleaseBuffer(metabuffer);
460  }
461  else
462  {
463  ReleaseBuffer(metabuffer);
464  }
465  }
466 }
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1583
PageHeaderData * PageHeader
Definition: bufpage.h:170
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77

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

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

◆ spgoptions()

bytea* spgoptions ( Datum  reloptions,
bool  validate 
)

Definition at line 739 of file spgutils.c.

740 {
741  static const relopt_parse_elt tab[] = {
742  {"fillfactor", RELOPT_TYPE_INT, offsetof(SpGistOptions, fillfactor)},
743  };
744 
745  return (bytea *) build_reloptions(reloptions, validate,
747  sizeof(SpGistOptions),
748  tab, lengthof(tab));
749 }
#define lengthof(array)
Definition: c.h:724
int fillfactor
Definition: pgbench.c:196
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1910
@ RELOPT_KIND_SPGIST
Definition: reloptions.h:50
@ RELOPT_TYPE_INT
Definition: reloptions.h:32
Definition: c.h:623

References build_reloptions(), fillfactor, lengthof, RELOPT_KIND_SPGIST, and RELOPT_TYPE_INT.

Referenced by spghandler().

◆ spgproperty()

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

Definition at line 1279 of file spgutils.c.

1282 {
1283  Oid opclass,
1284  opfamily,
1285  opcintype;
1286  CatCList *catlist;
1287  int i;
1288 
1289  /* Only answer column-level inquiries */
1290  if (attno == 0)
1291  return false;
1292 
1293  switch (prop)
1294  {
1296  break;
1297  default:
1298  return false;
1299  }
1300 
1301  /*
1302  * Currently, SP-GiST distance-ordered scans require that there be a
1303  * distance operator in the opclass with the default types. So we assume
1304  * that if such a operator exists, then there's a reason for it.
1305  */
1306 
1307  /* First we need to know the column's opclass. */
1308  opclass = get_index_column_opclass(index_oid, attno);
1309  if (!OidIsValid(opclass))
1310  {
1311  *isnull = true;
1312  return true;
1313  }
1314 
1315  /* Now look up the opclass family and input datatype. */
1316  if (!get_opclass_opfamily_and_input_type(opclass, &opfamily, &opcintype))
1317  {
1318  *isnull = true;
1319  return true;
1320  }
1321 
1322  /* And now we can check whether the operator is provided. */
1324  ObjectIdGetDatum(opfamily));
1325 
1326  *res = false;
1327 
1328  for (i = 0; i < catlist->n_members; i++)
1329  {
1330  HeapTuple amoptup = &catlist->members[i]->tuple;
1331  Form_pg_amop amopform = (Form_pg_amop) GETSTRUCT(amoptup);
1332 
1333  if (amopform->amoppurpose == AMOP_ORDER &&
1334  (amopform->amoplefttype == opcintype ||
1335  amopform->amoprighttype == opcintype) &&
1336  opfamily_can_sort_type(amopform->amopsortfamily,
1337  get_op_rettype(amopform->amopopr)))
1338  {
1339  *res = true;
1340  break;
1341  }
1342  }
1343 
1344  ReleaseSysCacheList(catlist);
1345 
1346  *isnull = false;
1347 
1348  return true;
1349 }
@ AMPROP_DISTANCE_ORDERABLE
Definition: amapi.h:42
bool opfamily_can_sort_type(Oid opfamilyoid, Oid datatypeoid)
Definition: amvalidate.c:271
bool get_opclass_opfamily_and_input_type(Oid opclass, Oid *opfamily, Oid *opcintype)
Definition: lsyscache.c:1239
Oid get_op_rettype(Oid opno)
Definition: lsyscache.c:1315
Oid get_index_column_opclass(Oid index_oid, int attno)
Definition: lsyscache.c:3477
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
CatCTup * members[FLEXIBLE_ARRAY_MEMBER]
Definition: catcache.h:178
int n_members
Definition: catcache.h:176
HeapTupleData tuple
Definition: catcache.h:121
@ AMOPSTRATEGY
Definition: syscache.h:38
#define ReleaseSysCacheList(x)
Definition: syscache.h:222
#define SearchSysCacheList1(cacheId, key1)
Definition: syscache.h:215

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, res, SearchSysCacheList1, and catctup::tuple.

Referenced by spghandler().