[Groonga-commit] pgroonga/pgroonga at aec84d3 [master] Reduce memory usage on static index construction

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Mon Nov 14 17:37:11 JST 2016


Kouhei Sutou	2016-11-14 17:37:11 +0900 (Mon, 14 Nov 2016)

  New Revision: aec84d36ca063b53c2a3651ed981b51869f83203
  https://github.com/pgroonga/pgroonga/commit/aec84d36ca063b53c2a3651ed981b51869f83203

  Message:
    Reduce memory usage on static index construction

  Modified files:
    src/pgroonga.c

  Modified: src/pgroonga.c (+14 -0)
===================================================================
--- src/pgroonga.c    2016-11-09 17:39:06 +0900 (3c5f70b)
+++ src/pgroonga.c    2016-11-14 17:37:11 +0900 (44431cc)
@@ -42,6 +42,7 @@
 #include <utils/array.h>
 #include <utils/builtins.h>
 #include <utils/lsyscache.h>
+#include <utils/memutils.h>
 #include <utils/selfuncs.h>
 #include <utils/syscache.h>
 #include <utils/timestamp.h>
@@ -84,6 +85,7 @@ typedef struct PGrnBuildStateData
 	double nIndexedTuples;
 	bool needMaxRecordSizeUpdate;
 	uint32_t maxRecordSize;
+	MemoryContext memoryContext;
 } PGrnBuildStateData;
 
 typedef PGrnBuildStateData *PGrnBuildState;
@@ -3561,11 +3563,14 @@ PGrnBuildCallbackRaw(Relation index,
 					 void *state)
 {
 	PGrnBuildState bs = (PGrnBuildState) state;
+	MemoryContext oldMemoryContext;
 	uint32_t recordSize;
 
 	if (!tupleIsAlive)
 		return;
 
+	oldMemoryContext = MemoryContextSwitchTo(bs->memoryContext);
+
 	recordSize = PGrnInsert(index,
 							bs->sourcesTable,
 							bs->sourcesCtidColumn,
@@ -3578,6 +3583,9 @@ PGrnBuildCallbackRaw(Relation index,
 		bs->maxRecordSize = recordSize;
 	}
 	bs->nIndexedTuples++;
+
+	MemoryContextSwitchTo(oldMemoryContext);
+	MemoryContextReset(bs->memoryContext);
 }
 
 #ifdef PGRN_IS_GREENPLUM
@@ -3634,6 +3642,10 @@ pgroonga_build_raw(Relation heap,
 	bs.nIndexedTuples = 0.0;
 	bs.needMaxRecordSizeUpdate = PGrnNeedMaxRecordSizeUpdate(index);
 	bs.maxRecordSize = 0;
+	bs.memoryContext =
+		AllocSetContextCreate(CurrentMemoryContext,
+							  "PGroonga index build temporay context",
+							  ALLOCSET_DEFAULT_SIZES);
 
 	GRN_PTR_INIT(&supplementaryTables, GRN_OBJ_VECTOR, GRN_ID_NIL);
 	GRN_PTR_INIT(&lexicons, GRN_OBJ_VECTOR, GRN_ID_NIL);
@@ -3683,6 +3695,8 @@ pgroonga_build_raw(Relation heap,
 	result->heap_tuples = nHeapTuples;
 	result->index_tuples = bs.nIndexedTuples;
 
+	MemoryContextDelete(bs.memoryContext);
+
 	if (bs.needMaxRecordSizeUpdate)
 	{
 		PGrnUpdateMaxRecordSize(index, bs.maxRecordSize);
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る