Skip to content

Commit 6411fee

Browse files
author
Alena Rybakina
committed
Clear AQO_cache_mem_ctx memory context.
1 parent 3f55c5e commit 6411fee

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

aqo.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ double log_selectivity_lower_bound = -30;
9494
* after a query parsing and is used during the query planning.
9595
*/
9696
MemoryContext AQOMemoryContext;
97+
MemoryContext AQO_cache_mem_ctx;
9798
QueryContextData query_context;
9899
/* Additional plan info */
99100
int njoins;
@@ -235,6 +236,9 @@ _PG_init(void)
235236
AQOMemoryContext = AllocSetContextCreate(TopMemoryContext,
236237
"AQOMemoryContext",
237238
ALLOCSET_DEFAULT_SIZES);
239+
AQO_cache_mem_ctx = AllocSetContextCreate(TopMemoryContext,
240+
"AQO_cache_mem_ctx",
241+
ALLOCSET_DEFAULT_SIZES);
238242
RegisterResourceReleaseCallback(aqo_free_callback, NULL);
239243
RegisterAQOPlanNodeMethods();
240244
}

aqo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ extern int njoins;
252252

253253
/* Memory context for long-live data */
254254
extern MemoryContext AQOMemoryContext;
255+
extern MemoryContext AQO_cache_mem_ctx;
255256

256257
/* Saved hook values in case of unload */
257258
extern post_parse_analyze_hook_type prev_post_parse_analyze_hook;

cardinality_hooks.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
226226

227227
if (query_context.use_aqo || query_context.learn_aqo)
228228
{
229-
MemoryContext mcxt;
229+
MemoryContext old_ctx_m;
230230

231231
selectivities = list_concat(
232232
get_selectivities(root, param_clauses, rel->relid,
@@ -241,7 +241,8 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
241241
relid = planner_rt_fetch(rel->relid, root)->relid;
242242
get_eclasses(allclauses, &nargs, &args_hash, &eclass_hash);
243243

244-
mcxt = MemoryContextSwitchTo(CacheMemoryContext);
244+
old_ctx_m = MemoryContextSwitchTo(AQO_cache_mem_ctx);
245+
245246
forboth(l, allclauses, l2, selectivities)
246247
{
247248
current_hash = get_clause_hash(
@@ -251,7 +252,7 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
251252
*((double *) lfirst(l2)));
252253
}
253254

254-
MemoryContextSwitchTo(mcxt);
255+
MemoryContextSwitchTo(old_ctx_m);
255256
pfree(args_hash);
256257
pfree(eclass_hash);
257258
}

selectivity_cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,6 @@ selectivity_cache_find_global_relid(int clause_hash, int global_relid)
8989
void
9090
selectivity_cache_clear(void)
9191
{
92+
MemoryContextReset(AQO_cache_mem_ctx);
9293
objects = NIL;
9394
}

0 commit comments

Comments
 (0)