aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/gin/ginbtree.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2013-11-06 10:31:38 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2013-11-06 10:32:09 +0200
commitecaa4708e5dde5e9f72cdb066780acb4b12ee0ec (patch)
tree71da25393149a4b62a385d822f010d75891f9cd4 /src/backend/access/gin/ginbtree.c
parent920c8261d58c10de7e68d99c8dd21a9650928d59 (diff)
downloadpostgresql-ecaa4708e5dde5e9f72cdb066780acb4b12ee0ec.tar.gz
postgresql-ecaa4708e5dde5e9f72cdb066780acb4b12ee0ec.zip
Misc GIN refactoring.
Merge the isEnoughSpace and placeToPage functions in the b-tree interface into one function that tries to put a tuple on page, and returns false if it doesn't fit. Move createPostingTree function to gindatapage.c, and change its contract so that it can be passed more items than fit on the root page. It's in a better position than the callers to know how many items fit. Move ginMergeItemPointers out of gindatapage.c, into a separate file. These changes make no difference now, but reduce the footprint of Alexander Korotkov's upcoming patch to pack item pointers more tightly.
Diffstat (limited to 'src/backend/access/gin/ginbtree.c')
-rw-r--r--src/backend/access/gin/ginbtree.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/backend/access/gin/ginbtree.c b/src/backend/access/gin/ginbtree.c
index 2a6be4b1a99..f032faa22ec 100644
--- a/src/backend/access/gin/ginbtree.c
+++ b/src/backend/access/gin/ginbtree.c
@@ -264,7 +264,7 @@ ginFindParents(GinBtree btree, GinBtreeStack *stack,
* Insert value (stored in GinBtree) to tree described by stack
*
* During an index build, buildStats is non-null and the counters
- * it contains should be incremented as needed.
+ * it contains are incremented as needed.
*
* NB: the passed-in stack is freed, as though by freeGinBtreeStack.
*/
@@ -290,15 +290,15 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats)
{
XLogRecData *rdata;
BlockNumber savedRightLink;
+ bool fit;
page = BufferGetPage(stack->buffer);
savedRightLink = GinPageGetOpaque(page)->rightlink;
- if (btree->isEnoughSpace(btree, stack->buffer, stack->off))
+ START_CRIT_SECTION();
+ fit = btree->placeToPage(btree, stack->buffer, stack->off, &rdata);
+ if (fit)
{
- START_CRIT_SECTION();
- btree->placeToPage(btree, stack->buffer, stack->off, &rdata);
-
MarkBufferDirty(stack->buffer);
if (RelationNeedsWAL(btree->index))
@@ -318,12 +318,17 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats)
}
else
{
- Buffer rbuffer = GinNewBuffer(btree->index);
+ /* Didn't fit, have to split */
+ Buffer rbuffer;
Page newlpage;
+ END_CRIT_SECTION();
+
+ rbuffer = GinNewBuffer(btree->index);
+
/*
- * newlpage is a pointer to memory page, it doesn't associate with
- * buffer, stack->buffer should be untouched
+ * newlpage is a pointer to memory page, it is not associated with
+ * a buffer. stack->buffer is not touched yet.
*/
newlpage = btree->splitPage(btree, stack->buffer, rbuffer, stack->off, &rdata);