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

Commite814774

Browse files
danolivoAlena0704
authored andcommitted
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 parentccfea61 commite814774

File tree

5 files changed

+8
-47
lines changed

5 files changed

+8
-47
lines changed

‎aqo.c

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

92-
/* Should be released in-place, just after a huge calculation */
93-
MemoryContextAQOUtilityMemCtx=NULL;
94-
9592
/* Is released at the end of planning */
9693
MemoryContextAQOPredictMemCtx=NULL;
9794

@@ -360,15 +357,7 @@ _PG_init(void)
360357
AQOCacheMemCtx=AllocSetContextCreate(AQOTopMemCtx,
361358
"AQOCacheMemCtx",
362359
ALLOCSET_DEFAULT_SIZES);
363-
/*
364-
* AQOUtilityMemoryContext containe short-lived information which
365-
* is appeared from having got clause, selectivity arrays and relid lists
366-
* while calculating hashes. It clean up inside calculated
367-
* function or immediately after her having completed.
368-
*/
369-
AQOUtilityMemCtx=AllocSetContextCreate(AQOTopMemCtx,
370-
"AQOUtilityMemoryContext",
371-
ALLOCSET_DEFAULT_SIZES);
360+
372361
/*
373362
* AQOPredictMemoryContext save necessary information for making predict of plan nodes
374363
* and clean up in the execution stage of query.

‎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
@@ -180,16 +180,13 @@ restore_selectivities(List *clauselist, List *relidslist, JoinType join_type,
180180
double*cur_sel;
181181
intcur_hash;
182182
intcur_relid;
183-
MemoryContextold_ctx_m;
184183

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

190-
old_ctx_m=MemoryContextSwitchTo(AQOUtilityMemCtx);
191189
get_eclasses(clauselist,&nargs,&args_hash,&eclass_hash);
192-
MemoryContextSwitchTo(old_ctx_m);
193190
}
194191

195192
foreach(l,clauselist)
@@ -223,11 +220,6 @@ restore_selectivities(List *clauselist, List *relidslist, JoinType join_type,
223220
lst=lappend(lst,cur_sel);
224221
}
225222

226-
if (parametrized_sel)
227-
{
228-
MemoryContextReset(AQOUtilityMemCtx);
229-
}
230-
231223
returnlst;
232224
}
233225

‎preprocessing.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ aqo_planner(Query *parse,
166166
ParamListInfoboundParams)
167167
{
168168
boolquery_is_stored= false;
169-
MemoryContextoldctx;
169+
MemoryContextoldctx;
170+
170171
oldctx=MemoryContextSwitchTo(AQOPredictMemCtx);
171172

172173
/*
@@ -195,15 +196,7 @@ aqo_planner(Query *parse,
195196
}
196197

197198
selectivity_cache_clear();
198-
MemoryContextSwitchTo(oldctx);
199-
200-
oldctx=MemoryContextSwitchTo(AQOUtilityMemCtx);
201199
query_context.query_hash=get_query_hash(parse,query_string);
202-
MemoryContextSwitchTo(oldctx);
203-
204-
MemoryContextReset(AQOUtilityMemCtx);
205-
206-
oldctx=MemoryContextSwitchTo(AQOPredictMemCtx);
207200

208201
/* By default, they should be equal */
209202
query_context.fspace_hash=query_context.query_hash;

‎storage.c

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

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

21112109
ptr+=sizeof(Oid);
21122110
}
@@ -2156,8 +2154,6 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
21562154
/* Query class preferences */
21572155
(*fs_num)+= (int)_aqo_queries_remove(entry->queryid);
21582156
}
2159-
2160-
MemoryContextReset(AQOUtilityMemCtx);
21612157
}
21622158

21632159
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp