@ -32,6 +32,7 @@
typedef struct
typedef struct
{
{
SpGistState spgstate ; /* SPGiST's working state */
SpGistState spgstate ; /* SPGiST's working state */
int64 indtuples ; /* total number of tuples indexed */
MemoryContext tmpCtx ; /* per-tuple temporary context */
MemoryContext tmpCtx ; /* per-tuple temporary context */
} SpGistBuildState ;
} SpGistBuildState ;
@ -59,6 +60,9 @@ spgistBuildCallback(Relation index, HeapTuple htup, Datum *values,
MemoryContextReset ( buildstate - > tmpCtx ) ;
MemoryContextReset ( buildstate - > tmpCtx ) ;
}
}
/* Update total tuple count */
buildstate - > indtuples + = 1 ;
MemoryContextSwitchTo ( oldCtx ) ;
MemoryContextSwitchTo ( oldCtx ) ;
MemoryContextReset ( buildstate - > tmpCtx ) ;
MemoryContextReset ( buildstate - > tmpCtx ) ;
}
}
@ -132,6 +136,7 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
*/
*/
initSpGistState ( & buildstate . spgstate , index ) ;
initSpGistState ( & buildstate . spgstate , index ) ;
buildstate . spgstate . isBuild = true ;
buildstate . spgstate . isBuild = true ;
buildstate . indtuples = 0 ;
buildstate . tmpCtx = AllocSetContextCreate ( CurrentMemoryContext ,
buildstate . tmpCtx = AllocSetContextCreate ( CurrentMemoryContext ,
" SP-GiST build temporary context " ,
" SP-GiST build temporary context " ,
@ -146,7 +151,8 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
SpGistUpdateMetaPage ( index ) ;
SpGistUpdateMetaPage ( index ) ;
result = ( IndexBuildResult * ) palloc0 ( sizeof ( IndexBuildResult ) ) ;
result = ( IndexBuildResult * ) palloc0 ( sizeof ( IndexBuildResult ) ) ;
result - > heap_tuples = result - > index_tuples = reltuples ;
result - > heap_tuples = reltuples ;
result - > index_tuples = buildstate . indtuples ;
return result ;
return result ;
}
}