*** pgsql/src/backend/access/gin/gininsert.c 2009/01/01 17:23:34 1.18 --- pgsql/src/backend/access/gin/gininsert.c 2009/03/24 20:17:11 1.19 *************** *** 8,14 **** * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.17 2008/11/19 10:34:50 heikki Exp $ *------------------------------------------------------------------------- */ --- 8,14 ---- * 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 $ *------------------------------------------------------------------------- */ *************** addItemPointersToTuple(Relation index, G *** 138,146 **** /* * 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) { GinBtreeData btree; GinBtreeStack *stack; --- 138,148 ---- /* * Inserts only one entry to the index, but it can add more than 1 ItemPointer. */ ! void ! ginEntryInsert(Relation index, GinState *ginstate, ! OffsetNumber attnum, Datum value, ! ItemPointerData *items, uint32 nitem, ! bool isBuild) { GinBtreeData btree; GinBtreeStack *stack; *************** ginbuild(PG_FUNCTION_ARGS) *** 273,279 **** IndexBuildResult *result; double reltuples; GinBuildState buildstate; ! Buffer buffer; ItemPointerData *list; Datum entry; uint32 nlist; --- 275,281 ---- IndexBuildResult *result; double reltuples; GinBuildState buildstate; ! Buffer RootBuffer, MetaBuffer; ItemPointerData *list; Datum entry; uint32 nlist; *************** ginbuild(PG_FUNCTION_ARGS) *** 286,296 **** initGinState(&buildstate.ginstate, index); /* initialize the root page */ ! buffer = GinNewBuffer(index); START_CRIT_SECTION(); ! GinInitBuffer(buffer, GIN_LEAF); ! MarkBufferDirty(buffer); if (!index->rd_istemp) { --- 288,304 ---- initGinState(&buildstate.ginstate, index); + /* initialize the meta page */ + MetaBuffer = GinNewBuffer(index); + /* initialize the root page */ ! RootBuffer = GinNewBuffer(index); ! START_CRIT_SECTION(); ! GinInitMetabuffer(MetaBuffer); ! MarkBufferDirty(MetaBuffer); ! GinInitBuffer(RootBuffer, GIN_LEAF); ! MarkBufferDirty(RootBuffer); if (!index->rd_istemp) { *************** ginbuild(PG_FUNCTION_ARGS) *** 303,318 **** rdata.len = sizeof(RelFileNode); rdata.next = NULL; - page = BufferGetPage(buffer); - - recptr = XLogInsert(RM_GIN_ID, XLOG_GIN_CREATE_INDEX, &rdata); PageSetLSN(page, recptr); PageSetTLI(page, ThisTimeLineID); } ! UnlockReleaseBuffer(buffer); END_CRIT_SECTION(); /* build the index */ --- 311,329 ---- rdata.len = sizeof(RelFileNode); rdata.next = NULL; 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(MetaBuffer); ! UnlockReleaseBuffer(RootBuffer); END_CRIT_SECTION(); /* build the index */ *************** gininsert(PG_FUNCTION_ARGS) *** 417,425 **** initGinState(&ginstate, index); ! for(i=0; inatts;i++) ! if ( !isnull[i] ) ! res += ginHeapTupleInsert(index, &ginstate, (OffsetNumber)(i+1), values[i], ht_ctid); MemoryContextSwitchTo(oldCtx); MemoryContextDelete(insertCtx); --- 428,453 ---- initGinState(&ginstate, index); ! if ( GinGetUseFastUpdate(index) ) ! { ! GinTupleCollector collector; ! ! memset(&collector, 0, sizeof(GinTupleCollector)); ! for(i=0; inatts;i++) ! if ( !isnull[i] ) ! res += ginHeapTupleFastCollect(index, &ginstate, &collector, ! (OffsetNumber)(i+1), values[i], ht_ctid); ! ! ginHeapTupleFastInsert(index, &ginstate, &collector); ! } ! else ! { ! for(i=0; inatts;i++) ! if ( !isnull[i] ) ! res += ginHeapTupleInsert(index, &ginstate, ! (OffsetNumber)(i+1), values[i], ht_ctid); ! ! } MemoryContextSwitchTo(oldCtx); MemoryContextDelete(insertCtx);