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

Commit03f09f1

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 parentf96fc0d commit03f09f1

File tree

6 files changed

+8
-41
lines changed

6 files changed

+8
-41
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

@@ -348,15 +345,7 @@ _PG_init(void)
348345
AQOCacheMemCtx=AllocSetContextCreate(AQOTopMemCtx,
349346
"AQOCacheMemCtx",
350347
ALLOCSET_DEFAULT_SIZES);
351-
/*
352-
* AQOUtilityMemoryContext containe short-lived information which
353-
* is appeared from having got clause, selectivity arrays and relid lists
354-
* while calculating hashes. It clean up inside calculated
355-
* function or immediately after her having completed.
356-
*/
357-
AQOUtilityMemCtx=AllocSetContextCreate(AQOTopMemCtx,
358-
"AQOUtilityMemoryContext",
359-
ALLOCSET_DEFAULT_SIZES);
348+
360349
/*
361350
* AQOPredictMemoryContext save necessary information for making predict of plan nodes
362351
* 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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,20 @@ get_fss_for_object(List *relsigns, List *clauselist,
194194
intsh=0,
195195
old_sh;
196196
intfss_hash;
197-
MemoryContextold_ctx_m;
198197

199198
n=list_length(clauselist);
200199

201200
/* Check parameters state invariant. */
202201
Assert(n==list_length(selectivities)||
203202
(nfeatures==NULL&&features==NULL));
204203

204+
/*
205+
* It should be allocated in a caller memory context, because it will be
206+
* returned.
207+
*/
205208
if (nfeatures!=NULL)
206209
*features=palloc0(sizeof(**features)*n);
207210

208-
old_ctx_m=MemoryContextSwitchTo(AQOUtilityMemCtx);
209-
210211
get_eclasses(clauselist,&nargs,&args_hash,&eclass_hash);
211212
clause_hashes=palloc(sizeof(*clause_hashes)*n);
212213
clause_has_consts=palloc(sizeof(*clause_has_consts)*n);
@@ -281,9 +282,6 @@ get_fss_for_object(List *relsigns, List *clauselist,
281282
relations_hash=get_relations_hash(relsigns);
282283
fss_hash=get_fss_hash(clauses_hash,eclasses_hash,relations_hash);
283284

284-
MemoryContextSwitchTo(old_ctx_m);
285-
MemoryContextReset(AQOUtilityMemCtx);
286-
287285
if (nfeatures!=NULL)
288286
{
289287
*nfeatures=n-sh;

‎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,21 +157,14 @@ aqo_planner(Query *parse,
156157
}
157158

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

161-
oldctx=MemoryContextSwitchTo(AQOUtilityMemCtx);
162161
/* Check unlucky case (get a hash of zero) */
163162
if (parse->queryId==UINT64CONST(0))
164163
JumbleQuery(parse,query_string);
165164

166165
Assert(parse->utilityStmt==NULL);
167166
Assert(parse->queryId!=UINT64CONST(0));
168167
query_context.query_hash=parse->queryId;
169-
MemoryContextSwitchTo(oldctx);
170-
171-
MemoryContextReset(AQOUtilityMemCtx);
172-
173-
oldctx=MemoryContextSwitchTo(AQOPredictMemCtx);
174168

175169
/* By default, they should be equal */
176170
query_context.fspace_hash=query_context.query_hash;
@@ -191,15 +185,14 @@ aqo_planner(Query *parse,
191185
cursorOptions,
192186
boundParams);
193187
}
194-
MemoryContextSwitchTo(oldctx);
195188

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

192+
MemoryContextSwitchTo(oldctx);
199193
oldctx=MemoryContextSwitchTo(AQOCacheMemCtx);
200194
cur_classes=lappend_uint64(cur_classes,query_context.query_hash);
201195
MemoryContextSwitchTo(oldctx);
202-
203196
oldctx=MemoryContextSwitchTo(AQOPredictMemCtx);
204197

205198
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