aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/gin/gininsert.c
diff options
context:
space:
mode:
authorTeodor Sigaev <teodor@sigaev.ru>2006-07-11 16:55:34 +0000
committerTeodor Sigaev <teodor@sigaev.ru>2006-07-11 16:55:34 +0000
commit234163649e4eb7eb348e2a00192fec4a30cf0e33 (patch)
tree2cc5c929e9c62924addac67ae7b981d98633c538 /src/backend/access/gin/gininsert.c
parentfa601357fb6c907a8e339b8a2ea7b4a8e2acf212 (diff)
downloadpostgresql-234163649e4eb7eb348e2a00192fec4a30cf0e33.tar.gz
postgresql-234163649e4eb7eb348e2a00192fec4a30cf0e33.zip
GIN improvements
- Replace sorted array of entries in maintenance_work_mem to binary tree, this should improve create performance. - More precisely calculate allocated memory, eliminate leaks with user-defined extractValue() - Improve wordings in tsearch2
Diffstat (limited to 'src/backend/access/gin/gininsert.c')
-rw-r--r--src/backend/access/gin/gininsert.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index a4416a94cb3..b67bf6e8218 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.2 2006/05/10 23:18:38 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.3 2006/07/11 16:55:34 teodor Exp $
*-------------------------------------------------------------------------
*/
@@ -26,6 +26,7 @@ typedef struct {
GinState ginstate;
double indtuples;
MemoryContext tmpCtx;
+ MemoryContext funcCtx;
BuildAccumulator accum;
} GinBuildState;
@@ -189,19 +190,22 @@ ginEntryInsert( Relation index, GinState *ginstate, Datum value, ItemPointerData
* Function isnt use during normal insert
*/
static uint32
-ginHeapTupleBulkInsert(BuildAccumulator *accum, Datum value, ItemPointer heapptr) {
+ginHeapTupleBulkInsert(GinBuildState *buildstate, Datum value, ItemPointer heapptr) {
Datum *entries;
uint32 nentries;
+ MemoryContext oldCtx;
- entries = extractEntriesSU( accum->ginstate, value, &nentries);
+ oldCtx = MemoryContextSwitchTo(buildstate->funcCtx);
+ entries = extractEntriesSU( buildstate->accum.ginstate, value, &nentries);
+ MemoryContextSwitchTo(oldCtx);
if ( nentries==0 )
/* nothing to insert */
return 0;
- ginInsertRecordBA( accum, heapptr, entries, nentries);
+ ginInsertRecordBA( &buildstate->accum, heapptr, entries, nentries);
- pfree( entries );
+ MemoryContextReset(buildstate->funcCtx);
return nentries;
}
@@ -218,7 +222,7 @@ ginBuildCallback(Relation index, HeapTuple htup, Datum *values,
oldCtx = MemoryContextSwitchTo(buildstate->tmpCtx);
- buildstate->indtuples += ginHeapTupleBulkInsert(&buildstate->accum, *values, &htup->t_self);
+ buildstate->indtuples += ginHeapTupleBulkInsert(buildstate, *values, &htup->t_self);
/* we use only half maintenance_work_mem, because there is some leaks
during insertion and extract values */
@@ -297,6 +301,12 @@ ginbuild(PG_FUNCTION_ARGS) {
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
+ buildstate.funcCtx = AllocSetContextCreate(buildstate.tmpCtx,
+ "Gin build temporary context for user-defined function",
+ ALLOCSET_DEFAULT_MINSIZE,
+ ALLOCSET_DEFAULT_INITSIZE,
+ ALLOCSET_DEFAULT_MAXSIZE);
+
buildstate.accum.ginstate = &buildstate.ginstate;
ginInitBA( &buildstate.accum );