aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/gin/gininsert.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/gin/gininsert.c')
-rw-r--r--src/backend/access/gin/gininsert.c58
1 files changed, 43 insertions, 15 deletions
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 2ab1105423c..d05882cdb94 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.18 2009/01/01 17:23:34 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.19 2009/03/24 20:17:11 tgl Exp $
*-------------------------------------------------------------------------
*/
@@ -138,9 +138,11 @@ addItemPointersToTuple(Relation index, GinState *ginstate, GinBtreeStack *stack,
/*
* Inserts only one entry to the index, but it can add more than 1 ItemPointer.
*/
-static void
-ginEntryInsert(Relation index, GinState *ginstate, OffsetNumber attnum, Datum value,
- ItemPointerData *items, uint32 nitem, bool isBuild)
+void
+ginEntryInsert(Relation index, GinState *ginstate,
+ OffsetNumber attnum, Datum value,
+ ItemPointerData *items, uint32 nitem,
+ bool isBuild)
{
GinBtreeData btree;
GinBtreeStack *stack;
@@ -273,7 +275,7 @@ ginbuild(PG_FUNCTION_ARGS)
IndexBuildResult *result;
double reltuples;
GinBuildState buildstate;
- Buffer buffer;
+ Buffer RootBuffer, MetaBuffer;
ItemPointerData *list;
Datum entry;
uint32 nlist;
@@ -286,11 +288,17 @@ ginbuild(PG_FUNCTION_ARGS)
initGinState(&buildstate.ginstate, index);
+ /* initialize the meta page */
+ MetaBuffer = GinNewBuffer(index);
+
/* initialize the root page */
- buffer = GinNewBuffer(index);
+ RootBuffer = GinNewBuffer(index);
+
START_CRIT_SECTION();
- GinInitBuffer(buffer, GIN_LEAF);
- MarkBufferDirty(buffer);
+ GinInitMetabuffer(MetaBuffer);
+ MarkBufferDirty(MetaBuffer);
+ GinInitBuffer(RootBuffer, GIN_LEAF);
+ MarkBufferDirty(RootBuffer);
if (!index->rd_istemp)
{
@@ -303,16 +311,19 @@ ginbuild(PG_FUNCTION_ARGS)
rdata.len = sizeof(RelFileNode);
rdata.next = NULL;
- page = BufferGetPage(buffer);
-
-
recptr = XLogInsert(RM_GIN_ID, XLOG_GIN_CREATE_INDEX, &rdata);
+
+ page = BufferGetPage(RootBuffer);
PageSetLSN(page, recptr);
PageSetTLI(page, ThisTimeLineID);
+ page = BufferGetPage(MetaBuffer);
+ PageSetLSN(page, recptr);
+ PageSetTLI(page, ThisTimeLineID);
}
- UnlockReleaseBuffer(buffer);
+ UnlockReleaseBuffer(MetaBuffer);
+ UnlockReleaseBuffer(RootBuffer);
END_CRIT_SECTION();
/* build the index */
@@ -417,9 +428,26 @@ gininsert(PG_FUNCTION_ARGS)
initGinState(&ginstate, index);
- for(i=0; i<ginstate.origTupdesc->natts;i++)
- if ( !isnull[i] )
- res += ginHeapTupleInsert(index, &ginstate, (OffsetNumber)(i+1), values[i], ht_ctid);
+ if ( GinGetUseFastUpdate(index) )
+ {
+ GinTupleCollector collector;
+
+ memset(&collector, 0, sizeof(GinTupleCollector));
+ for(i=0; i<ginstate.origTupdesc->natts;i++)
+ if ( !isnull[i] )
+ res += ginHeapTupleFastCollect(index, &ginstate, &collector,
+ (OffsetNumber)(i+1), values[i], ht_ctid);
+
+ ginHeapTupleFastInsert(index, &ginstate, &collector);
+ }
+ else
+ {
+ for(i=0; i<ginstate.origTupdesc->natts;i++)
+ if ( !isnull[i] )
+ res += ginHeapTupleInsert(index, &ginstate,
+ (OffsetNumber)(i+1), values[i], ht_ctid);
+
+ }
MemoryContextSwitchTo(oldCtx);
MemoryContextDelete(insertCtx);