summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/statistics/extended_stats.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c
index b0d0c6b205b..8cb469ceed4 100644
--- a/src/backend/statistics/extended_stats.c
+++ b/src/backend/statistics/extended_stats.c
@@ -74,13 +74,15 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
MemoryContext cxt;
MemoryContext oldcxt;
- cxt = AllocSetContextCreate(CurrentMemoryContext, "stats ext",
- ALLOCSET_DEFAULT_SIZES);
- oldcxt = MemoryContextSwitchTo(cxt);
-
pg_stext = heap_open(StatisticExtRelationId, RowExclusiveLock);
stats = fetch_statentries_for_relation(pg_stext, RelationGetRelid(onerel));
+ /* memory context for building each statistics object */
+ cxt = AllocSetContextCreate(CurrentMemoryContext,
+ "stats ext",
+ ALLOCSET_DEFAULT_SIZES);
+ oldcxt = MemoryContextSwitchTo(cxt);
+
foreach(lc, stats)
{
StatExtEntry *stat = (StatExtEntry *) lfirst(lc);
@@ -127,12 +129,17 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
/* store the statistics in the catalog */
statext_store(pg_stext, stat->statOid, ndistinct, dependencies, stats);
- }
- heap_close(pg_stext, RowExclusiveLock);
+ /* free the data used for building this statistics object */
+ MemoryContextReset(cxt);
+ }
MemoryContextSwitchTo(oldcxt);
MemoryContextDelete(cxt);
+
+ list_free(stats);
+
+ heap_close(pg_stext, RowExclusiveLock);
}
/*