Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83772cc

Browse files
committed
Free memory after building each statistics object
Until now, all extended statistics on a given relation were built in thesame memory context, without resetting. Some of the memory was releasedexplicitly, but not all of it - for example memory allocated whiledetoasting values is hard to free. This is how it worked since extendedstatistics were introduced in PostgreSQL 10, but adding support forextended stats on expressions made the issue somewhat worse as itincreases the number of statistics to build.Fixed by adding a memory context which gets reset after building eachstatistics object (all the statistics kinds included in it). Resettingit after building each statistics kind would be even better, but itwould require more invasive changes and copying of results, making itharder to backpatch.Backpatch to PostgreSQL 10, where extended statistics were introduced.Author: Justin PryzbyReported-by: Justin PryzbyReviewed-by: Tomas VondraBackpatch-through: 10Discussion:https://www.postgresql.org/message-id/20210915200928.GP831%40telsasoft.com
1 parentc7aeb77 commit83772cc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

‎src/backend/statistics/extended_stats.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,16 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
125125
if (!natts)
126126
return;
127127

128+
/* the list of stats has to be allocated outside the memory context */
129+
pg_stext=table_open(StatisticExtRelationId,RowExclusiveLock);
130+
statslist=fetch_statentries_for_relation(pg_stext,RelationGetRelid(onerel));
131+
132+
/* memory context for building each statistics object */
128133
cxt=AllocSetContextCreate(CurrentMemoryContext,
129134
"BuildRelationExtStatistics",
130135
ALLOCSET_DEFAULT_SIZES);
131136
oldcxt=MemoryContextSwitchTo(cxt);
132137

133-
pg_stext=table_open(StatisticExtRelationId,RowExclusiveLock);
134-
statslist=fetch_statentries_for_relation(pg_stext,RelationGetRelid(onerel));
135-
136138
/* report this phase */
137139
if (statslist!=NIL)
138140
{
@@ -234,14 +236,16 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
234236
pgstat_progress_update_param(PROGRESS_ANALYZE_EXT_STATS_COMPUTED,
235237
++ext_cnt);
236238

237-
/* free thebuilddata(allocated as a single chunk) */
238-
pfree(data);
239+
/* free the dataused for building this statistics object */
240+
MemoryContextReset(cxt);
239241
}
240242

241-
table_close(pg_stext,RowExclusiveLock);
242-
243243
MemoryContextSwitchTo(oldcxt);
244244
MemoryContextDelete(cxt);
245+
246+
list_free(statslist);
247+
248+
table_close(pg_stext,RowExclusiveLock);
245249
}
246250

247251
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp