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

Commitb564eb0

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 parentf09a81f commitb564eb0

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

‎src/backend/statistics/extended_stats.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
9797
MemoryContextoldcxt;
9898
int64ext_cnt;
9999

100+
pg_stext=table_open(StatisticExtRelationId,RowExclusiveLock);
101+
stats=fetch_statentries_for_relation(pg_stext,RelationGetRelid(onerel));
102+
103+
/* memory context for building each statistics object */
100104
cxt=AllocSetContextCreate(CurrentMemoryContext,
101105
"BuildRelationExtStatistics",
102106
ALLOCSET_DEFAULT_SIZES);
103107
oldcxt=MemoryContextSwitchTo(cxt);
104108

105-
pg_stext=table_open(StatisticExtRelationId,RowExclusiveLock);
106-
stats=fetch_statentries_for_relation(pg_stext,RelationGetRelid(onerel));
107-
108109
/* report this phase */
109110
if (stats!=NIL)
110111
{
@@ -189,12 +190,17 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
189190
/* for reporting progress */
190191
pgstat_progress_update_param(PROGRESS_ANALYZE_EXT_STATS_COMPUTED,
191192
++ext_cnt);
192-
}
193193

194-
table_close(pg_stext,RowExclusiveLock);
194+
/* free the data used for building this statistics object */
195+
MemoryContextReset(cxt);
196+
}
195197

196198
MemoryContextSwitchTo(oldcxt);
197199
MemoryContextDelete(cxt);
200+
201+
list_free(stats);
202+
203+
table_close(pg_stext,RowExclusiveLock);
198204
}
199205

200206
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp