From bbf08f1e8de0ee2233d4310356d4df04aac159ed Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Fri, 30 Mar 2018 12:23:15 -0600 Subject: [PATCH] Attempt to address planner context crashes Both of these are a bit of a shot in the dark. In one case, we noticed a stack trace where a caller received a null pointer and attempted to dereference the memory context field (at 0x010). In the other, I saw that any error thrown from within AdjustParseTree could keep the stack from being cleaned up (presumably if we push we should always pop). Both stack traces were collected during times of high memory pressure and locally reproducing the problem locally or otherwise has been very tricky (i.e. it hasn't been reproduced reliably at all). --- .../distributed/planner/multi_planner.c | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/backend/distributed/planner/multi_planner.c b/src/backend/distributed/planner/multi_planner.c index 52681bcc3..e9b375862 100644 --- a/src/backend/distributed/planner/multi_planner.c +++ b/src/backend/distributed/planner/multi_planner.c @@ -127,6 +127,11 @@ multi_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) { result = CreateDistributedPlan(result, originalQuery, parse, boundParams, plannerRestrictionContext); + + assignRTEIdentities = false; + setPartitionedTablesInherited = true; + + AdjustParseTree(parse, assignRTEIdentities, setPartitionedTablesInherited); } } PG_CATCH(); @@ -136,14 +141,6 @@ multi_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) } PG_END_TRY(); - if (needsDistributedPlanning) - { - assignRTEIdentities = false; - setPartitionedTablesInherited = true; - - AdjustParseTree(parse, assignRTEIdentities, setPartitionedTablesInherited); - } - /* remove the context from the context list */ PopPlannerRestrictionContext(); @@ -971,6 +968,13 @@ CurrentPlannerRestrictionContext(void) plannerRestrictionContext = (PlannerRestrictionContext *) linitial(plannerRestrictionContextList); + if (plannerRestrictionContext == NULL) + { + ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("planner restriction context stack was empty"), + errdetail("Please report this to the Citus core team."))); + } + return plannerRestrictionContext; }