PostgreSQL Source Code  git master
spgutils.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * spgutils.c
4  * various support functions for SP-GiST
5  *
6  *
7  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * IDENTIFICATION
11  * src/backend/access/spgist/spgutils.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 
16 #include "postgres.h"
17 
18 #include "access/amvalidate.h"
19 #include "access/htup_details.h"
20 #include "access/reloptions.h"
21 #include "access/spgist_private.h"
22 #include "access/transam.h"
23 #include "access/xact.h"
24 #include "catalog/pg_amop.h"
25 #include "commands/vacuum.h"
26 #include "storage/bufmgr.h"
27 #include "storage/indexfsm.h"
28 #include "storage/lmgr.h"
29 #include "utils/builtins.h"
30 #include "utils/catcache.h"
31 #include "utils/index_selfuncs.h"
32 #include "utils/lsyscache.h"
33 #include "utils/syscache.h"
34 
35 
36 /*
37  * SP-GiST handler function: return IndexAmRoutine with access method parameters
38  * and callbacks.
39  */
40 Datum
42 {
44 
45  amroutine->amstrategies = 0;
46  amroutine->amsupport = SPGISTNProc;
48  amroutine->amcanorder = false;
49  amroutine->amcanorderbyop = true;
50  amroutine->amcanbackward = false;
51  amroutine->amcanunique = false;
52  amroutine->amcanmulticol = false;
53  amroutine->amoptionalkey = true;
54  amroutine->amsearcharray = false;
55  amroutine->amsearchnulls = true;
56  amroutine->amstorage = false;
57  amroutine->amclusterable = false;
58  amroutine->ampredlocks = false;
59  amroutine->amcanparallel = false;
60  amroutine->amcaninclude = false;
61  amroutine->amusemaintenanceworkmem = false;
62  amroutine->amparallelvacuumoptions =
64  amroutine->amkeytype = InvalidOid;
65 
66  amroutine->ambuild = spgbuild;
67  amroutine->ambuildempty = spgbuildempty;
68  amroutine->aminsert = spginsert;
69  amroutine->ambulkdelete = spgbulkdelete;
70  amroutine->amvacuumcleanup = spgvacuumcleanup;
71  amroutine->amcanreturn = spgcanreturn;
72  amroutine->amcostestimate = spgcostestimate;
73  amroutine->amoptions = spgoptions;
74  amroutine->amproperty = spgproperty;
75  amroutine->ambuildphasename = NULL;
76  amroutine->amvalidate = spgvalidate;
77  amroutine->amadjustmembers = spgadjustmembers;
78  amroutine->ambeginscan = spgbeginscan;
79  amroutine->amrescan = spgrescan;
80  amroutine->amgettuple = spggettuple;
81  amroutine->amgetbitmap = spggetbitmap;
82  amroutine->amendscan = spgendscan;
83  amroutine->ammarkpos = NULL;
84  amroutine->amrestrpos = NULL;
85  amroutine->amestimateparallelscan = NULL;
86  amroutine->aminitparallelscan = NULL;
87  amroutine->amparallelrescan = NULL;
88 
89  PG_RETURN_POINTER(amroutine);
90 }
91 
92 /* Fill in a SpGistTypeDesc struct with info about the specified data type */
93 static void
95 {
96  desc->type = type;
97  get_typlenbyval(type, &desc->attlen, &desc->attbyval);
98 }
99 
100 /*
101  * Fetch local cache of AM-specific info about the index, initializing it
102  * if necessary
103  */
104 SpGistCache *
106 {
107  SpGistCache *cache;
108 
109  if (index->rd_amcache == NULL)
110  {
111  Oid atttype;
112  spgConfigIn in;
113  FmgrInfo *procinfo;
114  Buffer metabuffer;
115  SpGistMetaPageData *metadata;
116 
117  cache = MemoryContextAllocZero(index->rd_indexcxt,
118  sizeof(SpGistCache));
119 
120  /* SPGiST doesn't support multi-column indexes */
121  Assert(index->rd_att->natts == 1);
122 
123  /*
124  * Get the actual data type of the indexed column from the index
125  * tupdesc. We pass this to the opclass config function so that
126  * polymorphic opclasses are possible.
127  */
128  atttype = TupleDescAttr(index->rd_att, 0)->atttypid;
129 
130  /* Call the config function to get config info for the opclass */
131  in.attType = atttype;
132 
133  procinfo = index_getprocinfo(index, 1, SPGIST_CONFIG_PROC);
134  FunctionCall2Coll(procinfo,
135  index->rd_indcollation[0],
136  PointerGetDatum(&in),
137  PointerGetDatum(&cache->config));
138 
139  /* Get the information we need about each relevant datatype */
140  fillTypeDesc(&cache->attType, atttype);
141 
142  if (OidIsValid(cache->config.leafType) &&
143  cache->config.leafType != atttype)
144  {
146  ereport(ERROR,
147  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
148  errmsg("compress method must be defined when leaf type is different from input type")));
149 
150  fillTypeDesc(&cache->attLeafType, cache->config.leafType);
151  }
152  else
153  {
154  cache->attLeafType = cache->attType;
155  }
156 
157  fillTypeDesc(&cache->attPrefixType, cache->config.prefixType);
158  fillTypeDesc(&cache->attLabelType, cache->config.labelType);
159 
160  /* Last, get the lastUsedPages data from the metapage */
161  metabuffer = ReadBuffer(index, SPGIST_METAPAGE_BLKNO);
162  LockBuffer(metabuffer, BUFFER_LOCK_SHARE);
163 
164  metadata = SpGistPageGetMeta(BufferGetPage(metabuffer));
165 
166  if (metadata->magicNumber != SPGIST_MAGIC_NUMBER)
167  elog(ERROR, "index \"%s\" is not an SP-GiST index",
168  RelationGetRelationName(index));
169 
170  cache->lastUsedPages = metadata->lastUsedPages;
171 
172  UnlockReleaseBuffer(metabuffer);
173 
174  index->rd_amcache = (void *) cache;
175  }
176  else
177  {
178  /* assume it's up to date */
179  cache = (SpGistCache *) index->rd_amcache;
180  }
181 
182  return cache;
183 }
184 
185 /* Initialize SpGistState for working with the given index */
186 void
188 {
189  SpGistCache *cache;
190 
191  /* Get cached static information about index */
192  cache = spgGetCache(index);
193 
194  state->config = cache->config;
195  state->attType = cache->attType;
196  state->attLeafType = cache->attLeafType;
197  state->attPrefixType = cache->attPrefixType;
198  state->attLabelType = cache->attLabelType;
199 
200  /* Make workspace for constructing dead tuples */
202 
203  /* Set XID to use in redirection tuples */
204  state->myXid = GetTopTransactionIdIfAny();
205 
206  /* Assume we're not in an index build (spgbuild will override) */
207  state->isBuild = false;
208 }
209 
210 /*
211  * Allocate a new page (either by recycling, or by extending the index file).
212  *
213  * The returned buffer is already pinned and exclusive-locked.
214  * Caller is responsible for initializing the page by calling SpGistInitBuffer.
215  */
216 Buffer
218 {
219  Buffer buffer;
220  bool needLock;
221 
222  /* First, try to get a page from FSM */
223  for (;;)
224  {
225  BlockNumber blkno = GetFreeIndexPage(index);
226 
227  if (blkno == InvalidBlockNumber)
228  break; /* nothing known to FSM */
229 
230  /*
231  * The fixed pages shouldn't ever be listed in FSM, but just in case
232  * one is, ignore it.
233  */
234  if (SpGistBlockIsFixed(blkno))
235  continue;
236 
237  buffer = ReadBuffer(index, blkno);
238 
239  /*
240  * We have to guard against the possibility that someone else already
241  * recycled this page; the buffer may be locked if so.
242  */
243  if (ConditionalLockBuffer(buffer))
244  {
245  Page page = BufferGetPage(buffer);
246 
247  if (PageIsNew(page))
248  return buffer; /* OK to use, if never initialized */
249 
250  if (SpGistPageIsDeleted(page) || PageIsEmpty(page))
251  return buffer; /* OK to use */
252 
254  }
255 
256  /* Can't use it, so release buffer and try again */
257  ReleaseBuffer(buffer);
258  }
259 
260  /* Must extend the file */
261  needLock = !RELATION_IS_LOCAL(index);
262  if (needLock)
264 
265  buffer = ReadBuffer(index, P_NEW);
267 
268  if (needLock)
270 
271  return buffer;
272 }
273 
274 /*
275  * Update index metapage's lastUsedPages info from local cache, if possible
276  *
277  * Updating meta page isn't critical for index working, so
278  * 1 use ConditionalLockBuffer to improve concurrency
279  * 2 don't WAL-log metabuffer changes to decrease WAL traffic
280  */
281 void
283 {
284  SpGistCache *cache = (SpGistCache *) index->rd_amcache;
285 
286  if (cache != NULL)
287  {
288  Buffer metabuffer;
289 
290  metabuffer = ReadBuffer(index, SPGIST_METAPAGE_BLKNO);
291 
292  if (ConditionalLockBuffer(metabuffer))
293  {
294  Page metapage = BufferGetPage(metabuffer);
295  SpGistMetaPageData *metadata = SpGistPageGetMeta(metapage);
296 
297  metadata->lastUsedPages = cache->lastUsedPages;
298 
299  /*
300  * Set pd_lower just past the end of the metadata. This is
301  * essential, because without doing so, metadata will be lost if
302  * xlog.c compresses the page. (We must do this here because
303  * pre-v11 versions of PG did not set the metapage's pd_lower
304  * correctly, so a pg_upgraded index might contain the wrong
305  * value.)
306  */
307  ((PageHeader) metapage)->pd_lower =
308  ((char *) metadata + sizeof(SpGistMetaPageData)) - (char *) metapage;
309 
310  MarkBufferDirty(metabuffer);
311  UnlockReleaseBuffer(metabuffer);
312  }
313  else
314  {
315  ReleaseBuffer(metabuffer);
316  }
317  }
318 }
319 
320 /* Macro to select proper element of lastUsedPages cache depending on flags */
321 /* Masking flags with SPGIST_CACHED_PAGES is just for paranoia's sake */
322 #define GET_LUP(c, f) (&(c)->lastUsedPages.cachedPage[((unsigned int) (f)) % SPGIST_CACHED_PAGES])
323 
324 /*
325  * Allocate and initialize a new buffer of the type and parity specified by
326  * flags. The returned buffer is already pinned and exclusive-locked.
327  *
328  * When requesting an inner page, if we get one with the wrong parity,
329  * we just release the buffer and try again. We will get a different page
330  * because GetFreeIndexPage will have marked the page used in FSM. The page
331  * is entered in our local lastUsedPages cache, so there's some hope of
332  * making use of it later in this session, but otherwise we rely on VACUUM
333  * to eventually re-enter the page in FSM, making it available for recycling.
334  * Note that such a page does not get marked dirty here, so unless it's used
335  * fairly soon, the buffer will just get discarded and the page will remain
336  * as it was on disk.
337  *
338  * When we return a buffer to the caller, the page is *not* entered into
339  * the lastUsedPages cache; we expect the caller will do so after it's taken
340  * whatever space it will use. This is because after the caller has used up
341  * some space, the page might have less space than whatever was cached already
342  * so we'd rather not trash the old cache entry.
343  */
344 static Buffer
346 {
347  SpGistCache *cache = spgGetCache(index);
348  uint16 pageflags = 0;
349 
350  if (GBUF_REQ_LEAF(flags))
351  pageflags |= SPGIST_LEAF;
352  if (GBUF_REQ_NULLS(flags))
353  pageflags |= SPGIST_NULLS;
354 
355  for (;;)
356  {
357  Buffer buffer;
358 
359  buffer = SpGistNewBuffer(index);
360  SpGistInitBuffer(buffer, pageflags);
361 
362  if (pageflags & SPGIST_LEAF)
363  {
364  /* Leaf pages have no parity concerns, so just use it */
365  return buffer;
366  }
367  else
368  {
369  BlockNumber blkno = BufferGetBlockNumber(buffer);
370  int blkFlags = GBUF_INNER_PARITY(blkno);
371 
372  if ((flags & GBUF_PARITY_MASK) == blkFlags)
373  {
374  /* Page has right parity, use it */
375  return buffer;
376  }
377  else
378  {
379  /* Page has wrong parity, record it in cache and try again */
380  if (pageflags & SPGIST_NULLS)
381  blkFlags |= GBUF_NULLS;
382  cache->lastUsedPages.cachedPage[blkFlags].blkno = blkno;
383  cache->lastUsedPages.cachedPage[blkFlags].freeSpace =
385  UnlockReleaseBuffer(buffer);
386  }
387  }
388  }
389 }
390 
391 /*
392  * Get a buffer of the type and parity specified by flags, having at least
393  * as much free space as indicated by needSpace. We use the lastUsedPages
394  * cache to assign the same buffer previously requested when possible.
395  * The returned buffer is already pinned and exclusive-locked.
396  *
397  * *isNew is set true if the page was initialized here, false if it was
398  * already valid.
399  */
400 Buffer
401 SpGistGetBuffer(Relation index, int flags, int needSpace, bool *isNew)
402 {
403  SpGistCache *cache = spgGetCache(index);
404  SpGistLastUsedPage *lup;
405 
406  /* Bail out if even an empty page wouldn't meet the demand */
407  if (needSpace > SPGIST_PAGE_CAPACITY)
408  elog(ERROR, "desired SPGiST tuple size is too big");
409 
410  /*
411  * If possible, increase the space request to include relation's
412  * fillfactor. This ensures that when we add unrelated tuples to a page,
413  * we try to keep 100-fillfactor% available for adding tuples that are
414  * related to the ones already on it. But fillfactor mustn't cause an
415  * error for requests that would otherwise be legal.
416  */
417  needSpace += SpGistGetTargetPageFreeSpace(index);
418  needSpace = Min(needSpace, SPGIST_PAGE_CAPACITY);
419 
420  /* Get the cache entry for this flags setting */
421  lup = GET_LUP(cache, flags);
422 
423  /* If we have nothing cached, just turn it over to allocNewBuffer */
424  if (lup->blkno == InvalidBlockNumber)
425  {
426  *isNew = true;
427  return allocNewBuffer(index, flags);
428  }
429 
430  /* fixed pages should never be in cache */
432 
433  /* If cached freeSpace isn't enough, don't bother looking at the page */
434  if (lup->freeSpace >= needSpace)
435  {
436  Buffer buffer;
437  Page page;
438 
439  buffer = ReadBuffer(index, lup->blkno);
440 
441  if (!ConditionalLockBuffer(buffer))
442  {
443  /*
444  * buffer is locked by another process, so return a new buffer
445  */
446  ReleaseBuffer(buffer);
447  *isNew = true;
448  return allocNewBuffer(index, flags);
449  }
450 
451  page = BufferGetPage(buffer);
452 
453  if (PageIsNew(page) || SpGistPageIsDeleted(page) || PageIsEmpty(page))
454  {
455  /* OK to initialize the page */
456  uint16 pageflags = 0;
457 
458  if (GBUF_REQ_LEAF(flags))
459  pageflags |= SPGIST_LEAF;
460  if (GBUF_REQ_NULLS(flags))
461  pageflags |= SPGIST_NULLS;
462  SpGistInitBuffer(buffer, pageflags);
463  lup->freeSpace = PageGetExactFreeSpace(page) - needSpace;
464  *isNew = true;
465  return buffer;
466  }
467 
468  /*
469  * Check that page is of right type and has enough space. We must
470  * recheck this since our cache isn't necessarily up to date.
471  */
472  if ((GBUF_REQ_LEAF(flags) ? SpGistPageIsLeaf(page) : !SpGistPageIsLeaf(page)) &&
474  {
475  int freeSpace = PageGetExactFreeSpace(page);
476 
477  if (freeSpace >= needSpace)
478  {
479  /* Success, update freespace info and return the buffer */
480  lup->freeSpace = freeSpace - needSpace;
481  *isNew = false;
482  return buffer;
483  }
484  }
485 
486  /*
487  * fallback to allocation of new buffer
488  */
489  UnlockReleaseBuffer(buffer);
490  }
491 
492  /* No success with cache, so return a new buffer */
493  *isNew = true;
494  return allocNewBuffer(index, flags);
495 }
496 
497 /*
498  * Update lastUsedPages cache when done modifying a page.
499  *
500  * We update the appropriate cache entry if it already contained this page
501  * (its freeSpace is likely obsolete), or if this page has more space than
502  * whatever we had cached.
503  */
504 void
506 {
507  SpGistCache *cache = spgGetCache(index);
508  SpGistLastUsedPage *lup;
509  int freeSpace;
510  Page page = BufferGetPage(buffer);
511  BlockNumber blkno = BufferGetBlockNumber(buffer);
512  int flags;
513 
514  /* Never enter fixed pages (root pages) in cache, though */
515  if (SpGistBlockIsFixed(blkno))
516  return;
517 
518  if (SpGistPageIsLeaf(page))
519  flags = GBUF_LEAF;
520  else
521  flags = GBUF_INNER_PARITY(blkno);
522  if (SpGistPageStoresNulls(page))
523  flags |= GBUF_NULLS;
524 
525  lup = GET_LUP(cache, flags);
526 
527  freeSpace = PageGetExactFreeSpace(page);
528  if (lup->blkno == InvalidBlockNumber || lup->blkno == blkno ||
529  lup->freeSpace < freeSpace)
530  {
531  lup->blkno = blkno;
532  lup->freeSpace = freeSpace;
533  }
534 }
535 
536 /*
537  * Initialize an SPGiST page to empty, with specified flags
538  */
539 void
541 {
542  SpGistPageOpaque opaque;
543 
544  PageInit(page, BLCKSZ, MAXALIGN(sizeof(SpGistPageOpaqueData)));
545  opaque = SpGistPageGetOpaque(page);
546  memset(opaque, 0, sizeof(SpGistPageOpaqueData));
547  opaque->flags = f;
548  opaque->spgist_page_id = SPGIST_PAGE_ID;
549 }
550 
551 /*
552  * Initialize a buffer's page to empty, with specified flags
553  */
554 void
556 {
557  Assert(BufferGetPageSize(b) == BLCKSZ);
559 }
560 
561 /*
562  * Initialize metadata page
563  */
564 void
566 {
567  SpGistMetaPageData *metadata;
568  int i;
569 
571  metadata = SpGistPageGetMeta(page);
572  memset(metadata, 0, sizeof(SpGistMetaPageData));
573  metadata->magicNumber = SPGIST_MAGIC_NUMBER;
574 
575  /* initialize last-used-page cache to empty */
576  for (i = 0; i < SPGIST_CACHED_PAGES; i++)
578 
579  /*
580  * Set pd_lower just past the end of the metadata. This is essential,
581  * because without doing so, metadata will be lost if xlog.c compresses
582  * the page.
583  */
584  ((PageHeader) page)->pd_lower =
585  ((char *) metadata + sizeof(SpGistMetaPageData)) - (char *) page;
586 }
587 
588 /*
589  * reloptions processing for SPGiST
590  */
591 bytea *
592 spgoptions(Datum reloptions, bool validate)
593 {
594  static const relopt_parse_elt tab[] = {
596  };
597 
598  return (bytea *) build_reloptions(reloptions, validate,
600  sizeof(SpGistOptions),
601  tab, lengthof(tab));
602 
603 }
604 
605 /*
606  * Get the space needed to store a non-null datum of the indicated type.
607  * Note the result is already rounded up to a MAXALIGN boundary.
608  * Also, we follow the SPGiST convention that pass-by-val types are
609  * just stored in their Datum representation (compare memcpyDatum).
610  */
611 unsigned int
613 {
614  unsigned int size;
615 
616  if (att->attbyval)
617  size = sizeof(Datum);
618  else if (att->attlen > 0)
619  size = att->attlen;
620  else
621  size = VARSIZE_ANY(datum);
622 
623  return MAXALIGN(size);
624 }
625 
626 /*
627  * Copy the given non-null datum to *target
628  */
629 static void
630 memcpyDatum(void *target, SpGistTypeDesc *att, Datum datum)
631 {
632  unsigned int size;
633 
634  if (att->attbyval)
635  {
636  memcpy(target, &datum, sizeof(Datum));
637  }
638  else
639  {
640  size = (att->attlen > 0) ? att->attlen : VARSIZE_ANY(datum);
641  memcpy(target, DatumGetPointer(datum), size);
642  }
643 }
644 
645 /*
646  * Construct a leaf tuple containing the given heap TID and datum value
647  */
650  Datum datum, bool isnull)
651 {
652  SpGistLeafTuple tup;
653  unsigned int size;
654 
655  /* compute space needed (note result is already maxaligned) */
656  size = SGLTHDRSZ;
657  if (!isnull)
658  size += SpGistGetTypeSize(&state->attLeafType, datum);
659 
660  /*
661  * Ensure that we can replace the tuple with a dead tuple later. This
662  * test is unnecessary when !isnull, but let's be safe.
663  */
664  if (size < SGDTSIZE)
665  size = SGDTSIZE;
666 
667  /* OK, form the tuple */
668  tup = (SpGistLeafTuple) palloc0(size);
669 
670  tup->size = size;
672  tup->heapPtr = *heapPtr;
673  if (!isnull)
674  memcpyDatum(SGLTDATAPTR(tup), &state->attLeafType, datum);
675 
676  return tup;
677 }
678 
679 /*
680  * Construct a node (to go into an inner tuple) containing the given label
681  *
682  * Note that the node's downlink is just set invalid here. Caller will fill
683  * it in later.
684  */
687 {
688  SpGistNodeTuple tup;
689  unsigned int size;
690  unsigned short infomask = 0;
691 
692  /* compute space needed (note result is already maxaligned) */
693  size = SGNTHDRSZ;
694  if (!isnull)
695  size += SpGistGetTypeSize(&state->attLabelType, label);
696 
697  /*
698  * Here we make sure that the size will fit in the field reserved for it
699  * in t_info.
700  */
701  if ((size & INDEX_SIZE_MASK) != size)
702  ereport(ERROR,
703  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
704  errmsg("index row requires %zu bytes, maximum size is %zu",
705  (Size) size, (Size) INDEX_SIZE_MASK)));
706 
707  tup = (SpGistNodeTuple) palloc0(size);
708 
709  if (isnull)
710  infomask |= INDEX_NULL_MASK;
711  /* we don't bother setting the INDEX_VAR_MASK bit */
712  infomask |= size;
713  tup->t_info = infomask;
714 
715  /* The TID field will be filled in later */
717 
718  if (!isnull)
719  memcpyDatum(SGNTDATAPTR(tup), &state->attLabelType, label);
720 
721  return tup;
722 }
723 
724 /*
725  * Construct an inner tuple containing the given prefix and node array
726  */
728 spgFormInnerTuple(SpGistState *state, bool hasPrefix, Datum prefix,
729  int nNodes, SpGistNodeTuple *nodes)
730 {
731  SpGistInnerTuple tup;
732  unsigned int size;
733  unsigned int prefixSize;
734  int i;
735  char *ptr;
736 
737  /* Compute size needed */
738  if (hasPrefix)
739  prefixSize = SpGistGetTypeSize(&state->attPrefixType, prefix);
740  else
741  prefixSize = 0;
742 
743  size = SGITHDRSZ + prefixSize;
744 
745  /* Note: we rely on node tuple sizes to be maxaligned already */
746  for (i = 0; i < nNodes; i++)
747  size += IndexTupleSize(nodes[i]);
748 
749  /*
750  * Ensure that we can replace the tuple with a dead tuple later. This
751  * test is unnecessary given current tuple layouts, but let's be safe.
752  */
753  if (size < SGDTSIZE)
754  size = SGDTSIZE;
755 
756  /*
757  * Inner tuple should be small enough to fit on a page
758  */
759  if (size > SPGIST_PAGE_CAPACITY - sizeof(ItemIdData))
760  ereport(ERROR,
761  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
762  errmsg("SP-GiST inner tuple size %zu exceeds maximum %zu",
763  (Size) size,
764  SPGIST_PAGE_CAPACITY - sizeof(ItemIdData)),
765  errhint("Values larger than a buffer page cannot be indexed.")));
766 
767  /*
768  * Check for overflow of header fields --- probably can't fail if the
769  * above succeeded, but let's be paranoid
770  */
771  if (size > SGITMAXSIZE ||
772  prefixSize > SGITMAXPREFIXSIZE ||
773  nNodes > SGITMAXNNODES)
774  elog(ERROR, "SPGiST inner tuple header field is too small");
775 
776  /* OK, form the tuple */
777  tup = (SpGistInnerTuple) palloc0(size);
778 
779  tup->nNodes = nNodes;
780  tup->prefixSize = prefixSize;
781  tup->size = size;
782 
783  if (hasPrefix)
784  memcpyDatum(SGITDATAPTR(tup), &state->attPrefixType, prefix);
785 
786  ptr = (char *) SGITNODEPTR(tup);
787 
788  for (i = 0; i < nNodes; i++)
789  {
790  SpGistNodeTuple node = nodes[i];
791 
792  memcpy(ptr, node, IndexTupleSize(node));
793  ptr += IndexTupleSize(node);
794  }
795 
796  return tup;
797 }
798 
799 /*
800  * Construct a "dead" tuple to replace a tuple being deleted.
801  *
802  * The state can be SPGIST_REDIRECT, SPGIST_DEAD, or SPGIST_PLACEHOLDER.
803  * For a REDIRECT tuple, a pointer (blkno+offset) must be supplied, and
804  * the xid field is filled in automatically.
805  *
806  * This is called in critical sections, so we don't use palloc; the tuple
807  * is built in preallocated storage. It should be copied before another
808  * call with different parameters can occur.
809  */
812  BlockNumber blkno, OffsetNumber offnum)
813 {
815 
816  tuple->tupstate = tupstate;
817  tuple->size = SGDTSIZE;
819 
820  if (tupstate == SPGIST_REDIRECT)
821  {
822  ItemPointerSet(&tuple->pointer, blkno, offnum);
824  tuple->xid = state->myXid;
825  }
826  else
827  {
829  tuple->xid = InvalidTransactionId;
830  }
831 
832  return tuple;
833 }
834 
835 /*
836  * Extract the label datums of the nodes within innerTuple
837  *
838  * Returns NULL if label datums are NULLs
839  */
840 Datum *
842 {
843  Datum *nodeLabels;
844  int i;
845  SpGistNodeTuple node;
846 
847  /* Either all the labels must be NULL, or none. */
848  node = SGITNODEPTR(innerTuple);
849  if (IndexTupleHasNulls(node))
850  {
851  SGITITERATE(innerTuple, i, node)
852  {
853  if (!IndexTupleHasNulls(node))
854  elog(ERROR, "some but not all node labels are null in SPGiST inner tuple");
855  }
856  /* They're all null, so just return NULL */
857  return NULL;
858  }
859  else
860  {
861  nodeLabels = (Datum *) palloc(sizeof(Datum) * innerTuple->nNodes);
862  SGITITERATE(innerTuple, i, node)
863  {
864  if (IndexTupleHasNulls(node))
865  elog(ERROR, "some but not all node labels are null in SPGiST inner tuple");
866  nodeLabels[i] = SGNTDATUM(node, state);
867  }
868  return nodeLabels;
869  }
870 }
871 
872 /*
873  * Add a new item to the page, replacing a PLACEHOLDER item if possible.
874  * Return the location it's inserted at, or InvalidOffsetNumber on failure.
875  *
876  * If startOffset isn't NULL, we start searching for placeholders at
877  * *startOffset, and update that to the next place to search. This is just
878  * an optimization for repeated insertions.
879  *
880  * If errorOK is false, we throw error when there's not enough room,
881  * rather than returning InvalidOffsetNumber.
882  */
885  OffsetNumber *startOffset, bool errorOK)
886 {
887  SpGistPageOpaque opaque = SpGistPageGetOpaque(page);
888  OffsetNumber i,
889  maxoff,
890  offnum;
891 
892  if (opaque->nPlaceholder > 0 &&
893  PageGetExactFreeSpace(page) + SGDTSIZE >= MAXALIGN(size))
894  {
895  /* Try to replace a placeholder */
896  maxoff = PageGetMaxOffsetNumber(page);
897  offnum = InvalidOffsetNumber;
898 
899  for (;;)
900  {
901  if (startOffset && *startOffset != InvalidOffsetNumber)
902  i = *startOffset;
903  else
904  i = FirstOffsetNumber;
905  for (; i <= maxoff; i++)
906  {
908  PageGetItemId(page, i));
909 
910  if (it->tupstate == SPGIST_PLACEHOLDER)
911  {
912  offnum = i;
913  break;
914  }
915  }
916 
917  /* Done if we found a placeholder */
918  if (offnum != InvalidOffsetNumber)
919  break;
920 
921  if (startOffset && *startOffset != InvalidOffsetNumber)
922  {
923  /* Hint was no good, re-search from beginning */
924  *startOffset = InvalidOffsetNumber;
925  continue;
926  }
927 
928  /* Hmm, no placeholder found? */
929  opaque->nPlaceholder = 0;
930  break;
931  }
932 
933  if (offnum != InvalidOffsetNumber)
934  {
935  /* Replace the placeholder tuple */
936  PageIndexTupleDelete(page, offnum);
937 
938  offnum = PageAddItem(page, item, size, offnum, false, false);
939 
940  /*
941  * We should not have failed given the size check at the top of
942  * the function, but test anyway. If we did fail, we must PANIC
943  * because we've already deleted the placeholder tuple, and
944  * there's no other way to keep the damage from getting to disk.
945  */
946  if (offnum != InvalidOffsetNumber)
947  {
948  Assert(opaque->nPlaceholder > 0);
949  opaque->nPlaceholder--;
950  if (startOffset)
951  *startOffset = offnum + 1;
952  }
953  else
954  elog(PANIC, "failed to add item of size %u to SPGiST index page",
955  (int) size);
956 
957  return offnum;
958  }
959  }
960 
961  /* No luck in replacing a placeholder, so just add it to the page */
962  offnum = PageAddItem(page, item, size,
963  InvalidOffsetNumber, false, false);
964 
965  if (offnum == InvalidOffsetNumber && !errorOK)
966  elog(ERROR, "failed to add item of size %u to SPGiST index page",
967  (int) size);
968 
969  return offnum;
970 }
971 
972 /*
973  * spgproperty() -- Check boolean properties of indexes.
974  *
975  * This is optional for most AMs, but is required for SP-GiST because the core
976  * property code doesn't support AMPROP_DISTANCE_ORDERABLE.
977  */
978 bool
979 spgproperty(Oid index_oid, int attno,
980  IndexAMProperty prop, const char *propname,
981  bool *res, bool *isnull)
982 {
983  Oid opclass,
984  opfamily,
985  opcintype;
986  CatCList *catlist;
987  int i;
988 
989  /* Only answer column-level inquiries */
990  if (attno == 0)
991  return false;
992 
993  switch (prop)
994  {
996  break;
997  default:
998  return false;
999  }
1000 
1001  /*
1002  * Currently, SP-GiST distance-ordered scans require that there be a
1003  * distance operator in the opclass with the default types. So we assume
1004  * that if such a operator exists, then there's a reason for it.
1005  */
1006 
1007  /* First we need to know the column's opclass. */
1008  opclass = get_index_column_opclass(index_oid, attno);
1009  if (!OidIsValid(opclass))
1010  {
1011  *isnull = true;
1012  return true;
1013  }
1014 
1015  /* Now look up the opclass family and input datatype. */
1016  if (!get_opclass_opfamily_and_input_type(opclass, &opfamily, &opcintype))
1017  {
1018  *isnull = true;
1019  return true;
1020  }
1021 
1022  /* And now we can check whether the operator is provided. */
1024  ObjectIdGetDatum(opfamily));
1025 
1026  *res = false;
1027 
1028  for (i = 0; i < catlist->n_members; i++)
1029  {
1030  HeapTuple amoptup = &catlist->members[i]->tuple;
1031  Form_pg_amop amopform = (Form_pg_amop) GETSTRUCT(amoptup);
1032 
1033  if (amopform->amoppurpose == AMOP_ORDER &&
1034  (amopform->amoplefttype == opcintype ||
1035  amopform->amoprighttype == opcintype) &&
1036  opfamily_can_sort_type(amopform->amopsortfamily,
1037  get_op_rettype(amopform->amopopr)))
1038  {
1039  *res = true;
1040  break;
1041  }
1042  }
1043 
1044  ReleaseSysCacheList(catlist);
1045 
1046  *isnull = false;
1047 
1048  return true;
1049 }
ambeginscan_function ambeginscan
Definition: amapi.h:270
void SpGistUpdateMetaPage(Relation index)
Definition: spgutils.c:282
uint8 amparallelvacuumoptions
Definition: amapi.h:247
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
SpGistTypeDesc attLeafType
#define SGITNODEPTR(x)
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:96
Definition: fmgr.h:56
SpGistTypeDesc attPrefixType
ambulkdelete_function ambulkdelete
Definition: amapi.h:261
Datum * spgExtractNodeLabels(SpGistState *state, SpGistInnerTuple innerTuple)
Definition: spgutils.c:841
bool amcanmulticol
Definition: amapi.h:227
int n_members
Definition: catcache.h:176
uint16 amsupport
Definition: amapi.h:215
SpGistInnerTupleData * SpGistInnerTuple
#define PageIsEmpty(page)
Definition: bufpage.h:222
#define SpGistPageIsLeaf(page)
SpGistDeadTuple spgFormDeadTuple(SpGistState *state, int tupstate, BlockNumber blkno, OffsetNumber offnum)
Definition: spgutils.c:811
int errhint(const char *fmt,...)
Definition: elog.c:1071
#define SPGIST_OPTIONS_PROC
Definition: spgist.h:29
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
IndexAMProperty
Definition: amapi.h:34
SpGistCache * spgGetCache(Relation index)
Definition: spgutils.c:105
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:800
#define SGITMAXPREFIXSIZE
#define SGDTSIZE
bool opfamily_can_sort_type(Oid opfamilyoid, Oid datatypeoid)
Definition: amvalidate.c:271
amgettuple_function amgettuple
Definition: amapi.h:272
#define SPGIST_REDIRECT
bool amcanorderbyop
Definition: amapi.h:221
amproperty_function amproperty
Definition: amapi.h:266
#define GET_LUP(c, f)
Definition: spgutils.c:322
void PageIndexTupleDelete(Page page, OffsetNumber offnum)
Definition: bufpage.c:719
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1469
#define ExclusiveLock
Definition: lockdefs.h:44
#define PointerGetDatum(X)
Definition: postgres.h:556
bool spgproperty(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
Definition: spgutils.c:979
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
IndexBulkDeleteResult * spgvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: spgvacuum.c:932
#define SGITITERATE(x, i, nt)
#define RELATION_IS_LOCAL(relation)
Definition: rel.h:583
SpGistTypeDesc attLeafType
ItemPointerData t_tid
Definition: itup.h:37
#define SPGIST_PLACEHOLDER
amparallelrescan_function amparallelrescan
Definition: amapi.h:281
#define Min(x, y)
Definition: c.h:927
SpGistTypeDesc attType
#define SPGIST_NULLS
bool amstorage
Definition: amapi.h:235
void SpGistSetLastUsedPage(Relation index, Buffer buffer)
Definition: spgutils.c:505
Pointer Item
Definition: item.h:17
#define SGLTDATAPTR(x)
#define INDEX_SIZE_MASK
Definition: itup.h:65
int errcode(int sqlerrcode)
Definition: elog.c:610
void spgrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
Definition: spgscan.c:365
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
Definition: bufpage.h:416
static Buffer allocNewBuffer(Relation index, int flags)
Definition: spgutils.c:345
bool ampredlocks
Definition: amapi.h:239
uint32 BlockNumber
Definition: block.h:31
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3518
SpGistTypeDesc attLabelType
#define IndexTupleHasNulls(itup)
Definition: itup.h:72
#define P_NEW
Definition: bufmgr.h:91
aminsert_function aminsert
Definition: amapi.h:260
Oid attType
Definition: spgist.h:38
bool spginsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, IndexInfo *indexInfo)
Definition: spginsert.c:207
#define lengthof(array)
Definition: c.h:675
#define SGNTHDRSZ
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:98
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1152
unsigned int Oid
Definition: postgres_ext.h:31
SpGistTypeDesc attType
Oid amkeytype
Definition: amapi.h:249
void spgendscan(IndexScanDesc scan)
Definition: spgscan.c:411
#define OidIsValid(objectId)
Definition: c.h:651
#define PANIC
Definition: elog.h:53
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
Oid get_op_rettype(Oid opno)
Definition: lsyscache.c:1250
bool amoptionalkey
Definition: amapi.h:229
amvalidate_function amvalidate
Definition: amapi.h:268
SpGistLUPCache lastUsedPages
bool spgcanreturn(Relation index, int attno)
Definition: spgscan.c:1018
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:1887
uint16 OffsetNumber
Definition: off.h:24
Definition: type.h:89
CatCTup * members[FLEXIBLE_ARRAY_MEMBER]
Definition: catcache.h:178
spgConfigOut config
bool get_opclass_opfamily_and_input_type(Oid opclass, Oid *opfamily, Oid *opcintype)
Definition: lsyscache.c:1174
SpGistLastUsedPage cachedPage[SPGIST_CACHED_PAGES]
#define GBUF_REQ_NULLS(flags)
unsigned short uint16
Definition: c.h:373
amgetbitmap_function amgetbitmap
Definition: amapi.h:273
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3541
Oid * rd_indcollation
Definition: rel.h:199
ItemPointerData pointer
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
IndexBulkDeleteResult * spgbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition: spgvacuum.c:901
ambuild_function ambuild
Definition: amapi.h:258
amoptions_function amoptions
Definition: amapi.h:265
int fillfactor
Definition: pgbench.c:159
bool amcaninclude
Definition: amapi.h:243
#define SPGIST_PAGE_ID
#define GBUF_INNER_PARITY(x)
unsigned int prefixSize
amcostestimate_function amcostestimate
Definition: amapi.h:264
bool amcanunique
Definition: amapi.h:225
#define SGITMAXSIZE
#define SGITDATAPTR(x)
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:262
amendscan_function amendscan
Definition: amapi.h:274
bool amcanbackward
Definition: amapi.h:223
void spgadjustmembers(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
Definition: spgvalidate.c:311
#define FirstOffsetNumber
Definition: off.h:27
SpGistInnerTuple spgFormInnerTuple(SpGistState *state, bool hasPrefix, Datum prefix, int nNodes, SpGistNodeTuple *nodes)
Definition: spgutils.c:728
#define SPGIST_METAPAGE_BLKNO
void initSpGistState(SpGistState *state, Relation index)
Definition: spgutils.c:187
SpGistDeadTupleData * SpGistDeadTuple
#define InvalidTransactionId
Definition: transam.h:31
#define RelationGetRelationName(relation)
Definition: rel.h:490
int64 spggetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
Definition: spgscan.c:888
#define SearchSysCacheList1(cacheId, key1)
Definition: syscache.h:210
#define SpGistBlockIsFixed(blkno)
TransactionId myXid
void spgbuildempty(Relation index)
Definition: spginsert.c:156
#define INDEX_NULL_MASK
Definition: itup.h:69
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:425
void SpGistInitBuffer(Buffer b, uint16 f)
Definition: spgutils.c:555
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define SGITMAXNNODES
amrescan_function amrescan
Definition: amapi.h:271
bool amcanparallel
Definition: amapi.h:241
bool ConditionalLockBuffer(Buffer buffer)
Definition: bufmgr.c:3783
#define SPGIST_META
#define SGLTHDRSZ
#define GBUF_LEAF
bytea * spgoptions(Datum reloptions, bool validate)
Definition: spgutils.c:592
unsigned int SpGistGetTypeSize(SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:612
#define SPGIST_MAGIC_NUMBER
spgConfigOut config
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
SpGistLeafTuple spgFormLeafTuple(SpGistState *state, ItemPointer heapPtr, Datum datum, bool isnull)
Definition: spgutils.c:649
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:402
bool amsearchnulls
Definition: amapi.h:233
#define ReleaseSysCacheList(x)
Definition: syscache.h:217
SpGistLUPCache lastUsedPages
void * palloc0(Size size)
Definition: mcxt.c:980
unsigned int tupstate
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:452
uintptr_t Datum
Definition: postgres.h:367
#define BufferGetPageSize(buffer)
Definition: bufmgr.h:156
static char * label
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3757
#define SPGIST_PAGE_CAPACITY
char * deadTupleStorage
bool amclusterable
Definition: amapi.h:237
Oid prefixType
Definition: spgist.h:43
TupleDesc rd_att
Definition: rel.h:110
#define VARSIZE_ANY(PTR)
Definition: postgres.h:335
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:839
Buffer SpGistNewBuffer(Relation index)
Definition: spgutils.c:217
OffsetNumber nextOffset
bool amsearcharray
Definition: amapi.h:231
#define InvalidOffsetNumber
Definition: off.h:26
#define InvalidOid
Definition: postgres_ext.h:36
#define GBUF_PARITY_MASK
#define ereport(elevel,...)
Definition: elog.h:144
bool amusemaintenanceworkmem
Definition: amapi.h:245
BlockNumber GetFreeIndexPage(Relation rel)
Definition: indexfsm.c:38
#define SpGistPageStoresNulls(page)
void spgcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Definition: selfuncs.c:6644
#define makeNode(_type_)
Definition: nodes.h:577
PageHeaderData * PageHeader
Definition: bufpage.h:166
amadjustmembers_function amadjustmembers
Definition: amapi.h:269
#define Assert(condition)
Definition: c.h:745
#define VACUUM_OPTION_PARALLEL_COND_CLEANUP
Definition: vacuum.h:52
Definition: regguts.h:298
#define SpGistPageIsDeleted(page)
#define SGNTDATAPTR(x)
Buffer SpGistGetBuffer(Relation index, int flags, int needSpace, bool *isNew)
Definition: spgutils.c:401
#define SPGIST_COMPRESS_PROC
Definition: spgist.h:28
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:607
#define SPGIST_CONFIG_PROC
Definition: spgist.h:23
size_t Size
Definition: c.h:473
void SpGistInitMetapage(Page page)
Definition: spgutils.c:565
#define InvalidBlockNumber
Definition: block.h:33
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2139
#define MAXALIGN(LEN)
Definition: c.h:698
#define GBUF_NULLS
OffsetNumber nextOffset
ammarkpos_function ammarkpos
Definition: amapi.h:275
bool amcanorder
Definition: amapi.h:219
ambuildphasename_function ambuildphasename
Definition: amapi.h:267
#define VACUUM_OPTION_PARALLEL_BULKDEL
Definition: vacuum.h:45
#define SPGIST_CACHED_PAGES
#define SpGistPageGetMeta(p)
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:279
SpGistTypeDesc attLabelType
IndexBuildResult * spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
Definition: spginsert.c:75
#define DatumGetPointer(X)
Definition: postgres.h:549
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:625
#define SpGistPageGetOpaque(page)
uint16 amstrategies
Definition: amapi.h:213
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2668
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
Oid get_index_column_opclass(Oid index_oid, int attno)
Definition: lsyscache.c:3287
static void memcpyDatum(void *target, SpGistTypeDesc *att, Datum datum)
Definition: spgutils.c:630
#define PageIsNew(page)
Definition: bufpage.h:229
void SpGistInitPage(Page page, uint16 f)
Definition: spgutils.c:540
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define SPGISTNProc
Definition: spgist.h:31
bool spgvalidate(Oid opclassoid)
Definition: spgvalidate.c:39
uint16 amoptsprocnum
Definition: amapi.h:217
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
bool spggettuple(IndexScanDesc scan, ScanDirection dir)
Definition: spgscan.c:960
#define elog(elevel,...)
Definition: elog.h:214
ambuildempty_function ambuildempty
Definition: amapi.h:259
MemoryContext rd_indexcxt
Definition: rel.h:186
Oid labelType
Definition: spgist.h:44
int i
Oid leafType
Definition: spgist.h:45
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:97
#define SpGistGetTargetPageFreeSpace(relation)
SpGistTypeDesc attPrefixType
Definition: c.h:562
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define SGNTDATUM(x, s)
IndexScanDesc spgbeginscan(Relation rel, int keysz, int orderbysz)
Definition: spgscan.c:295
HeapTupleData tuple
Definition: catcache.h:121
static void fillTypeDesc(SpGistTypeDesc *desc, Oid type)
Definition: spgutils.c:94
ItemPointerData heapPtr
unsigned short t_info
Definition: itup.h:49
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void * rd_amcache
Definition: rel.h:211
SpGistLeafTupleData * SpGistLeafTuple
#define SPGIST_LEAF
int Buffer
Definition: buf.h:23
amcanreturn_function amcanreturn
Definition: amapi.h:263
OffsetNumber SpGistPageAddNewItem(SpGistState *state, Page page, Item item, Size size, OffsetNumber *startOffset, bool errorOK)
Definition: spgutils.c:884
SpGistNodeTuple spgFormNodeTuple(SpGistState *state, Datum label, bool isnull)
Definition: spgutils.c:686
#define offsetof(type, field)
Definition: c.h:668
#define SGITHDRSZ
#define PageGetItem(page, itemId)
Definition: bufpage.h:340
Pointer Page
Definition: bufpage.h:78
#define IndexTupleSize(itup)
Definition: itup.h:71
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:280
Datum spghandler(PG_FUNCTION_ARGS)
Definition: spgutils.c:41
amrestrpos_function amrestrpos
Definition: amapi.h:276
SpGistNodeTupleData * SpGistNodeTuple
void PageInit(Page page, Size pageSize, Size specialSize)
Definition: bufpage.c:42
#define GBUF_REQ_LEAF(flags)
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:766