Skip to content

Bugfix. Remove dangerous usage of short-lived AQO memory contexts. #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions preprocessing.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ aqo_planner(Query *parse,
bool query_is_stored = false;
MemoryContext oldctx;

oldctx = MemoryContextSwitchTo(AQOPredictMemCtx);

/*
* We do not work inside an parallel worker now by reason of insert into
* the heap during planning. Transactions are synchronized between parallel
Expand All @@ -146,7 +144,6 @@ aqo_planner(Query *parse,
* We should disable AQO for this query to remember this decision along
* all execution stages.
*/
MemoryContextSwitchTo(oldctx);
disable_aqo_for_query();

return call_default_planner(parse,
Expand Down Expand Up @@ -176,7 +173,6 @@ aqo_planner(Query *parse,
* feature space, that is processing yet (disallow invalidation
* recursion, as an example).
*/
MemoryContextSwitchTo(oldctx);
disable_aqo_for_query();

return call_default_planner(parse,
Expand All @@ -188,11 +184,9 @@ aqo_planner(Query *parse,
elog(DEBUG1, "AQO will be used for query '%s', class "UINT64_FORMAT,
query_string ? query_string : "null string", query_context.query_hash);

MemoryContextSwitchTo(oldctx);
oldctx = MemoryContextSwitchTo(AQOCacheMemCtx);
cur_classes = lappend_uint64(cur_classes, query_context.query_hash);
MemoryContextSwitchTo(oldctx);
oldctx = MemoryContextSwitchTo(AQOPredictMemCtx);

if (aqo_mode == AQO_MODE_DISABLED)
{
Expand Down Expand Up @@ -351,7 +345,7 @@ aqo_planner(Query *parse,
INSTR_TIME_SET_CURRENT(query_context.start_planning_time);
{
PlannedStmt *stmt;
MemoryContextSwitchTo(oldctx);

stmt = call_default_planner(parse, query_string,
cursorOptions, boundParams);

Expand Down Expand Up @@ -458,7 +452,6 @@ jointree_walker(Node *jtnode, void *context)
static bool
isQueryUsingSystemRelation_walker(Node *node, void *context)
{
MemoryContext oldctx = MemoryContextSwitchTo(AQOLearnMemCtx);
AQOPreWalkerCtx *ctx = (AQOPreWalkerCtx *) context;

if (node == NULL)
Expand Down Expand Up @@ -500,7 +493,6 @@ isQueryUsingSystemRelation_walker(Node *node, void *context)
}

jointree_walker((Node *) query->jointree, context);
MemoryContextSwitchTo(oldctx);

/* Recursively plunge into subqueries and CTEs */
return query_tree_walker(query,
Expand Down