PostgreSQL Source Code  git master
gist.c File Reference
#include "postgres.h"
#include "access/gist_private.h"
#include "access/gistscan.h"
#include "catalog/pg_collation.h"
#include "miscadmin.h"
#include "storage/lmgr.h"
#include "storage/predicate.h"
#include "nodes/execnodes.h"
#include "utils/builtins.h"
#include "utils/index_selfuncs.h"
#include "utils/memutils.h"
#include "utils/rel.h"
Include dependency graph for gist.c:

Go to the source code of this file.

Macros

#define ROTATEDIST(d)
 

Functions

static void gistfixsplit (GISTInsertState *state, GISTSTATE *giststate)
 
static bool gistinserttuple (GISTInsertState *state, GISTInsertStack *stack, GISTSTATE *giststate, IndexTuple tuple, OffsetNumber oldoffnum)
 
static bool gistinserttuples (GISTInsertState *state, GISTInsertStack *stack, GISTSTATE *giststate, IndexTuple *tuples, int ntup, OffsetNumber oldoffnum, Buffer leftchild, Buffer rightchild, bool unlockbuf, bool unlockleftchild)
 
static void gistfinishsplit (GISTInsertState *state, GISTInsertStack *stack, GISTSTATE *giststate, List *splitinfo, bool releasebuf)
 
static void gistvacuumpage (Relation rel, Page page, Buffer buffer)
 
Datum gisthandler (PG_FUNCTION_ARGS)
 
MemoryContext createTempGistContext (void)
 
void gistbuildempty (Relation index)
 
bool gistinsert (Relation r, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, IndexInfo *indexInfo)
 
bool gistplacetopage (Relation rel, Size freespace, GISTSTATE *giststate, Buffer buffer, IndexTuple *itup, int ntup, OffsetNumber oldoffnum, BlockNumber *newblkno, Buffer leftchildbuf, List **splitinfo, bool markfollowright)
 
void gistdoinsert (Relation r, IndexTuple itup, Size freespace, GISTSTATE *giststate)
 
static GISTInsertStackgistFindPath (Relation r, BlockNumber child, OffsetNumber *downlinkoffnum)
 
static void gistFindCorrectParent (Relation r, GISTInsertStack *child)
 
static IndexTuple gistformdownlink (Relation rel, Buffer buf, GISTSTATE *giststate, GISTInsertStack *stack)
 
SplitedPageLayoutgistSplit (Relation r, Page page, IndexTuple *itup, int len, GISTSTATE *giststate)
 
GISTSTATEinitGISTstate (Relation index)
 
void freeGISTstate (GISTSTATE *giststate)
 

Macro Definition Documentation

◆ ROTATEDIST

#define ROTATEDIST (   d)
Value:
do { \
SplitedPageLayout *tmp=(SplitedPageLayout*)palloc(sizeof(SplitedPageLayout)); \
memset(tmp,0,sizeof(SplitedPageLayout)); \
tmp->block.blkno = InvalidBlockNumber; \
tmp->buffer = InvalidBuffer; \
tmp->next = (d); \
(d)=tmp; \
} while(0)
#define InvalidBuffer
Definition: buf.h:25
#define InvalidBlockNumber
Definition: block.h:33
void * palloc(Size size)
Definition: mcxt.c:924

Definition at line 44 of file gist.c.

Referenced by gistSplit().

Function Documentation

◆ createTempGistContext()

MemoryContext createTempGistContext ( void  )

Definition at line 113 of file gist.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, and CurrentMemoryContext.

Referenced by gist_xlog_startup(), gistbeginscan(), gistbuild(), and gistinsert().

114 {
116  "GiST temporary context",
118 }
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:170

◆ freeGISTstate()

void freeGISTstate ( GISTSTATE giststate)

Definition at line 1535 of file gist.c.

References MemoryContextDelete(), and GISTSTATE::scanCxt.

Referenced by gistbuild(), and gistendscan().

1536 {
1537  /* It's sufficient to delete the scanCxt */
1538  MemoryContextDelete(giststate->scanCxt);
1539 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
MemoryContext scanCxt
Definition: gist_private.h:78

◆ gistbuildempty()

void gistbuildempty ( Relation  index)

Definition at line 124 of file gist.c.

References buffer, BUFFER_LOCK_EXCLUSIVE, END_CRIT_SECTION, F_LEAF, GISTInitBuffer(), INIT_FORKNUM, LockBuffer(), log_newpage_buffer(), MarkBufferDirty(), P_NEW, RBM_NORMAL, ReadBufferExtended(), START_CRIT_SECTION, and UnlockReleaseBuffer().

Referenced by gisthandler().

125 {
126  Buffer buffer;
127 
128  /* Initialize the root page */
129  buffer = ReadBufferExtended(index, INIT_FORKNUM, P_NEW, RBM_NORMAL, NULL);
131 
132  /* Initialize and xlog buffer */
134  GISTInitBuffer(buffer, F_LEAF);
135  MarkBufferDirty(buffer);
136  log_newpage_buffer(buffer, true);
138 
139  /* Unlock and release the buffer */
140  UnlockReleaseBuffer(buffer);
141 }
XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std)
Definition: xloginsert.c:1009
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1450
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:640
#define END_CRIT_SECTION()
Definition: miscadmin.h:133
#define START_CRIT_SECTION()
Definition: miscadmin.h:131
#define P_NEW
Definition: bufmgr.h:82
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:89
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
#define F_LEAF
Definition: gist.h:42
void GISTInitBuffer(Buffer b, uint32 f)
Definition: gistutil.c:721
int Buffer
Definition: buf.h:23

◆ gistdoinsert()

void gistdoinsert ( Relation  r,
IndexTuple  itup,
Size  freespace,
GISTSTATE giststate 
)

Definition at line 607 of file gist.c.

References Assert, GISTInsertStack::blkno, GISTInsertStack::buffer, BufferGetLSNAtomic(), BufferGetPage, GISTInsertStack::downlinkoffnum, ereport, errdetail(), errhint(), errmsg(), ERROR, GISTInsertState::freespace, GIST_EXCLUSIVE, GIST_ROOT_BLKNO, GIST_SHARE, GIST_UNLOCK, gistcheckpage(), gistchoose(), gistfixsplit(), GistFollowRight, gistgetadjusted(), gistinserttuple(), GistPageGetNSN, GistPageIsLeaf, GistTupleIsInvalid, InvalidOffsetNumber, ItemPointerGetBlockNumber, LockBuffer(), GISTInsertStack::lsn, GISTInsertStack::page, PageGetItem, PageGetItemId, PageGetLSN, palloc0(), GISTInsertStack::parent, GISTInsertState::r, ReadBuffer(), RelationGetRelationName, RelationNeedsWAL, ReleaseBuffer(), GISTInsertState::stack, IndexTupleData::t_tid, UnlockReleaseBuffer(), and XLogRecPtrIsInvalid.

Referenced by gistBuildCallback(), and gistinsert().

608 {
609  ItemId iid;
610  IndexTuple idxtuple;
611  GISTInsertStack firststack;
612  GISTInsertStack *stack;
614  bool xlocked = false;
615 
616  memset(&state, 0, sizeof(GISTInsertState));
617  state.freespace = freespace;
618  state.r = r;
619 
620  /* Start from the root */
621  firststack.blkno = GIST_ROOT_BLKNO;
622  firststack.lsn = 0;
623  firststack.parent = NULL;
624  firststack.downlinkoffnum = InvalidOffsetNumber;
625  state.stack = stack = &firststack;
626 
627  /*
628  * Walk down along the path of smallest penalty, updating the parent
629  * pointers with the key we're inserting as we go. If we crash in the
630  * middle, the tree is consistent, although the possible parent updates
631  * were a waste.
632  */
633  for (;;)
634  {
635  if (XLogRecPtrIsInvalid(stack->lsn))
636  stack->buffer = ReadBuffer(state.r, stack->blkno);
637 
638  /*
639  * Be optimistic and grab shared lock first. Swap it for an exclusive
640  * lock later if we need to update the page.
641  */
642  if (!xlocked)
643  {
644  LockBuffer(stack->buffer, GIST_SHARE);
645  gistcheckpage(state.r, stack->buffer);
646  }
647 
648  stack->page = (Page) BufferGetPage(stack->buffer);
649  stack->lsn = xlocked ?
650  PageGetLSN(stack->page) : BufferGetLSNAtomic(stack->buffer);
651  Assert(!RelationNeedsWAL(state.r) || !XLogRecPtrIsInvalid(stack->lsn));
652 
653  /*
654  * If this page was split but the downlink was never inserted to the
655  * parent because the inserting backend crashed before doing that, fix
656  * that now.
657  */
658  if (GistFollowRight(stack->page))
659  {
660  if (!xlocked)
661  {
662  LockBuffer(stack->buffer, GIST_UNLOCK);
664  xlocked = true;
665  /* someone might've completed the split when we unlocked */
666  if (!GistFollowRight(stack->page))
667  continue;
668  }
669  gistfixsplit(&state, giststate);
670 
671  UnlockReleaseBuffer(stack->buffer);
672  xlocked = false;
673  state.stack = stack = stack->parent;
674  continue;
675  }
676 
677  if (stack->blkno != GIST_ROOT_BLKNO &&
678  stack->parent->lsn < GistPageGetNSN(stack->page))
679  {
680  /*
681  * Concurrent split detected. There's no guarantee that the
682  * downlink for this page is consistent with the tuple we're
683  * inserting anymore, so go back to parent and rechoose the best
684  * child.
685  */
686  UnlockReleaseBuffer(stack->buffer);
687  xlocked = false;
688  state.stack = stack = stack->parent;
689  continue;
690  }
691 
692  if (!GistPageIsLeaf(stack->page))
693  {
694  /*
695  * This is an internal page so continue to walk down the tree.
696  * Find the child node that has the minimum insertion penalty.
697  */
698  BlockNumber childblkno;
699  IndexTuple newtup;
700  GISTInsertStack *item;
701  OffsetNumber downlinkoffnum;
702 
703  downlinkoffnum = gistchoose(state.r, stack->page, itup, giststate);
704  iid = PageGetItemId(stack->page, downlinkoffnum);
705  idxtuple = (IndexTuple) PageGetItem(stack->page, iid);
706  childblkno = ItemPointerGetBlockNumber(&(idxtuple->t_tid));
707 
708  /*
709  * Check that it's not a leftover invalid tuple from pre-9.1
710  */
711  if (GistTupleIsInvalid(idxtuple))
712  ereport(ERROR,
713  (errmsg("index \"%s\" contains an inner tuple marked as invalid",
715  errdetail("This is caused by an incomplete page split at crash recovery before upgrading to PostgreSQL 9.1."),
716  errhint("Please REINDEX it.")));
717 
718  /*
719  * Check that the key representing the target child node is
720  * consistent with the key we're inserting. Update it if it's not.
721  */
722  newtup = gistgetadjusted(state.r, idxtuple, itup, giststate);
723  if (newtup)
724  {
725  /*
726  * Swap shared lock for an exclusive one. Beware, the page may
727  * change while we unlock/lock the page...
728  */
729  if (!xlocked)
730  {
731  LockBuffer(stack->buffer, GIST_UNLOCK);
733  xlocked = true;
734  stack->page = (Page) BufferGetPage(stack->buffer);
735 
736  if (PageGetLSN(stack->page) != stack->lsn)
737  {
738  /* the page was changed while we unlocked it, retry */
739  continue;
740  }
741  }
742 
743  /*
744  * Update the tuple.
745  *
746  * We still hold the lock after gistinserttuple(), but it
747  * might have to split the page to make the updated tuple fit.
748  * In that case the updated tuple might migrate to the other
749  * half of the split, so we have to go back to the parent and
750  * descend back to the half that's a better fit for the new
751  * tuple.
752  */
753  if (gistinserttuple(&state, stack, giststate, newtup,
754  downlinkoffnum))
755  {
756  /*
757  * If this was a root split, the root page continues to be
758  * the parent and the updated tuple went to one of the
759  * child pages, so we just need to retry from the root
760  * page.
761  */
762  if (stack->blkno != GIST_ROOT_BLKNO)
763  {
764  UnlockReleaseBuffer(stack->buffer);
765  xlocked = false;
766  state.stack = stack = stack->parent;
767  }
768  continue;
769  }
770  }
771  LockBuffer(stack->buffer, GIST_UNLOCK);
772  xlocked = false;
773 
774  /* descend to the chosen child */
775  item = (GISTInsertStack *) palloc0(sizeof(GISTInsertStack));
776  item->blkno = childblkno;
777  item->parent = stack;
778  item->downlinkoffnum = downlinkoffnum;
779  state.stack = stack = item;
780  }
781  else
782  {
783  /*
784  * Leaf page. Insert the new key. We've already updated all the
785  * parents on the way down, but we might have to split the page if
786  * it doesn't fit. gistinserthere() will take care of that.
787  */
788 
789  /*
790  * Swap shared lock for an exclusive one. Be careful, the page may
791  * change while we unlock/lock the page...
792  */
793  if (!xlocked)
794  {
795  LockBuffer(stack->buffer, GIST_UNLOCK);
797  xlocked = true;
798  stack->page = (Page) BufferGetPage(stack->buffer);
799  stack->lsn = PageGetLSN(stack->page);
800 
801  if (stack->blkno == GIST_ROOT_BLKNO)
802  {
803  /*
804  * the only page that can become inner instead of leaf is
805  * the root page, so for root we should recheck it
806  */
807  if (!GistPageIsLeaf(stack->page))
808  {
809  /*
810  * very rare situation: during unlock/lock index with
811  * number of pages = 1 was increased
812  */
813  LockBuffer(stack->buffer, GIST_UNLOCK);
814  xlocked = false;
815  continue;
816  }
817 
818  /*
819  * we don't need to check root split, because checking
820  * leaf/inner is enough to recognize split for root
821  */
822  }
823  else if (GistFollowRight(stack->page) ||
824  stack->parent->lsn < GistPageGetNSN(stack->page))
825  {
826  /*
827  * The page was split while we momentarily unlocked the
828  * page. Go back to parent.
829  */
830  UnlockReleaseBuffer(stack->buffer);
831  xlocked = false;
832  state.stack = stack = stack->parent;
833  continue;
834  }
835  }
836 
837  /* now state.stack->(page, buffer and blkno) points to leaf page */
838 
839  gistinserttuple(&state, stack, giststate, itup,
841  LockBuffer(stack->buffer, GIST_UNLOCK);
842 
843  /* Release any pins we might still hold before exiting */
844  for (; stack; stack = stack->parent)
845  ReleaseBuffer(stack->buffer);
846  break;
847  }
848  }
849 }
#define GistFollowRight(page)
Definition: gist.h:147
BlockNumber blkno
Definition: gist_private.h:206
#define GistPageGetNSN(page)
Definition: gist.h:151
static bool gistinserttuple(GISTInsertState *state, GISTInsertStack *stack, GISTSTATE *giststate, IndexTuple tuple, OffsetNumber oldoffnum)
Definition: gist.c:1179
int errhint(const char *fmt,...)
Definition: elog.c:987
static void gistfixsplit(GISTInsertState *state, GISTSTATE *giststate)
Definition: gist.c:1120
ItemPointerData t_tid
Definition: itup.h:37
#define GistTupleIsInvalid(itup)
Definition: gist_private.h:275
#define GIST_UNLOCK
Definition: gist_private.h:45
uint32 BlockNumber
Definition: block.h:31
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
IndexTuple gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate)
Definition: gistutil.c:314
uint16 OffsetNumber
Definition: off.h:24
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
#define ERROR
Definition: elog.h:43
GISTInsertStack * stack
Definition: gist_private.h:245
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
Definition: bufmgr.c:2832
IndexTupleData * IndexTuple
Definition: itup.h:53
int errdetail(const char *fmt,...)
Definition: elog.c:873
#define RelationGetRelationName(relation)
Definition: rel.h:441
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
OffsetNumber gistchoose(Relation r, Page p, IndexTuple it, GISTSTATE *giststate)
Definition: gistutil.c:372
#define GistPageIsLeaf(page)
Definition: gist.h:132
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29
OffsetNumber downlinkoffnum
Definition: gist_private.h:217
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:231
void * palloc0(Size size)
Definition: mcxt.c:955
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define InvalidOffsetNumber
Definition: off.h:26
#define Assert(condition)
Definition: c.h:699
Definition: regguts.h:298
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
void gistcheckpage(Relation rel, Buffer buf)
Definition: gistutil.c:743
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:594
#define GIST_SHARE
Definition: gist_private.h:43
#define RelationNeedsWAL(relation)
Definition: rel.h:510
#define PageGetLSN(page)
Definition: bufpage.h:362
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define GIST_ROOT_BLKNO
Definition: gist_private.h:249
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
#define GIST_EXCLUSIVE
Definition: gist_private.h:44
struct GISTInsertStack * parent
Definition: gist_private.h:220
#define PageGetItem(page, itemId)
Definition: bufpage.h:336
Pointer Page
Definition: bufpage.h:74

◆ gistFindCorrectParent()

static void gistFindCorrectParent ( Relation  r,
GISTInsertStack child 
)
static

Definition at line 971 of file gist.c.

References GISTInsertStack::blkno, GISTInsertStack::buffer, BufferGetPage, GISTInsertStack::downlinkoffnum, FirstOffsetNumber, GIST_EXCLUSIVE, gistcheckpage(), gistFindPath(), GistPageGetOpaque, i, InvalidBlockNumber, InvalidOffsetNumber, ItemPointerGetBlockNumber, LockBuffer(), GISTInsertStack::lsn, OffsetNumberNext, GISTInsertStack::page, PageGetItem, PageGetItemId, PageGetLSN, PageGetMaxOffsetNumber, DataPageDeleteStack::parent, GISTInsertStack::parent, ReadBuffer(), ReleaseBuffer(), IndexTupleData::t_tid, and UnlockReleaseBuffer().

Referenced by gistfinishsplit(), and gistformdownlink().

972 {
973  GISTInsertStack *parent = child->parent;
974 
975  gistcheckpage(r, parent->buffer);
976  parent->page = (Page) BufferGetPage(parent->buffer);
977 
978  /* here we don't need to distinguish between split and page update */
979  if (child->downlinkoffnum == InvalidOffsetNumber ||
980  parent->lsn != PageGetLSN(parent->page))
981  {
982  /* parent is changed, look child in right links until found */
983  OffsetNumber i,
984  maxoff;
985  ItemId iid;
986  IndexTuple idxtuple;
987  GISTInsertStack *ptr;
988 
989  while (true)
990  {
991  maxoff = PageGetMaxOffsetNumber(parent->page);
992  for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
993  {
994  iid = PageGetItemId(parent->page, i);
995  idxtuple = (IndexTuple) PageGetItem(parent->page, iid);
996  if (ItemPointerGetBlockNumber(&(idxtuple->t_tid)) == child->blkno)
997  {
998  /* yes!!, found */
999  child->downlinkoffnum = i;
1000  return;
1001  }
1002  }
1003 
1004  parent->blkno = GistPageGetOpaque(parent->page)->rightlink;
1005  UnlockReleaseBuffer(parent->buffer);
1006  if (parent->blkno == InvalidBlockNumber)
1007  {
1008  /*
1009  * End of chain and still didn't find parent. It's a very-very
1010  * rare situation when root splited.
1011  */
1012  break;
1013  }
1014  parent->buffer = ReadBuffer(r, parent->blkno);
1015  LockBuffer(parent->buffer, GIST_EXCLUSIVE);
1016  gistcheckpage(r, parent->buffer);
1017  parent->page = (Page) BufferGetPage(parent->buffer);
1018  }
1019 
1020  /*
1021  * awful!!, we need search tree to find parent ... , but before we
1022  * should release all old parent
1023  */
1024 
1025  ptr = child->parent->parent; /* child->parent already released
1026  * above */
1027  while (ptr)
1028  {
1029  ReleaseBuffer(ptr->buffer);
1030  ptr = ptr->parent;
1031  }
1032 
1033  /* ok, find new path */
1034  ptr = parent = gistFindPath(r, child->blkno, &child->downlinkoffnum);
1035 
1036  /* read all buffers as expected by caller */
1037  /* note we don't lock them or gistcheckpage them here! */
1038  while (ptr)
1039  {
1040  ptr->buffer = ReadBuffer(r, ptr->blkno);
1041  ptr->page = (Page) BufferGetPage(ptr->buffer);
1042  ptr = ptr->parent;
1043  }
1044 
1045  /* install new chain of parents to stack */
1046  child->parent = parent;
1047 
1048  /* make recursive call to normal processing */
1050  gistFindCorrectParent(r, child);
1051  }
1052 
1053  return;
1054 }
BlockNumber blkno
Definition: gist_private.h:206
ItemPointerData t_tid
Definition: itup.h:37
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:353
uint16 OffsetNumber
Definition: off.h:24
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
#define FirstOffsetNumber
Definition: off.h:27
IndexTupleData * IndexTuple
Definition: itup.h:53
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
OffsetNumber downlinkoffnum
Definition: gist_private.h:217
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:231
static void gistFindCorrectParent(Relation r, GISTInsertStack *child)
Definition: gist.c:971
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define InvalidOffsetNumber
Definition: off.h:26
static GISTInsertStack * gistFindPath(Relation r, BlockNumber child, OffsetNumber *downlinkoffnum)
Definition: gist.c:861
#define GistPageGetOpaque(page)
Definition: gist.h:130
void gistcheckpage(Relation rel, Buffer buf)
Definition: gistutil.c:743
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:594
#define OffsetNumberNext(offsetNumber)
Definition: off.h:53
#define InvalidBlockNumber
Definition: block.h:33
#define PageGetLSN(page)
Definition: bufpage.h:362
int i
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
#define GIST_EXCLUSIVE
Definition: gist_private.h:44
struct GISTInsertStack * parent
Definition: gist_private.h:220
#define PageGetItem(page, itemId)
Definition: bufpage.h:336
Pointer Page
Definition: bufpage.h:74

◆ gistFindPath()

static GISTInsertStack* gistFindPath ( Relation  r,
BlockNumber  child,
OffsetNumber downlinkoffnum 
)
static

Definition at line 861 of file gist.c.

References DataPageDeleteStack::blkno, GISTInsertStack::blkno, buffer, BufferGetLSNAtomic(), BufferGetPage, GISTInsertStack::downlinkoffnum, elog, ERROR, FirstOffsetNumber, GIST_ROOT_BLKNO, GIST_SHARE, gistcheckpage(), GistFollowRight, GistPageGetNSN, GistPageGetOpaque, GistPageIsLeaf, i, InvalidBlockNumber, InvalidOffsetNumber, ItemPointerGetBlockNumber, lappend(), lcons(), linitial, list_delete_first(), list_make1, LockBuffer(), GISTInsertStack::lsn, NIL, OffsetNumberNext, PageGetItem, PageGetItemId, PageGetMaxOffsetNumber, palloc0(), GISTInsertStack::parent, ReadBuffer(), RelationGetRelationName, IndexTupleData::t_tid, and UnlockReleaseBuffer().

Referenced by gistFindCorrectParent().

862 {
863  Page page;
864  Buffer buffer;
865  OffsetNumber i,
866  maxoff;
867  ItemId iid;
868  IndexTuple idxtuple;
869  List *fifo;
870  GISTInsertStack *top,
871  *ptr;
872  BlockNumber blkno;
873 
874  top = (GISTInsertStack *) palloc0(sizeof(GISTInsertStack));
875  top->blkno = GIST_ROOT_BLKNO;
877 
878  fifo = list_make1(top);
879  while (fifo != NIL)
880  {
881  /* Get next page to visit */
882  top = linitial(fifo);
883  fifo = list_delete_first(fifo);
884 
885  buffer = ReadBuffer(r, top->blkno);
886  LockBuffer(buffer, GIST_SHARE);
887  gistcheckpage(r, buffer);
888  page = (Page) BufferGetPage(buffer);
889 
890  if (GistPageIsLeaf(page))
891  {
892  /*
893  * Because we scan the index top-down, all the rest of the pages
894  * in the queue must be leaf pages as well.
895  */
896  UnlockReleaseBuffer(buffer);
897  break;
898  }
899 
900  top->lsn = BufferGetLSNAtomic(buffer);
901 
902  /*
903  * If F_FOLLOW_RIGHT is set, the page to the right doesn't have a
904  * downlink. This should not normally happen..
905  */
906  if (GistFollowRight(page))
907  elog(ERROR, "concurrent GiST page split was incomplete");
908 
909  if (top->parent && top->parent->lsn < GistPageGetNSN(page) &&
910  GistPageGetOpaque(page)->rightlink != InvalidBlockNumber /* sanity check */ )
911  {
912  /*
913  * Page was split while we looked elsewhere. We didn't see the
914  * downlink to the right page when we scanned the parent, so add
915  * it to the queue now.
916  *
917  * Put the right page ahead of the queue, so that we visit it
918  * next. That's important, because if this is the lowest internal
919  * level, just above leaves, we might already have queued up some
920  * leaf pages, and we assume that there can't be any non-leaf
921  * pages behind leaf pages.
922  */
923  ptr = (GISTInsertStack *) palloc0(sizeof(GISTInsertStack));
924  ptr->blkno = GistPageGetOpaque(page)->rightlink;
926  ptr->parent = top->parent;
927 
928  fifo = lcons(ptr, fifo);
929  }
930 
931  maxoff = PageGetMaxOffsetNumber(page);
932 
933  for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
934  {
935  iid = PageGetItemId(page, i);
936  idxtuple = (IndexTuple) PageGetItem(page, iid);
937  blkno = ItemPointerGetBlockNumber(&(idxtuple->t_tid));
938  if (blkno == child)
939  {
940  /* Found it! */
941  UnlockReleaseBuffer(buffer);
942  *downlinkoffnum = i;
943  return top;
944  }
945  else
946  {
947  /* Append this child to the list of pages to visit later */
948  ptr = (GISTInsertStack *) palloc0(sizeof(GISTInsertStack));
949  ptr->blkno = blkno;
950  ptr->downlinkoffnum = i;
951  ptr->parent = top;
952 
953  fifo = lappend(fifo, ptr);
954  }
955  }
956 
957  UnlockReleaseBuffer(buffer);
958  }
959 
960  elog(ERROR, "failed to re-find parent of a page in index \"%s\", block %u",
961  RelationGetRelationName(r), child);
962  return NULL; /* keep compiler quiet */
963 }
#define GistFollowRight(page)
Definition: gist.h:147
#define NIL
Definition: pg_list.h:69
BlockNumber blkno
Definition: gist_private.h:206
#define GistPageGetNSN(page)
Definition: gist.h:151
ItemPointerData t_tid
Definition: itup.h:37
uint32 BlockNumber
Definition: block.h:31
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:353
uint16 OffsetNumber
Definition: off.h:24
#define list_make1(x1)
Definition: pg_list.h:139
#define linitial(l)
Definition: pg_list.h:111
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
#define ERROR
Definition: elog.h:43
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
Definition: bufmgr.c:2832
#define FirstOffsetNumber
Definition: off.h:27
IndexTupleData * IndexTuple
Definition: itup.h:53
#define RelationGetRelationName(relation)
Definition: rel.h:441
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
List * lappend(List *list, void *datum)
Definition: list.c:128
#define GistPageIsLeaf(page)
Definition: gist.h:132
OffsetNumber downlinkoffnum
Definition: gist_private.h:217
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:231
void * palloc0(Size size)
Definition: mcxt.c:955
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define InvalidOffsetNumber
Definition: off.h:26
#define GistPageGetOpaque(page)
Definition: gist.h:130
List * lcons(void *datum, List *list)
Definition: list.c:259
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
void gistcheckpage(Relation rel, Buffer buf)
Definition: gistutil.c:743
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:594
#define OffsetNumberNext(offsetNumber)
Definition: off.h:53
#define InvalidBlockNumber
Definition: block.h:33
#define GIST_SHARE
Definition: gist_private.h:43
int i
#define GIST_ROOT_BLKNO
Definition: gist_private.h:249
#define elog
Definition: elog.h:219
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
Definition: pg_list.h:45
int Buffer
Definition: buf.h:23
struct GISTInsertStack * parent
Definition: gist_private.h:220
#define PageGetItem(page, itemId)
Definition: bufpage.h:336
Pointer Page
Definition: bufpage.h:74
List * list_delete_first(List *list)
Definition: list.c:666

◆ gistfinishsplit()

static void gistfinishsplit ( GISTInsertState state,
GISTInsertStack stack,
GISTSTATE giststate,
List splitinfo,
bool  releasebuf 
)
static

Definition at line 1271 of file gist.c.

References Assert, GISTPageSplitInfo::buf, GISTInsertStack::buffer, GISTPageSplitInfo::downlink, GISTInsertStack::downlinkoffnum, GIST_EXCLUSIVE, gistFindCorrectParent(), gistinserttuples(), InvalidOffsetNumber, lcons(), lfirst, linitial, list_delete_first(), list_length(), LockBuffer(), lsecond, NIL, GISTInsertStack::parent, and GISTInsertState::r.

Referenced by gistfixsplit(), and gistinserttuples().

1273 {
1274  ListCell *lc;
1275  List *reversed;
1276  GISTPageSplitInfo *right;
1277  GISTPageSplitInfo *left;
1278  IndexTuple tuples[2];
1279 
1280  /* A split always contains at least two halves */
1281  Assert(list_length(splitinfo) >= 2);
1282 
1283  /*
1284  * We need to insert downlinks for each new page, and update the downlink
1285  * for the original (leftmost) page in the split. Begin at the rightmost
1286  * page, inserting one downlink at a time until there's only two pages
1287  * left. Finally insert the downlink for the last new page and update the
1288  * downlink for the original page as one operation.
1289  */
1290 
1291  /* for convenience, create a copy of the list in reverse order */
1292  reversed = NIL;
1293  foreach(lc, splitinfo)
1294  {
1295  reversed = lcons(lfirst(lc), reversed);
1296  }
1297 
1299  gistFindCorrectParent(state->r, stack);
1300 
1301  /*
1302  * insert downlinks for the siblings from right to left, until there are
1303  * only two siblings left.
1304  */
1305  while (list_length(reversed) > 2)
1306  {
1307  right = (GISTPageSplitInfo *) linitial(reversed);
1308  left = (GISTPageSplitInfo *) lsecond(reversed);
1309 
1310  if (gistinserttuples(state, stack->parent, giststate,
1311  &right->downlink, 1,
1313  left->buf, right->buf, false, false))
1314  {
1315  /*
1316  * If the parent page was split, need to relocate the original
1317  * parent pointer.
1318  */
1319  gistFindCorrectParent(state->r, stack);
1320  }
1321  /* gistinserttuples() released the lock on right->buf. */
1322  reversed = list_delete_first(reversed);
1323  }
1324 
1325  right = (GISTPageSplitInfo *) linitial(reversed);
1326  left = (GISTPageSplitInfo *) lsecond(reversed);
1327 
1328  /*
1329  * Finally insert downlink for the remaining right page and update the
1330  * downlink for the original page to not contain the tuples that were
1331  * moved to the new pages.
1332  */
1333  tuples[0] = left->downlink;
1334  tuples[1] = right->downlink;
1335  gistinserttuples(state, stack->parent, giststate,
1336  tuples, 2,
1337  stack->downlinkoffnum,
1338  left->buf, right->buf,
1339  true, /* Unlock parent */
1340  unlockbuf /* Unlock stack->buffer if caller wants that */
1341  );
1342  Assert(left->buf == stack->buffer);
1343 }
#define NIL
Definition: pg_list.h:69
#define lsecond(l)
Definition: pg_list.h:116
#define linitial(l)
Definition: pg_list.h:111
IndexTuple downlink
Definition: gist_private.h:398
OffsetNumber downlinkoffnum
Definition: gist_private.h:217
static void gistFindCorrectParent(Relation r, GISTInsertStack *child)
Definition: gist.c:971
static bool gistinserttuples(GISTInsertState *state, GISTInsertStack *stack, GISTSTATE *giststate, IndexTuple *tuples, int ntup, OffsetNumber oldoffnum, Buffer leftchild, Buffer rightchild, bool unlockbuf, bool unlockleftchild)
Definition: gist.c:1213
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define InvalidOffsetNumber
Definition: off.h:26
List * lcons(void *datum, List *list)
Definition: list.c:259
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
#define GIST_EXCLUSIVE
Definition: gist_private.h:44
Definition: pg_list.h:45
struct GISTInsertStack * parent
Definition: gist_private.h:220
List * list_delete_first(List *list)
Definition: list.c:666

◆ gistfixsplit()

static void gistfixsplit ( GISTInsertState state,
GISTSTATE giststate 
)
static

Definition at line 1120 of file gist.c.

References Assert, GISTInsertStack::blkno, buf, GISTPageSplitInfo::buf, GISTInsertStack::buffer, BufferGetPage, GISTPageSplitInfo::downlink, GISTInsertStack::downlinkoffnum, elog, GIST_EXCLUSIVE, gistfinishsplit(), GistFollowRight, gistformdownlink(), GistPageGetOpaque, lappend(), LockBuffer(), LOG, NIL, OffsetNumberIsValid, GISTInsertStack::page, palloc(), GISTInsertState::r, ReadBuffer(), RelationGetRelationName, and GISTInsertState::stack.

Referenced by gistdoinsert().

1121 {
1122  GISTInsertStack *stack = state->stack;
1123  Buffer buf;
1124  Page page;
1125  List *splitinfo = NIL;
1126 
1127  elog(LOG, "fixing incomplete split in index \"%s\", block %u",
1128  RelationGetRelationName(state->r), stack->blkno);
1129 
1130  Assert(GistFollowRight(stack->page));
1132 
1133  buf = stack->buffer;
1134 
1135  /*
1136  * Read the chain of split pages, following the rightlinks. Construct a
1137  * downlink tuple for each page.
1138  */
1139  for (;;)
1140  {
1142  IndexTuple downlink;
1143 
1144  page = BufferGetPage(buf);
1145 
1146  /* Form the new downlink tuples to insert to parent */
1147  downlink = gistformdownlink(state->r, buf, giststate, stack);
1148 
1149  si->buf = buf;
1150  si->downlink = downlink;
1151 
1152  splitinfo = lappend(splitinfo, si);
1153 
1154  if (GistFollowRight(page))
1155  {
1156  /* lock next page */
1157  buf = ReadBuffer(state->r, GistPageGetOpaque(page)->rightlink);
1158  LockBuffer(buf, GIST_EXCLUSIVE);
1159  }
1160  else
1161  break;
1162  }
1163 
1164  /* Insert the downlinks */
1165  gistfinishsplit(state, stack, giststate, splitinfo, false);
1166 }
#define GistFollowRight(page)
Definition: gist.h:147
#define NIL
Definition: pg_list.h:69
BlockNumber blkno
Definition: gist_private.h:206
#define LOG
Definition: elog.h:26
static void gistfinishsplit(GISTInsertState *state, GISTInsertStack *stack, GISTSTATE *giststate, List *splitinfo, bool releasebuf)
Definition: gist.c:1271
static IndexTuple gistformdownlink(Relation rel, Buffer buf, GISTSTATE *giststate, GISTInsertStack *stack)
Definition: gist.c:1060
IndexTuple downlink
Definition: gist_private.h:398
GISTInsertStack * stack
Definition: gist_private.h:245
static char * buf
Definition: pg_test_fsync.c:67
#define RelationGetRelationName(relation)
Definition: rel.h:441
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
List * lappend(List *list, void *datum)
Definition: list.c:128
OffsetNumber downlinkoffnum
Definition: gist_private.h:217
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define GistPageGetOpaque(page)
Definition: gist.h:130
#define Assert(condition)
Definition: c.h:699
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:594
void * palloc(Size size)
Definition: mcxt.c:924
#define OffsetNumberIsValid(offsetNumber)
Definition: off.h:40
#define elog
Definition: elog.h:219
#define GIST_EXCLUSIVE
Definition: gist_private.h:44
Definition: pg_list.h:45
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:74

◆ gistformdownlink()

static IndexTuple gistformdownlink ( Relation  rel,
Buffer  buf,
GISTSTATE giststate,
GISTInsertStack stack 
)
static

Definition at line 1060 of file gist.c.

References GISTInsertStack::buffer, BufferGetBlockNumber(), BufferGetPage, CopyIndexTuple(), GISTInsertStack::downlinkoffnum, FirstOffsetNumber, GIST_EXCLUSIVE, GIST_UNLOCK, gistFindCorrectParent(), gistgetadjusted(), GistTupleSetValid, ItemPointerSetBlockNumber, LockBuffer(), OffsetNumberNext, GISTInsertStack::page, PageGetItem, PageGetItemId, PageGetMaxOffsetNumber, GISTInsertStack::parent, and IndexTupleData::t_tid.

Referenced by gistfixsplit().

1062 {
1063  Page page = BufferGetPage(buf);
1064  OffsetNumber maxoff;
1065  OffsetNumber offset;
1066  IndexTuple downlink = NULL;
1067 
1068  maxoff = PageGetMaxOffsetNumber(page);
1069  for (offset = FirstOffsetNumber; offset <= maxoff; offset = OffsetNumberNext(offset))
1070  {
1071  IndexTuple ituple = (IndexTuple)
1072  PageGetItem(page, PageGetItemId(page, offset));
1073 
1074  if (downlink == NULL)
1075  downlink = CopyIndexTuple(ituple);
1076  else
1077  {
1078  IndexTuple newdownlink;
1079 
1080  newdownlink = gistgetadjusted(rel, downlink, ituple,
1081  giststate);
1082  if (newdownlink)
1083  downlink = newdownlink;
1084  }
1085  }
1086 
1087  /*
1088  * If the page is completely empty, we can't form a meaningful downlink
1089  * for it. But we have to insert a downlink for the page. Any key will do,
1090  * as long as its consistent with the downlink of parent page, so that we
1091  * can legally insert it to the parent. A minimal one that matches as few
1092  * scans as possible would be best, to keep scans from doing useless work,
1093  * but we don't know how to construct that. So we just use the downlink of
1094  * the original page that was split - that's as far from optimal as it can
1095  * get but will do..
1096  */
1097  if (!downlink)
1098  {
1099  ItemId iid;
1100 
1102  gistFindCorrectParent(rel, stack);
1103  iid = PageGetItemId(stack->parent->page, stack->downlinkoffnum);
1104  downlink = (IndexTuple) PageGetItem(stack->parent->page, iid);
1105  downlink = CopyIndexTuple(downlink);
1106  LockBuffer(stack->parent->buffer, GIST_UNLOCK);
1107  }
1108 
1110  GistTupleSetValid(downlink);
1111 
1112  return downlink;
1113 }
ItemPointerData t_tid
Definition: itup.h:37
#define GIST_UNLOCK
Definition: gist_private.h:45
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:353
IndexTuple gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate)
Definition: gistutil.c:314
uint16 OffsetNumber
Definition: off.h:24
IndexTuple CopyIndexTuple(IndexTuple source)
Definition: indextuple.c:441
static char * buf
Definition: pg_test_fsync.c:67
#define FirstOffsetNumber
Definition: off.h:27
IndexTupleData * IndexTuple
Definition: itup.h:53
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define GistTupleSetValid(itup)
Definition: gist_private.h:276
OffsetNumber downlinkoffnum
Definition: gist_private.h:217
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:231
static void gistFindCorrectParent(Relation r, GISTInsertStack *child)
Definition: gist.c:971
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define OffsetNumberNext(offsetNumber)
Definition: off.h:53
#define ItemPointerSetBlockNumber(pointer, blockNumber)
Definition: itemptr.h:138
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
#define GIST_EXCLUSIVE
Definition: gist_private.h:44
struct GISTInsertStack * parent
Definition: gist_private.h:220
#define PageGetItem(page, itemId)
Definition: bufpage.h:336
Pointer Page
Definition: bufpage.h:74

◆ gisthandler()

Datum gisthandler ( PG_FUNCTION_ARGS  )

Definition at line 59 of file gist.c.

References IndexAmRoutine::ambeginscan, IndexAmRoutine::ambuild, IndexAmRoutine::ambuildempty, 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::amparallelrescan, IndexAmRoutine::ampredlocks, IndexAmRoutine::amproperty, IndexAmRoutine::amrescan, IndexAmRoutine::amrestrpos, IndexAmRoutine::amsearcharray, IndexAmRoutine::amsearchnulls, IndexAmRoutine::amstorage, IndexAmRoutine::amstrategies, IndexAmRoutine::amsupport, IndexAmRoutine::amvacuumcleanup, IndexAmRoutine::amvalidate, gistbeginscan(), gistbuild(), gistbuildempty(), gistbulkdelete(), gistcanreturn(), gistcostestimate(), gistendscan(), gistgetbitmap(), gistgettuple(), gistinsert(), GISTNProcs, gistoptions(), gistproperty(), gistrescan(), gistvacuumcleanup(), gistvalidate(), InvalidOid, makeNode, and PG_RETURN_POINTER.

60 {
62 
63  amroutine->amstrategies = 0;
64  amroutine->amsupport = GISTNProcs;
65  amroutine->amcanorder = false;
66  amroutine->amcanorderbyop = true;
67  amroutine->amcanbackward = false;
68  amroutine->amcanunique = false;
69  amroutine->amcanmulticol = true;
70  amroutine->amoptionalkey = true;
71  amroutine->amsearcharray = false;
72  amroutine->amsearchnulls = true;
73  amroutine->amstorage = true;
74  amroutine->amclusterable = true;
75  amroutine->ampredlocks = true;
76  amroutine->amcanparallel = false;
77  amroutine->amcaninclude = false;
78  amroutine->amkeytype = InvalidOid;
79 
80  amroutine->ambuild = gistbuild;
81  amroutine->ambuildempty = gistbuildempty;
82  amroutine->aminsert = gistinsert;
83  amroutine->ambulkdelete = gistbulkdelete;
85  amroutine->amcanreturn = gistcanreturn;
86  amroutine->amcostestimate = gistcostestimate;
87  amroutine->amoptions = gistoptions;
88  amroutine->amproperty = gistproperty;
89  amroutine->amvalidate = gistvalidate;
90  amroutine->ambeginscan = gistbeginscan;
91  amroutine->amrescan = gistrescan;
92  amroutine->amgettuple = gistgettuple;
93  amroutine->amgetbitmap = gistgetbitmap;
94  amroutine->amendscan = gistendscan;
95  amroutine->ammarkpos = NULL;
96  amroutine->amrestrpos = NULL;
97  amroutine->amestimateparallelscan = NULL;
98  amroutine->aminitparallelscan = NULL;
99  amroutine->amparallelrescan = NULL;
100 
101  PG_RETURN_POINTER(amroutine);
102 }
ambeginscan_function ambeginscan
Definition: amapi.h:217
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
ambulkdelete_function ambulkdelete
Definition: amapi.h:210
bool amcanmulticol
Definition: amapi.h:180
uint16 amsupport
Definition: amapi.h:170
amgettuple_function amgettuple
Definition: amapi.h:219
IndexBulkDeleteResult * gistvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: gistvacuum.c:29
bool amcanorderbyop
Definition: amapi.h:174
amproperty_function amproperty
Definition: amapi.h:215
IndexBulkDeleteResult * gistbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition: gistvacuum.c:138
amparallelrescan_function amparallelrescan
Definition: amapi.h:228
bool amstorage
Definition: amapi.h:188
bool gistgettuple(IndexScanDesc scan, ScanDirection dir)
Definition: gistget.c:630
bool ampredlocks
Definition: amapi.h:192
aminsert_function aminsert
Definition: amapi.h:209
bytea * gistoptions(Datum reloptions, bool validate)
Definition: gistutil.c:836
Oid amkeytype
Definition: amapi.h:198
bool amoptionalkey
Definition: amapi.h:182
amvalidate_function amvalidate
Definition: amapi.h:216
bool gistinsert(Relation r, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, IndexInfo *indexInfo)
Definition: gist.c:150
IndexBuildResult * gistbuild(Relation heap, Relation index, IndexInfo *indexInfo)
Definition: gistbuild.c:114
amgetbitmap_function amgetbitmap
Definition: amapi.h:220
ambuild_function ambuild
Definition: amapi.h:207
amoptions_function amoptions
Definition: amapi.h:214
bool amcaninclude
Definition: amapi.h:196
amcostestimate_function amcostestimate
Definition: amapi.h:213
bool amcanunique
Definition: amapi.h:178
void gistrescan(IndexScanDesc scan, ScanKey key, int nkeys, ScanKey orderbys, int norderbys)
Definition: gistscan.c:111
void gistcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Definition: selfuncs.c:7283
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:211
amendscan_function amendscan
Definition: amapi.h:221
bool amcanbackward
Definition: amapi.h:176
amrescan_function amrescan
Definition: amapi.h:218
bool amcanparallel
Definition: amapi.h:194
int64 gistgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
Definition: gistget.c:761
void gistbuildempty(Relation index)
Definition: gist.c:124
bool amsearchnulls
Definition: amapi.h:186
bool amclusterable
Definition: amapi.h:190
bool amsearcharray
Definition: amapi.h:184
#define InvalidOid
Definition: postgres_ext.h:36
bool gistcanreturn(Relation index, int attno)
Definition: gistget.c:810
#define makeNode(_type_)
Definition: nodes.h:565
ammarkpos_function ammarkpos
Definition: amapi.h:222
bool amcanorder
Definition: amapi.h:172
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:226
#define GISTNProcs
Definition: gist.h:37
uint16 amstrategies
Definition: amapi.h:168
bool gistvalidate(Oid opclassoid)
Definition: gistvalidate.c:34
ambuildempty_function ambuildempty
Definition: amapi.h:208
IndexScanDesc gistbeginscan(Relation r, int nkeys, int norderbys)
Definition: gistscan.c:58
void gistendscan(IndexScanDesc scan)
Definition: gistscan.c:322
bool gistproperty(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
Definition: gistutil.c:871
amcanreturn_function amcanreturn
Definition: amapi.h:212
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:227
amrestrpos_function amrestrpos
Definition: amapi.h:223

◆ gistinsert()

bool gistinsert ( Relation  r,
Datum values,
bool isnull,
ItemPointer  ht_ctid,
Relation  heapRel,
IndexUniqueCheck  checkUnique,
IndexInfo indexInfo 
)

Definition at line 150 of file gist.c.

References createTempGistContext(), gistdoinsert(), gistFormTuple(), IndexInfo::ii_AmCache, IndexInfo::ii_Context, initGISTstate(), MemoryContextReset(), MemoryContextSwitchTo(), and GISTSTATE::tempCxt.

Referenced by gisthandler().

154 {
155  GISTSTATE *giststate = (GISTSTATE *) indexInfo->ii_AmCache;
156  IndexTuple itup;
157  MemoryContext oldCxt;
158 
159  /* Initialize GISTSTATE cache if first call in this statement */
160  if (giststate == NULL)
161  {
162  oldCxt = MemoryContextSwitchTo(indexInfo->ii_Context);
163  giststate = initGISTstate(r);
164  giststate->tempCxt = createTempGistContext();
165  indexInfo->ii_AmCache = (void *) giststate;
166  MemoryContextSwitchTo(oldCxt);
167  }
168 
169  oldCxt = MemoryContextSwitchTo(giststate->tempCxt);
170 
171  itup = gistFormTuple(giststate, r,
172  values, isnull, true /* size is currently bogus */ );
173  itup->t_tid = *ht_ctid;
174 
175  gistdoinsert(r, itup, 0, giststate);
176 
177  /* cleanup */
178  MemoryContextSwitchTo(oldCxt);
179  MemoryContextReset(giststate->tempCxt);
180 
181  return false;
182 }
MemoryContext ii_Context
Definition: execnodes.h:171
MemoryContext createTempGistContext(void)
Definition: gist.c:113
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:136
void gistdoinsert(Relation r, IndexTuple itup, Size freespace, GISTSTATE *giststate)
Definition: gist.c:607
MemoryContext tempCxt
Definition: gist_private.h:79
void * ii_AmCache
Definition: execnodes.h:170
GISTSTATE * initGISTstate(Relation index)
Definition: gist.c:1436
static Datum values[MAXATTR]
Definition: bootstrap.c:164
IndexTuple gistFormTuple(GISTSTATE *giststate, Relation r, Datum attdata[], bool isnull[], bool isleaf)
Definition: gistutil.c:572

◆ gistinserttuple()

static bool gistinserttuple ( GISTInsertState state,
GISTInsertStack stack,
GISTSTATE giststate,
IndexTuple  tuple,
OffsetNumber  oldoffnum 
)
static

Definition at line 1179 of file gist.c.

References gistinserttuples(), and InvalidBuffer.

Referenced by gistdoinsert().

1181 {
1182  return gistinserttuples(state, stack, giststate, &tuple, 1, oldoffnum,
1183  InvalidBuffer, InvalidBuffer, false, false);
1184 }
#define InvalidBuffer
Definition: buf.h:25
static bool gistinserttuples(GISTInsertState *state, GISTInsertStack *stack, GISTSTATE *giststate, IndexTuple *tuples, int ntup, OffsetNumber oldoffnum, Buffer leftchild, Buffer rightchild, bool unlockbuf, bool unlockleftchild)
Definition: gist.c:1213

◆ gistinserttuples()

static bool gistinserttuples ( GISTInsertState state,
GISTInsertStack stack,
GISTSTATE giststate,
IndexTuple tuples,
int  ntup,
OffsetNumber  oldoffnum,
Buffer  leftchild,
Buffer  rightchild,
bool  unlockbuf,
bool  unlockleftchild 
)
static

Definition at line 1213 of file gist.c.

References GISTInsertStack::buffer, BufferIsValid, CheckForSerializableConflictIn(), GISTInsertState::freespace, GIST_UNLOCK, gistfinishsplit(), gistplacetopage(), LockBuffer(), GISTInsertState::r, and UnlockReleaseBuffer().

Referenced by gistfinishsplit(), and gistinserttuple().

1218 {
1219  List *splitinfo;
1220  bool is_split;
1221 
1222  /*
1223  * Check for any rw conflicts (in serializable isolation level) just
1224  * before we intend to modify the page
1225  */
1226  CheckForSerializableConflictIn(state->r, NULL, stack->buffer);
1227 
1228  /* Insert the tuple(s) to the page, splitting the page if necessary */
1229  is_split = gistplacetopage(state->r, state->freespace, giststate,
1230  stack->buffer,
1231  tuples, ntup,
1232  oldoffnum, NULL,
1233  leftchild,
1234  &splitinfo,
1235  true);
1236 
1237  /*
1238  * Before recursing up in case the page was split, release locks on the
1239  * child pages. We don't need to keep them locked when updating the
1240  * parent.
1241  */
1244  if (BufferIsValid(leftchild) && unlockleftchild)
1246 
1247  /*
1248  * If we had to split, insert/update the downlinks in the parent. If the
1249  * caller requested us to release the lock on stack->buffer, tell
1250  * gistfinishsplit() to do that as soon as it's safe to do so. If we
1251  * didn't have to split, release it ourselves.
1252  */
1253  if (splitinfo)
1254  gistfinishsplit(state, stack, giststate, splitinfo, unlockbuf);
1255  else if (unlockbuf)
1256  LockBuffer(stack->buffer, GIST_UNLOCK);
1257 
1258  return is_split;
1259 }
#define GIST_UNLOCK
Definition: gist_private.h:45
static void gistfinishsplit(GISTInsertState *state, GISTInsertStack *stack, GISTSTATE *giststate, List *splitinfo, bool releasebuf)
Definition: gist.c:1271
void CheckForSerializableConflictIn(Relation relation, HeapTuple tuple, Buffer buffer)
Definition: predicate.c:4280
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
bool gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate, Buffer buffer, IndexTuple *itup, int ntup, OffsetNumber oldoffnum, BlockNumber *newblkno, Buffer leftchildbuf, List **splitinfo, bool markfollowright)
Definition: gist.c:215
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define rightchild(x)
Definition: fsmpage.c:30
#define leftchild(x)
Definition: fsmpage.c:29
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
Definition: pg_list.h:45

◆ gistplacetopage()

bool gistplacetopage ( Relation  rel,
Size  freespace,
GISTSTATE giststate,
Buffer  buffer,
IndexTuple itup,
int  ntup,
OffsetNumber  oldoffnum,
BlockNumber newblkno,
Buffer  leftchildbuf,
List **  splitinfo,
bool  markfollowright 
)

Definition at line 215 of file gist.c.

References DataPageDeleteStack::blkno, gistxlogPage::blkno, SplitedPageLayout::block, GISTPageSplitInfo::buf, SplitedPageLayout::buffer, buffer, BufferGetBlockNumber(), BufferGetPage, BufferIsValid, GISTPageSplitInfo::downlink, elog, END_CRIT_SECTION, ERROR, F_LEAF, FirstOffsetNumber, GIST_MAX_SPLIT_PAGES, GIST_ROOT_BLKNO, GistClearFollowRight, gistextractpage(), gistfillbuffer(), gistfillitupvec(), GistFollowRight, gistGetFakeLSN(), GISTInitBuffer(), gistjoinvector(), GistMarkFollowRight, gistNewBuffer(), gistnospace(), GistPageGetNSN, GistPageGetOpaque, GistPageHasGarbage, GistPageIsLeaf, GistPageSetNSN, gistSplit(), GistTupleSetValid, gistvacuumpage(), gistXLogSplit(), gistXLogUpdate(), i, IndexTupleSize, InvalidBlockNumber, InvalidOffsetNumber, ItemPointerEquals(), ItemPointerSetBlockNumber, SplitedPageLayout::itup, lappend(), SplitedPageLayout::lenlist, SplitedPageLayout::list, MarkBufferDirty(), memmove, SplitedPageLayout::next, NIL, gistxlogPage::num, OffsetNumberIsValid, SplitedPageLayout::page, PageAddItem, PageGetTempPageCopySpecial(), PageIndexTupleDelete(), PageIndexTupleOverwrite(), PageRestoreTempPage(), PageSetLSN, palloc(), PredicateLockPageSplit(), RelationGetRelationName, RelationNeedsWAL, START_CRIT_SECTION, IndexTupleData::t_tid, UnlockReleaseBuffer(), and XLogEnsureRecordSpace().

Referenced by gistbufferinginserttuples(), and gistinserttuples().

222 {
224  Page page = BufferGetPage(buffer);
225  bool is_leaf = (GistPageIsLeaf(page)) ? true : false;
226  XLogRecPtr recptr;
227  int i;
228  bool is_split;
229 
230  /*
231  * Refuse to modify a page that's incompletely split. This should not
232  * happen because we finish any incomplete splits while we walk down the
233  * tree. However, it's remotely possible that another concurrent inserter
234  * splits a parent page, and errors out before completing the split. We
235  * will just throw an error in that case, and leave any split we had in
236  * progress unfinished too. The next insert that comes along will clean up
237  * the mess.
238  */
239  if (GistFollowRight(page))
240  elog(ERROR, "concurrent GiST page split was incomplete");
241 
242  *splitinfo = NIL;
243 
244  /*
245  * if isupdate, remove old key: This node's key has been modified, either
246  * because a child split occurred or because we needed to adjust our key
247  * for an insert in a child node. Therefore, remove the old version of
248  * this node's key.
249  *
250  * for WAL replay, in the non-split case we handle this by setting up a
251  * one-element todelete array; in the split case, it's handled implicitly
252  * because the tuple vector passed to gistSplit won't include this tuple.
253  */
254  is_split = gistnospace(page, itup, ntup, oldoffnum, freespace);
255 
256  /*
257  * If leaf page is full, try at first to delete dead tuples. And then
258  * check again.
259  */
260  if (is_split && GistPageIsLeaf(page) && GistPageHasGarbage(page))
261  {
262  gistvacuumpage(rel, page, buffer);
263  is_split = gistnospace(page, itup, ntup, oldoffnum, freespace);
264  }
265 
266  if (is_split)
267  {
268  /* no space for insertion */
269  IndexTuple *itvec;
270  int tlen;
271  SplitedPageLayout *dist = NULL,
272  *ptr;
273  BlockNumber oldrlink = InvalidBlockNumber;
274  GistNSN oldnsn = 0;
275  SplitedPageLayout rootpg;
276  bool is_rootsplit;
277  int npage;
278 
279  is_rootsplit = (blkno == GIST_ROOT_BLKNO);
280 
281  /*
282  * Form index tuples vector to split. If we're replacing an old tuple,
283  * remove the old version from the vector.
284  */
285  itvec = gistextractpage(page, &tlen);
286  if (OffsetNumberIsValid(oldoffnum))
287  {
288  /* on inner page we should remove old tuple */
289  int pos = oldoffnum - FirstOffsetNumber;
290 
291  tlen--;
292  if (pos != tlen)
293  memmove(itvec + pos, itvec + pos + 1, sizeof(IndexTuple) * (tlen - pos));
294  }
295  itvec = gistjoinvector(itvec, &tlen, itup, ntup);
296  dist = gistSplit(rel, page, itvec, tlen, giststate);
297 
298  /*
299  * Check that split didn't produce too many pages.
300  */
301  npage = 0;
302  for (ptr = dist; ptr; ptr = ptr->next)
303  npage++;
304  /* in a root split, we'll add one more page to the list below */
305  if (is_rootsplit)
306  npage++;
307  if (npage > GIST_MAX_SPLIT_PAGES)
308  elog(ERROR, "GiST page split into too many halves (%d, maximum %d)",
309  npage, GIST_MAX_SPLIT_PAGES);
310 
311  /*
312  * Set up pages to work with. Allocate new buffers for all but the
313  * leftmost page. The original page becomes the new leftmost page, and
314  * is just replaced with the new contents.
315  *
316  * For a root-split, allocate new buffers for all child pages, the
317  * original page is overwritten with new root page containing
318  * downlinks to the new child pages.
319  */
320  ptr = dist;
321  if (!is_rootsplit)
322  {
323  /* save old rightlink and NSN */
324  oldrlink = GistPageGetOpaque(page)->rightlink;
325  oldnsn = GistPageGetNSN(page);
326 
327  dist->buffer = buffer;
330 
331  /* clean all flags except F_LEAF */
332  GistPageGetOpaque(dist->page)->flags = (is_leaf) ? F_LEAF : 0;
333 
334  ptr = ptr->next;
335  }
336  for (; ptr; ptr = ptr->next)
337  {
338  /* Allocate new page */
339  ptr->buffer = gistNewBuffer(rel);
340  GISTInitBuffer(ptr->buffer, (is_leaf) ? F_LEAF : 0);
341  ptr->page = BufferGetPage(ptr->buffer);
342  ptr->block.blkno = BufferGetBlockNumber(ptr->buffer);
345  BufferGetBlockNumber(ptr->buffer));
346  }
347 
348  /*
349  * Now that we know which blocks the new pages go to, set up downlink
350  * tuples to point to them.
351  */
352  for (ptr = dist; ptr; ptr = ptr->next)
353  {
354  ItemPointerSetBlockNumber(&(ptr->itup->t_tid), ptr->block.blkno);
355  GistTupleSetValid(ptr->itup);
356  }
357 
358  /*
359  * If this is a root split, we construct the new root page with the
360  * downlinks here directly, instead of requiring the caller to insert
361  * them. Add the new root page to the list along with the child pages.
362  */
363  if (is_rootsplit)
364  {
365  IndexTuple *downlinks;
366  int ndownlinks = 0;
367  int i;
368 
369  rootpg.buffer = buffer;
371  GistPageGetOpaque(rootpg.page)->flags = 0;
372 
373  /* Prepare a vector of all the downlinks */
374  for (ptr = dist; ptr; ptr = ptr->next)
375  ndownlinks++;
376  downlinks = palloc(sizeof(IndexTuple) * ndownlinks);
377  for (i = 0, ptr = dist; ptr; ptr = ptr->next)
378  downlinks[i++] = ptr->itup;
379 
380  rootpg.block.blkno = GIST_ROOT_BLKNO;
381  rootpg.block.num = ndownlinks;
382  rootpg.list = gistfillitupvec(downlinks, ndownlinks,
383  &(rootpg.lenlist));
384  rootpg.itup = NULL;
385 
386  rootpg.next = dist;
387  dist = &rootpg;
388  }
389  else
390  {
391  /* Prepare split-info to be returned to caller */
392  for (ptr = dist; ptr; ptr = ptr->next)
393  {
395 
396  si->buf = ptr->buffer;
397  si->downlink = ptr->itup;
398  *splitinfo = lappend(*splitinfo, si);
399  }
400  }
401 
402  /*
403  * Fill all pages. All the pages are new, ie. freshly allocated empty
404  * pages, or a temporary copy of the old page.
405  */
406  for (ptr = dist; ptr; ptr = ptr->next)
407  {
408  char *data = (char *) (ptr->list);
409 
410  for (i = 0; i < ptr->block.num; i++)
411  {
412  IndexTuple thistup = (IndexTuple) data;
413 
414  if (PageAddItem(ptr->page, (Item) data, IndexTupleSize(thistup), i + FirstOffsetNumber, false, false) == InvalidOffsetNumber)
415  elog(ERROR, "failed to add item to index page in \"%s\"", RelationGetRelationName(rel));
416 
417  /*
418  * If this is the first inserted/updated tuple, let the caller
419  * know which page it landed on.
420  */
421  if (newblkno && ItemPointerEquals(&thistup->t_tid, &(*itup)->t_tid))
422  *newblkno = ptr->block.blkno;
423 
424  data += IndexTupleSize(thistup);
425  }
426 
427  /* Set up rightlinks */
428  if (ptr->next && ptr->block.blkno != GIST_ROOT_BLKNO)
429  GistPageGetOpaque(ptr->page)->rightlink =
430  ptr->next->block.blkno;
431  else
432  GistPageGetOpaque(ptr->page)->rightlink = oldrlink;
433 
434  /*
435  * Mark the all but the right-most page with the follow-right
436  * flag. It will be cleared as soon as the downlink is inserted
437  * into the parent, but this ensures that if we error out before
438  * that, the index is still consistent. (in buffering build mode,
439  * any error will abort the index build anyway, so this is not
440  * needed.)
441  */
442  if (ptr->next && !is_rootsplit && markfollowright)
443  GistMarkFollowRight(ptr->page);
444  else
445  GistClearFollowRight(ptr->page);
446 
447  /*
448  * Copy the NSN of the original page to all pages. The
449  * F_FOLLOW_RIGHT flags ensure that scans will follow the
450  * rightlinks until the downlinks are inserted.
451  */
452  GistPageSetNSN(ptr->page, oldnsn);
453  }
454 
455  /*
456  * gistXLogSplit() needs to WAL log a lot of pages, prepare WAL
457  * insertion for that. NB: The number of pages and data segments
458  * specified here must match the calculations in gistXLogSplit()!
459  */
460  if (RelationNeedsWAL(rel))
461  XLogEnsureRecordSpace(npage, 1 + npage * 2);
462 
464 
465  /*
466  * Must mark buffers dirty before XLogInsert, even though we'll still
467  * be changing their opaque fields below.
468  */
469  for (ptr = dist; ptr; ptr = ptr->next)
470  MarkBufferDirty(ptr->buffer);
471  if (BufferIsValid(leftchildbuf))
472  MarkBufferDirty(leftchildbuf);
473 
474  /*
475  * The first page in the chain was a temporary working copy meant to
476  * replace the old page. Copy it over the old page.
477  */
479  dist->page = BufferGetPage(dist->buffer);
480 
481  /* Write the WAL record */
482  if (RelationNeedsWAL(rel))
483  recptr = gistXLogSplit(is_leaf,
484  dist, oldrlink, oldnsn, leftchildbuf,
485  markfollowright);
486  else
487  recptr = gistGetFakeLSN(rel);
488 
489  for (ptr = dist; ptr; ptr = ptr->next)
490  {
491  PageSetLSN(ptr->page, recptr);
492  }
493 
494  /*
495  * Return the new child buffers to the caller.
496  *
497  * If this was a root split, we've already inserted the downlink
498  * pointers, in the form of a new root page. Therefore we can release
499  * all the new buffers, and keep just the root page locked.
500  */
501  if (is_rootsplit)
502  {
503  for (ptr = dist->next; ptr; ptr = ptr->next)
504  UnlockReleaseBuffer(ptr->buffer);
505  }
506  }
507  else
508  {
509  /*
510  * Enough space. We always get here if ntup==0.
511  */
513 
514  /*
515  * Delete old tuple if any, then insert new tuple(s) if any. If
516  * possible, use the fast path of PageIndexTupleOverwrite.
517  */
518  if (OffsetNumberIsValid(oldoffnum))
519  {
520  if (ntup == 1)
521  {
522  /* One-for-one replacement, so use PageIndexTupleOverwrite */
523  if (!PageIndexTupleOverwrite(page, oldoffnum, (Item) *itup,
524  IndexTupleSize(*itup)))
525  elog(ERROR, "failed to add item to index page in \"%s\"",
527  }
528  else
529  {
530  /* Delete old, then append new tuple(s) to page */
531  PageIndexTupleDelete(page, oldoffnum);
532  gistfillbuffer(page, itup, ntup, InvalidOffsetNumber);
533  }
534  }
535  else
536  {
537  /* Just append new tuples at the end of the page */
538  gistfillbuffer(page, itup, ntup, InvalidOffsetNumber);
539  }
540 
542 
543  if (BufferIsValid(leftchildbuf))
544  MarkBufferDirty(leftchildbuf);
545 
546  if (RelationNeedsWAL(rel))
547  {
548  OffsetNumber ndeloffs = 0,
549  deloffs[1];
550 
551  if (OffsetNumberIsValid(oldoffnum))
552  {
553  deloffs[0] = oldoffnum;
554  ndeloffs = 1;
555  }
556 
557  recptr = gistXLogUpdate(buffer,
558  deloffs, ndeloffs, itup, ntup,
559  leftchildbuf);
560 
561  PageSetLSN(page, recptr);
562  }
563  else
564  {
565  recptr = gistGetFakeLSN(rel);
566  PageSetLSN(page, recptr);
567  }
568 
569  if (newblkno)
570  *newblkno = blkno;
571  }
572 
573  /*
574  * If we inserted the downlink for a child page, set NSN and clear
575  * F_FOLLOW_RIGHT flag on the left child, so that concurrent scans know to
576  * follow the rightlink if and only if they looked at the parent page
577  * before we inserted the downlink.
578  *
579  * Note that we do this *after* writing the WAL record. That means that
580  * the possible full page image in the WAL record does not include these
581  * changes, and they must be replayed even if the page is restored from
582  * the full page image. There's a chicken-and-egg problem: if we updated
583  * the child pages first, we wouldn't know the recptr of the WAL record
584  * we're about to write.
585  */
586  if (BufferIsValid(leftchildbuf))
587  {
588  Page leftpg = BufferGetPage(leftchildbuf);
589 
590  GistPageSetNSN(leftpg, recptr);
591  GistClearFollowRight(leftpg);
592 
593  PageSetLSN(leftpg, recptr);
594  }
595 
597 
598  return is_split;
599 }
#define GistFollowRight(page)
Definition: gist.h:147
#define NIL
Definition: pg_list.h:69
#define GistPageGetNSN(page)
Definition: gist.h:151
void PageRestoreTempPage(Page tempPage, Page oldPage)
Definition: bufpage.c:407
BlockNumber blkno
Definition: gist_private.h:182
void PageIndexTupleDelete(Page page, OffsetNumber offnum)
Definition: bufpage.c:723
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1450
ItemPointerData t_tid
Definition: itup.h:37
void gistfillbuffer(Page page, IndexTuple *itup, int len, OffsetNumber off)
Definition: gistutil.c:33
#define END_CRIT_SECTION()
Definition: miscadmin.h:133
Pointer Item
Definition: item.h:17
#define GistPageSetNSN(page, val)
Definition: gist.h:152
#define START_CRIT_SECTION()
Definition: miscadmin.h:131
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
Definition: bufpage.h:412
#define GistPageHasGarbage(page)
Definition: gist.h:143
uint32 BlockNumber
Definition: block.h:31
IndexTupleData * list
Definition: gist_private.h:190
XLogRecPtr gistGetFakeLSN(Relation rel)
Definition: gistutil.c:980
uint16 OffsetNumber
Definition: off.h:24
Page PageGetTempPageCopySpecial(Page page)
Definition: bufpage.c:385
gistxlogPage block
Definition: gist_private.h:189
XLogRecPtr gistXLogSplit(bool page_is_leaf, SplitedPageLayout *dist, BlockNumber origrlink, GistNSN orignsn, Buffer leftchildbuf, bool markfollowright)
Definition: gistxlog.c:393
IndexTuple * gistextractpage(Page page, int *len)
Definition: gistutil.c:94
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
#define ERROR
Definition: elog.h:43
#define GIST_MAX_SPLIT_PAGES
Definition: gist_private.h:40
IndexTuple downlink
Definition: gist_private.h:398
bool PageIndexTupleOverwrite(Page page, OffsetNumber offnum, Item newtup, Size newsize)
Definition: bufpage.c:1062
#define memmove(d, s, c)
Definition: c.h:1135
#define FirstOffsetNumber
Definition: off.h:27
IndexTupleData * IndexTuple
Definition: itup.h:53
bool gistnospace(Page page, IndexTuple *itvec, int len, OffsetNumber todelete, Size freespace)
Definition: gistutil.c:58
#define RelationGetRelationName(relation)
Definition: rel.h:441
struct SplitedPageLayout * next
Definition: gist_private.h:196
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
static void gistvacuumpage(Relation rel, Page page, Buffer buffer)
Definition: gist.c:1546
List * lappend(List *list, void *datum)
Definition: list.c:128
#define GistPageIsLeaf(page)
Definition: gist.h:132
#define GistTupleSetValid(itup)
Definition: gist_private.h:276
#define GistClearFollowRight(page)
Definition: gist.h:149
IndexTuple * gistjoinvector(IndexTuple *itvec, int *len, IndexTuple *additvec, int addlen)
Definition: gistutil.c:113
SplitedPageLayout * gistSplit(Relation r, Page page, IndexTuple *itup, int len, GISTSTATE *giststate)
Definition: gist.c:1351
#define InvalidOffsetNumber
Definition: off.h:26
XLogRecPtr gistXLogUpdate(Buffer buffer, OffsetNumber *todelete, int ntodelete, IndexTuple *itup, int ituplen, Buffer leftchildbuf)
Definition: gistxlog.c:457
#define GistPageGetOpaque(page)
Definition: gist.h:130
uint64 XLogRecPtr
Definition: xlogdefs.h:21
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
IndexTupleData * gistfillitupvec(IndexTuple *vec, int veclen, int *memlen)
Definition: gistutil.c:126
#define InvalidBlockNumber
Definition: block.h:33
void XLogEnsureRecordSpace(int max_block_id, int ndatas)
Definition: xloginsert.c:146
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
#define ItemPointerSetBlockNumber(pointer, blockNumber)
Definition: itemptr.h:138
#define GistMarkFollowRight(page)
Definition: gist.h:148
#define RelationNeedsWAL(relation)
Definition: rel.h:510
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
XLogRecPtr GistNSN
Definition: gist.h:50
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
void * palloc(Size size)
Definition: mcxt.c:924
#define F_LEAF
Definition: gist.h:42
int i
#define GIST_ROOT_BLKNO
Definition: gist_private.h:249
#define OffsetNumberIsValid(offsetNumber)
Definition: off.h:40
void GISTInitBuffer(Buffer b, uint32 f)
Definition: gistutil.c:721
#define elog
Definition: elog.h:219
#define PageSetLSN(page, lsn)
Definition: bufpage.h:364
Buffer gistNewBuffer(Relation r)
Definition: gistutil.c:782
void PredicateLockPageSplit(Relation relation, BlockNumber oldblkno, BlockNumber newblkno)
Definition: predicate.c:3065
Pointer Page
Definition: bufpage.h:74
#define IndexTupleSize(itup)
Definition: itup.h:71

◆ gistSplit()

SplitedPageLayout* gistSplit ( Relation  r,
Page  page,
IndexTuple itup,
int  len,
GISTSTATE giststate 
)

Definition at line 1351 of file gist.c.

References Assert, SplitedPageLayout::block, check_stack_depth(), ereport, errcode(), errmsg(), ERROR, gistfillitupvec(), gistfitpage(), gistFormTuple(), GiSTPageSize, gistSplit(), gistSplitByKey(), i, IndexTupleSize, SplitedPageLayout::itup, SplitedPageLayout::lenlist, SplitedPageLayout::list, tupleDesc::natts, SplitedPageLayout::next, gistxlogPage::num, palloc(), RelationGetRelationName, ROTATEDIST, GistSplitVector::spl_lattr, GIST_SPLITVEC::spl_left, GistSplitVector::spl_lisnull, GIST_SPLITVEC::spl_nleft, GIST_SPLITVEC::spl_nright, GistSplitVector::spl_rattr, GIST_SPLITVEC::spl_right, GistSplitVector::spl_risnull, GistSplitVector::splitVector, and GISTSTATE::tupdesc.

Referenced by gistplacetopage(), and gistSplit().

1356 {
1357  IndexTuple *lvectup,
1358  *rvectup;
1359  GistSplitVector v;
1360  int i;
1361  SplitedPageLayout *res = NULL;
1362 
1363  /* this should never recurse very deeply, but better safe than sorry */
1365 
1366  /* there's no point in splitting an empty page */
1367  Assert(len > 0);
1368 
1369  /*
1370  * If a single tuple doesn't fit on a page, no amount of splitting will
1371  * help.
1372  */
1373  if (len == 1)
1374  ereport(ERROR,
1375  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1376  errmsg("index row size %zu exceeds maximum %zu for index \"%s\"",
1377  IndexTupleSize(itup[0]), GiSTPageSize,
1379 
1380  memset(v.spl_lisnull, true, sizeof(bool) * giststate->tupdesc->natts);
1381  memset(v.spl_risnull, true, sizeof(bool) * giststate->tupdesc->natts);
1382  gistSplitByKey(r, page, itup, len, giststate, &v, 0);
1383 
1384  /* form left and right vector */
1385  lvectup = (IndexTuple *) palloc(sizeof(IndexTuple) * (len + 1));
1386  rvectup = (IndexTuple *) palloc(sizeof(IndexTuple) * (len + 1));
1387 
1388  for (i = 0; i < v.splitVector.spl_nleft; i++)
1389  lvectup[i] = itup[v.splitVector.spl_left[i] - 1];
1390 
1391  for (i = 0; i < v.splitVector.spl_nright; i++)
1392  rvectup[i] = itup[v.splitVector.spl_right[i] - 1];
1393 
1394  /* finalize splitting (may need another split) */
1395  if (!gistfitpage(rvectup, v.splitVector.spl_nright))
1396  {
1397  res = gistSplit(r, page, rvectup, v.splitVector.spl_nright, giststate);
1398  }
1399  else
1400  {
1401  ROTATEDIST(res);
1402  res->block.num = v.splitVector.spl_nright;
1403  res->list = gistfillitupvec(rvectup, v.splitVector.spl_nright, &(res->lenlist));
1404  res->itup = gistFormTuple(giststate, r, v.spl_rattr, v.spl_risnull, false);
1405  }
1406 
1407  if (!gistfitpage(lvectup, v.splitVector.spl_nleft))
1408  {
1409  SplitedPageLayout *resptr,
1410  *subres;
1411 
1412  resptr = subres = gistSplit(r, page, lvectup, v.splitVector.spl_nleft, giststate);
1413 
1414  /* install on list's tail */
1415  while (resptr->next)
1416  resptr = resptr->next;
1417 
1418  resptr->next = res;
1419  res = subres;
1420  }
1421  else
1422  {
1423  ROTATEDIST(res);
1424  res->block.num = v.splitVector.spl_nleft;
1425  res->list = gistfillitupvec(lvectup, v.splitVector.spl_nleft, &(res->lenlist));
1426  res->itup = gistFormTuple(giststate, r, v.spl_lattr, v.spl_lisnull, false);
1427  }
1428 
1429  return res;
1430 }
TupleDesc tupdesc
Definition: gist_private.h:81
Datum spl_lattr[INDEX_MAX_KEYS]
Definition: gist_private.h:228
OffsetNumber * spl_left
Definition: gist.h:105
GIST_SPLITVEC splitVector
Definition: gist_private.h:226
int errcode(int sqlerrcode)
Definition: elog.c:575
int spl_nleft
Definition: gist.h:106
IndexTupleData * list
Definition: gist_private.h:190
void gistSplitByKey(Relation r, Page page, IndexTuple *itup, int len, GISTSTATE *giststate, GistSplitVector *v, int attno)
Definition: gistsplit.c:623
Datum spl_rattr[INDEX_MAX_KEYS]
Definition: gist_private.h:232
int natts
Definition: tupdesc.h:82
gistxlogPage block
Definition: gist_private.h:189
#define ERROR
Definition: elog.h:43
int spl_nright
Definition: gist.h:111
void check_stack_depth(void)
Definition: postgres.c:3159
#define RelationGetRelationName(relation)
Definition: rel.h:441
struct SplitedPageLayout * next
Definition: gist_private.h:196
#define ereport(elevel, rest)
Definition: elog.h:122
#define GiSTPageSize
Definition: gist_private.h:432
#define ROTATEDIST(d)
Definition: gist.c:44
SplitedPageLayout * gistSplit(Relation r, Page page, IndexTuple *itup, int len, GISTSTATE *giststate)
Definition: gist.c:1351
bool gistfitpage(IndexTuple *itvec, int len)
Definition: gistutil.c:78
#define Assert(condition)
Definition: c.h:699
IndexTupleData * gistfillitupvec(IndexTuple *vec, int veclen, int *memlen)
Definition: gistutil.c:126
OffsetNumber * spl_right
Definition: gist.h:110
bool spl_risnull[INDEX_MAX_KEYS]
Definition: gist_private.h:234
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
IndexTuple gistFormTuple(GISTSTATE *giststate, Relation r, Datum attdata[], bool isnull[], bool isleaf)
Definition: gistutil.c:572
bool spl_lisnull[INDEX_MAX_KEYS]
Definition: gist_private.h:230
#define IndexTupleSize(itup)
Definition: itup.h:71

◆ gistvacuumpage()

static void gistvacuumpage ( Relation  rel,
Page  page,
Buffer  buffer 
)
static

Definition at line 1546 of file gist.c.

References Assert, END_CRIT_SECTION, FirstOffsetNumber, GistClearPageHasGarbage, gistGetFakeLSN(), GistPageIsLeaf, gistXLogUpdate(), InvalidBuffer, ItemIdIsDead, MarkBufferDirty(), MaxIndexTuplesPerPage, OffsetNumberNext, PageGetItemId, PageGetMaxOffsetNumber, PageIndexMultiDelete(), PageSetLSN, RelationNeedsWAL, and START_CRIT_SECTION.

Referenced by gistplacetopage().

1547 {
1549  int ndeletable = 0;
1550  OffsetNumber offnum,
1551  maxoff;
1552 
1553  Assert(GistPageIsLeaf(page));
1554 
1555  /*
1556  * Scan over all items to see which ones need to be deleted according to
1557  * LP_DEAD flags.
1558  */
1559  maxoff = PageGetMaxOffsetNumber(page);
1560  for (offnum = FirstOffsetNumber;
1561  offnum <= maxoff;
1562  offnum = OffsetNumberNext(offnum))
1563  {
1564  ItemId itemId = PageGetItemId(page, offnum);
1565 
1566  if (ItemIdIsDead(itemId))
1567  deletable[ndeletable++] = offnum;
1568  }
1569 
1570  if (ndeletable > 0)
1571  {
1573 
1574  PageIndexMultiDelete(page, deletable, ndeletable);
1575 
1576  /*
1577  * Mark the page as not containing any LP_DEAD items. This is not
1578  * certainly true (there might be some that have recently been marked,
1579  * but weren't included in our target-item list), but it will almost
1580  * always be true and it doesn't seem worth an additional page scan to
1581  * check it. Remember that F_HAS_GARBAGE is only a hint anyway.
1582  */
1584 
1586 
1587  /* XLOG stuff */
1588  if (RelationNeedsWAL(rel))
1589  {
1590  XLogRecPtr recptr;
1591 
1592  recptr = gistXLogUpdate(buffer,
1593  deletable, ndeletable,
1594  NULL, 0, InvalidBuffer);
1595 
1596  PageSetLSN(page, recptr);
1597  }
1598  else
1599  PageSetLSN(page, gistGetFakeLSN(rel));
1600 
1601  END_CRIT_SECTION();
1602  }
1603 
1604  /*
1605  * Note: if we didn't find any LP_DEAD items, then the page's
1606  * F_HAS_GARBAGE hint bit is falsely set. We do not bother expending a
1607  * separate write to clear it, however. We will clear it when we split
1608  * the page.
1609  */
1610 }
#define GistClearPageHasGarbage(page)
Definition: gist.h:145
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1450
#define END_CRIT_SECTION()
Definition: miscadmin.h:133
#define InvalidBuffer
Definition: buf.h:25
#define START_CRIT_SECTION()
Definition: miscadmin.h:131
#define ItemIdIsDead(itemId)
Definition: itemid.h:112
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:353
XLogRecPtr gistGetFakeLSN(Relation rel)
Definition: gistutil.c:980
uint16 OffsetNumber
Definition: off.h:24
#define FirstOffsetNumber
Definition: off.h:27
#define GistPageIsLeaf(page)
Definition: gist.h:132
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:231
XLogRecPtr gistXLogUpdate(Buffer buffer, OffsetNumber *todelete, int ntodelete, IndexTuple *itup, int ituplen, Buffer leftchildbuf)
Definition: gistxlog.c:457
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:699
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
void PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
Definition: bufpage.c:832
#define OffsetNumberNext(offsetNumber)
Definition: off.h:53
#define RelationNeedsWAL(relation)
Definition: rel.h:510
#define MaxIndexTuplesPerPage
Definition: itup.h:145
#define PageSetLSN(page, lsn)
Definition: bufpage.h:364

◆ initGISTstate()

GISTSTATE* initGISTstate ( Relation  index)

Definition at line 1436 of file gist.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, GISTSTATE::compressFn, GISTSTATE::consistentFn, CurrentMemoryContext, GISTSTATE::decompressFn, GISTSTATE::distanceFn, elog, GISTSTATE::equalFn, ERROR, GISTSTATE::fetchFn, fmgr_info_copy(), FmgrInfo::fn_oid, GIST_COMPRESS_PROC, GIST_CONSISTENT_PROC, GIST_DECOMPRESS_PROC, GIST_DISTANCE_PROC, GIST_EQUAL_PROC, GIST_FETCH_PROC, GIST_PENALTY_PROC, GIST_PICKSPLIT_PROC, GIST_UNION_PROC, i, index_getprocid(), index_getprocinfo(), INDEX_MAX_KEYS, InvalidOid, MemoryContextSwitchTo(), tupleDesc::natts, OidIsValid, palloc(), GISTSTATE::penaltyFn, GISTSTATE::picksplitFn, RelationData::rd_att, RelationData::rd_indcollation, GISTSTATE::scanCxt, GISTSTATE::supportCollation, GISTSTATE::tempCxt, GISTSTATE::tupdesc, and GISTSTATE::unionFn.

Referenced by gistbeginscan(), gistbuild(), and gistinsert().

1437 {
1438  GISTSTATE *giststate;
1439  MemoryContext scanCxt;
1440  MemoryContext oldCxt;
1441  int i;
1442 
1443  /* safety check to protect fixed-size arrays in GISTSTATE */
1444  if (index->rd_att->natts > INDEX_MAX_KEYS)
1445  elog(ERROR, "numberOfAttributes %d > %d",
1446  index->rd_att->natts, INDEX_MAX_KEYS);
1447 
1448  /* Create the memory context that will hold the GISTSTATE */
1450  "GiST scan context",
1452  oldCxt = MemoryContextSwitchTo(scanCxt);
1453 
1454  /* Create and fill in the GISTSTATE */
1455  giststate = (GISTSTATE *) palloc(sizeof(GISTSTATE));
1456 
1457  giststate->scanCxt = scanCxt;
1458  giststate->tempCxt = scanCxt; /* caller must change this if needed */
1459  giststate->tupdesc = index->rd_att;
1460 
1461  for (i = 0; i < index->rd_att->natts; i++)
1462  {
1463  fmgr_info_copy(&(giststate->consistentFn[i]),
1464  index_getprocinfo(index, i + 1, GIST_CONSISTENT_PROC),
1465  scanCxt);
1466  fmgr_info_copy(&(giststate->unionFn[i]),
1467  index_getprocinfo(index, i + 1, GIST_UNION_PROC),
1468  scanCxt);
1469 
1470  /* opclasses are not required to provide a Compress method */
1471  if (OidIsValid(index_getprocid(index, i + 1, GIST_COMPRESS_PROC)))
1472  fmgr_info_copy(&(giststate->compressFn[i]),
1473  index_getprocinfo(index, i + 1, GIST_COMPRESS_PROC),
1474  scanCxt);
1475  else
1476  giststate->compressFn[i].fn_oid = InvalidOid;
1477 
1478  /* opclasses are not required to provide a Decompress method */
1479  if (OidIsValid(index_getprocid(index, i + 1, GIST_DECOMPRESS_PROC)))
1480  fmgr_info_copy(&(giststate->decompressFn[i]),
1481  index_getprocinfo(index, i + 1, GIST_DECOMPRESS_PROC),
1482  scanCxt);
1483  else
1484  giststate->decompressFn[i].fn_oid = InvalidOid;
1485 
1486  fmgr_info_copy(&(giststate->penaltyFn[i]),
1487  index_getprocinfo(index, i + 1, GIST_PENALTY_PROC),
1488  scanCxt);
1489  fmgr_info_copy(&(giststate->picksplitFn[i]),
1490  index_getprocinfo(index, i + 1, GIST_PICKSPLIT_PROC),
1491  scanCxt);
1492  fmgr_info_copy(&(giststate->equalFn[i]),
1493  index_getprocinfo(index, i + 1, GIST_EQUAL_PROC),
1494  scanCxt);
1495 
1496  /* opclasses are not required to provide a Distance method */
1497  if (OidIsValid(index_getprocid(index, i + 1, GIST_DISTANCE_PROC)))
1498  fmgr_info_copy(&(giststate->distanceFn[i]),
1499  index_getprocinfo(index, i + 1, GIST_DISTANCE_PROC),
1500  scanCxt);
1501  else
1502  giststate->distanceFn[i].fn_oid = InvalidOid;
1503 
1504  /* opclasses are not required to provide a Fetch method */
1505  if (OidIsValid(index_getprocid(index, i + 1, GIST_FETCH_PROC)))
1506  fmgr_info_copy(&(giststate->fetchFn[i]),
1507  index_getprocinfo(index, i + 1, GIST_FETCH_PROC),
1508  scanCxt);
1509  else
1510  giststate->fetchFn[i].fn_oid = InvalidOid;
1511 
1512  /*
1513  * If the index column has a specified collation, we should honor that
1514  * while doing comparisons. However, we may have a collatable storage
1515  * type for a noncollatable indexed data type. If there's no index
1516  * collation then specify default collation in case the support
1517  * functions need collation. This is harmless if the support
1518  * functions don't care about collation, so we just do it
1519  * unconditionally. (We could alternatively call get_typcollation,
1520  * but that seems like expensive overkill --- there aren't going to be
1521  * any cases where a GiST storage type has a nondefault collation.)
1522  */
1523  if (OidIsValid(index->rd_indcollation[i]))
1524  giststate->supportCollation[i] = index->rd_indcollation[i];
1525  else
1526  giststate->supportCollation[i] = DEFAULT_COLLATION_OID;
1527  }
1528 
1529  MemoryContextSwitchTo(oldCxt);
1530 
1531  return giststate;
1532 }
TupleDesc tupdesc
Definition: gist_private.h:81
#define GIST_FETCH_PROC
Definition: gist.h:36
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:855
FmgrInfo fetchFn[INDEX_MAX_KEYS]
Definition: gist_private.h:93
#define GIST_EQUAL_PROC
Definition: gist.h:34
Oid supportCollation[INDEX_MAX_KEYS]
Definition: gist_private.h:96
FmgrInfo compressFn[INDEX_MAX_KEYS]
Definition: gist_private.h:87
FmgrInfo equalFn[INDEX_MAX_KEYS]
Definition: gist_private.h:91
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define OidIsValid(objectId)
Definition: c.h:605
int natts
Definition: tupdesc.h:82
FmgrInfo consistentFn[INDEX_MAX_KEYS]
Definition: gist_private.h:85
#define GIST_PICKSPLIT_PROC
Definition: gist.h:33
Oid * rd_indcollation
Definition: rel.h:165
#define ERROR
Definition: elog.h:43
#define GIST_COMPRESS_PROC
Definition: gist.h:30
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
Definition: fmgr.c:610
MemoryContext tempCxt
Definition: gist_private.h:79
FmgrInfo picksplitFn[INDEX_MAX_KEYS]
Definition: gist_private.h:90
FmgrInfo penaltyFn[INDEX_MAX_KEYS]
Definition: gist_private.h:89
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
FmgrInfo decompressFn[INDEX_MAX_KEYS]
Definition: gist_private.h:88
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:170
TupleDesc rd_att
Definition: rel.h:85
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
#define GIST_CONSISTENT_PROC
Definition: gist.h:28
#define GIST_UNION_PROC
Definition: gist.h:29
#define INDEX_MAX_KEYS
#define GIST_PENALTY_PROC
Definition: gist.h:32
#define GIST_DISTANCE_PROC
Definition: gist.h:35
FmgrInfo distanceFn[INDEX_MAX_KEYS]
Definition: gist_private.h:92
void * palloc(Size size)
Definition: mcxt.c:924
int i
MemoryContext scanCxt
Definition: gist_private.h:78
#define GIST_DECOMPRESS_PROC
Definition: gist.h:31
#define elog
Definition: elog.h:219
FmgrInfo unionFn[INDEX_MAX_KEYS]
Definition: gist_private.h:86
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:821