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

Commitb6dd1c6

Browse files
committed
Bugfix. AQOUtilityMemCtx is reset although some allocated data still in use.
Remove the AQOUtilityMemCtx memory context at all. It is used for too smalloperations. I don't buy that such operations can allocate so much memory thatbackend must free memory right after the end of operation to avoid OOM.I guess, prediction, planning and execution memory context set is good enough.
1 parent743524b commitb6dd1c6

File tree

6 files changed

+9
-49
lines changed

6 files changed

+9
-49
lines changed

‎aqo.c‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ MemoryContextAQOTopMemCtx = NULL;
8787
/* Is released at the end of transaction */
8888
MemoryContextAQOCacheMemCtx=NULL;
8989

90-
/* Should be released in-place, just after a huge calculation */
91-
MemoryContextAQOUtilityMemCtx=NULL;
92-
9390
/* Is released at the end of planning */
9491
MemoryContextAQOPredictMemCtx=NULL;
9592

@@ -342,15 +339,7 @@ _PG_init(void)
342339
AQOCacheMemCtx=AllocSetContextCreate(AQOTopMemCtx,
343340
"AQOCacheMemCtx",
344341
ALLOCSET_DEFAULT_SIZES);
345-
/*
346-
* AQOUtilityMemoryContext containe short-lived information which
347-
* is appeared from having got clause, selectivity arrays and relid lists
348-
* while calculating hashes. It clean up inside calculated
349-
* function or immediately after her having completed.
350-
*/
351-
AQOUtilityMemCtx=AllocSetContextCreate(AQOTopMemCtx,
352-
"AQOUtilityMemoryContext",
353-
ALLOCSET_DEFAULT_SIZES);
342+
354343
/*
355344
* AQOPredictMemoryContext save necessary information for making predict of plan nodes
356345
* and clean up in the execution stage of query.

‎aqo.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ extern int njoins;
225225
/* AQO Memory contexts */
226226
externMemoryContextAQOTopMemCtx;
227227
externMemoryContextAQOCacheMemCtx;
228-
externMemoryContextAQOUtilityMemCtx;
229228
externMemoryContextAQOPredictMemCtx;
230229
externMemoryContextAQOLearnMemCtx;
231230

‎hash.c‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,21 @@ get_fss_for_object(List *relsigns, List *clauselist,
212212
intsh=0,
213213
old_sh;
214214
intfss_hash;
215-
MemoryContextold_ctx_m;
216215

217216
n=list_length(clauselist);
218217

219218
/* Check parameters state invariant. */
220219
Assert(n==list_length(selectivities)||
221220
(nfeatures==NULL&&features==NULL));
222221

223-
get_eclasses(clauselist,&nargs,&args_hash,&eclass_hash);
222+
/*
223+
* It should be allocated in a caller memory context, because it will be
224+
* returned.
225+
*/
224226
if (nfeatures!=NULL)
225227
*features=palloc0(sizeof(**features)*n);
226228

227-
old_ctx_m=MemoryContextSwitchTo(AQOUtilityMemCtx);
228-
229+
get_eclasses(clauselist,&nargs,&args_hash,&eclass_hash);
229230
clause_hashes=palloc(sizeof(*clause_hashes)*n);
230231
clause_has_consts=palloc(sizeof(*clause_has_consts)*n);
231232
sorted_clauses=palloc(sizeof(*sorted_clauses)*n);
@@ -299,9 +300,6 @@ get_fss_for_object(List *relsigns, List *clauselist,
299300
relations_hash= (int)get_relations_hash(relsigns);
300301
fss_hash=get_fss_hash(clauses_hash,eclasses_hash,relations_hash);
301302

302-
MemoryContextSwitchTo(old_ctx_m);
303-
MemoryContextReset(AQOUtilityMemCtx);
304-
305303
if (nfeatures!=NULL)
306304
{
307305
*nfeatures=n-sh;
@@ -682,19 +680,14 @@ get_eclasses(List *clauselist, int *nargs, int **args_hash, int **eclass_hash)
682680
inti,
683681
v;
684682
int*e_hashes;
685-
MemoryContextold_ctx_m;
686683

687684
get_clauselist_args(clauselist,nargs,args_hash);
688685
*eclass_hash=palloc((*nargs)*sizeof(**eclass_hash));
689686

690-
old_ctx_m=MemoryContextSwitchTo(AQOUtilityMemCtx);
691-
692687
p=perform_eclasses_join(clauselist,*nargs,*args_hash);
693688
lsts=palloc((*nargs)*sizeof(*lsts));
694689
e_hashes=palloc((*nargs)*sizeof(*e_hashes));
695690

696-
MemoryContextSwitchTo(old_ctx_m);
697-
698691
for (i=0;i<*nargs;++i)
699692
lsts[i]=NIL;
700693

@@ -708,8 +701,6 @@ get_eclasses(List *clauselist, int *nargs, int **args_hash, int **eclass_hash)
708701

709702
for (i=0;i<*nargs;++i)
710703
(*eclass_hash)[i]=e_hashes[disjoint_set_get_parent(p,i)];
711-
712-
MemoryContextReset(AQOUtilityMemCtx);
713704
}
714705

715706
/*

‎postprocessing.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,13 @@ restore_selectivities(List *clauselist, List *relidslist, JoinType join_type,
178178
double*cur_sel;
179179
intcur_hash;
180180
intcur_relid;
181-
MemoryContextold_ctx_m;
182181

183182
parametrized_sel=was_parametrized&& (list_length(relidslist)==1);
184183
if (parametrized_sel)
185184
{
186185
cur_relid=linitial_int(relidslist);
187186

188-
old_ctx_m=MemoryContextSwitchTo(AQOUtilityMemCtx);
189187
get_eclasses(clauselist,&nargs,&args_hash,&eclass_hash);
190-
MemoryContextSwitchTo(old_ctx_m);
191188
}
192189

193190
foreach(l,clauselist)
@@ -221,11 +218,6 @@ restore_selectivities(List *clauselist, List *relidslist, JoinType join_type,
221218
lst=lappend(lst,cur_sel);
222219
}
223220

224-
if (parametrized_sel)
225-
{
226-
MemoryContextReset(AQOUtilityMemCtx);
227-
}
228-
229221
returnlst;
230222
}
231223

‎preprocessing.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ aqo_planner(Query *parse,
127127
ParamListInfoboundParams)
128128
{
129129
boolquery_is_stored= false;
130-
MemoryContextoldctx;
130+
MemoryContextoldctx;
131+
131132
oldctx=MemoryContextSwitchTo(AQOPredictMemCtx);
132133

133134
/*
@@ -156,15 +157,8 @@ aqo_planner(Query *parse,
156157
}
157158

158159
selectivity_cache_clear();
159-
MemoryContextSwitchTo(oldctx);
160160

161-
oldctx=MemoryContextSwitchTo(AQOUtilityMemCtx);
162161
query_context.query_hash=get_query_hash(parse,query_string);
163-
MemoryContextSwitchTo(oldctx);
164-
165-
MemoryContextReset(AQOUtilityMemCtx);
166-
167-
oldctx=MemoryContextSwitchTo(AQOPredictMemCtx);
168162

169163
/* By default, they should be equal */
170164
query_context.fspace_hash=query_context.query_hash;
@@ -185,15 +179,14 @@ aqo_planner(Query *parse,
185179
cursorOptions,
186180
boundParams);
187181
}
188-
MemoryContextSwitchTo(oldctx);
189182

190183
elog(DEBUG1,"AQO will be used for query '%s', class "UINT64_FORMAT,
191184
query_string ?query_string :"null string",query_context.query_hash);
192185

186+
MemoryContextSwitchTo(oldctx);
193187
oldctx=MemoryContextSwitchTo(AQOCacheMemCtx);
194188
cur_classes=lappend_uint64(cur_classes,query_context.query_hash);
195189
MemoryContextSwitchTo(oldctx);
196-
197190
oldctx=MemoryContextSwitchTo(AQOPredictMemCtx);
198191

199192
if (aqo_mode==AQO_MODE_DISABLED)

‎storage.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,6 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
20962096
for(i=0;i<dentry->nrels;i++)
20972097
{
20982098
Oidreloid=ObjectIdGetDatum(*(Oid*)ptr);
2099-
MemoryContextoldctx=MemoryContextSwitchTo(AQOUtilityMemCtx);
21002099

21012100
if (!SearchSysCacheExists1(RELOID,reloid))
21022101
/* Remember this value */
@@ -2105,7 +2104,6 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
21052104
else
21062105
actual_fss=list_append_unique_int(actual_fss,
21072106
dentry->key.fss);
2108-
MemoryContextSwitchTo(oldctx);
21092107

21102108
ptr+=sizeof(Oid);
21112109
}
@@ -2155,8 +2153,6 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
21552153
/* Query class preferences */
21562154
(*fs_num)+= (int)_aqo_queries_remove(entry->queryid);
21572155
}
2158-
2159-
MemoryContextReset(AQOUtilityMemCtx);
21602156
}
21612157

21622158
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp