}
}
+ btree->prepareDownlink(btree, stack->buffer);
btree->isDelete = FALSE;
/* search parent to lock */
rdata[1].len = MAXALIGN(maxoff * sizeofitem);
rdata[1].next = NULL;
- /* Prepare a downlink tuple for insertion to the parent */
+ return lpage;
+}
+
+/*
+ * Prepare the state in 'btree' for inserting a downlink for given buffer.
+ */
+static void
+dataPrepareDownlink(GinBtree btree, Buffer lbuf)
+{
+ Page lpage = BufferGetPage(lbuf);
+
PostingItemSetBlockNumber(&(btree->pitem), BufferGetBlockNumber(lbuf));
btree->pitem.key = *GinDataPageGetRightBound(lpage);
- btree->rightblkno = BufferGetBlockNumber(rbuf);
-
- return lpage;
+ btree->rightblkno = GinPageGetOpaque(lpage)->rightlink;
}
/*
btree->placeToPage = dataPlaceToPage;
btree->splitPage = dataSplitPage;
btree->fillRoot = ginDataFillRoot;
+ btree->prepareDownlink = dataPrepareDownlink;
btree->isData = TRUE;
btree->isDelete = FALSE;
Size lsize = 0,
size;
char *ptr;
- IndexTuple itup,
- leftrightmost = NULL;
+ IndexTuple itup;
Page page;
Page lpage = PageGetTempPageCopy(BufferGetPage(lbuf));
Page rpage = BufferGetPage(rbuf);
}
else
{
- leftrightmost = itup;
lsize += MAXALIGN(IndexTupleSize(itup)) + sizeof(ItemIdData);
}
ptr += MAXALIGN(IndexTupleSize(itup));
}
- btree->entry = GinFormInteriorTuple(leftrightmost, lpage,
- BufferGetBlockNumber(lbuf));
-
- btree->rightblkno = BufferGetBlockNumber(rbuf);
-
data.node = btree->index->rd_node;
data.rootBlkno = InvalidBlockNumber;
data.lblkno = BufferGetBlockNumber(lbuf);
}
/*
- * return newly allocated rightmost tuple
+ * Prepare the state in 'btree' for inserting a downlink for given buffer.
*/
-IndexTuple
-ginPageGetLinkItup(Buffer buf)
+static void
+entryPrepareDownlink(GinBtree btree, Buffer lbuf)
{
- IndexTuple itup,
- nitup;
- Page page = BufferGetPage(buf);
+ Page lpage = BufferGetPage(lbuf);
+ IndexTuple itup;
- itup = getRightMostTuple(page);
- nitup = GinFormInteriorTuple(itup, page, BufferGetBlockNumber(buf));
+ itup = getRightMostTuple(lpage);
- return nitup;
+ btree->entry = GinFormInteriorTuple(itup,
+ lpage,
+ BufferGetBlockNumber(lbuf));
+ btree->rightblkno = GinPageGetOpaque(lpage)->rightlink;
}
/*
void
ginEntryFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf)
{
- Page page;
+ Page page = BufferGetPage(root);
+ Page lpage = BufferGetPage(lbuf);
+ Page rpage = BufferGetPage(rbuf);
IndexTuple itup;
- page = BufferGetPage(root);
-
- itup = ginPageGetLinkItup(lbuf);
+ itup = GinFormInteriorTuple(getRightMostTuple(lpage),
+ lpage,
+ BufferGetBlockNumber(lbuf));
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, false, false) == InvalidOffsetNumber)
elog(ERROR, "failed to add item to index root page");
pfree(itup);
- itup = ginPageGetLinkItup(rbuf);
+ itup = GinFormInteriorTuple(getRightMostTuple(rpage),
+ rpage,
+ BufferGetBlockNumber(rbuf));
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, false, false) == InvalidOffsetNumber)
elog(ERROR, "failed to add item to index root page");
pfree(itup);
btree->placeToPage = entryPlaceToPage;
btree->splitPage = entrySplitPage;
btree->fillRoot = ginEntryFillRoot;
+ btree->prepareDownlink = entryPrepareDownlink;
btree->isData = FALSE;
btree->fullScan = FALSE;
ginPrepareEntryScan(&btree,
InvalidOffsetNumber, (Datum) 0, GIN_CAT_NULL_KEY,
&ginstate);
- btree.entry = ginPageGetLinkItup(buffer);
}
else
{
- Page page = BufferGetPage(buffer);
-
ginPrepareDataScan(&btree, reln);
-
- PostingItemSetBlockNumber(&(btree.pitem), split->leftBlkno);
- if (GinPageIsLeaf(page))
- btree.pitem.key = *GinDataPageGetItemPointer(page,
- GinPageGetOpaque(page)->maxoff);
- else
- btree.pitem.key = GinDataPageGetPostingItem(page,
- GinPageGetOpaque(page)->maxoff)->key;
}
- btree.rightblkno = split->rightBlkno;
-
stack.blkno = split->leftBlkno;
stack.buffer = buffer;
stack.off = InvalidOffsetNumber;
stack.parent = NULL;
ginFindParents(&btree, &stack, split->rootBlkno);
+
+ btree.prepareDownlink(&btree, buffer);
ginInsertValue(&btree, stack.parent, NULL);
FreeFakeRelcacheEntry(reln);
OffsetNumber (*findChildPtr) (GinBtree, Page, BlockNumber, OffsetNumber);
bool (*placeToPage) (GinBtree, Buffer, OffsetNumber, XLogRecData **);
Page (*splitPage) (GinBtree, Buffer, Buffer, OffsetNumber, XLogRecData **);
+ void (*prepareDownlink) (GinBtree, Buffer);
void (*fillRoot) (GinBtree, Buffer, Buffer, Buffer);
bool isData;
Datum key, GinNullCategory category,
GinState *ginstate);
extern void ginEntryFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf);
-extern IndexTuple ginPageGetLinkItup(Buffer buf);
/* gindatapage.c */
extern BlockNumber createPostingTree(Relation index,