From 1bb0ec316adec7302a9ec1c872cae40ff4f35fb6 Mon Sep 17 00:00:00 2001 From: velioglu Date: Thu, 10 Jan 2019 15:52:35 +0300 Subject: [PATCH] Reset planner restriction context instead of popping with recursive planning --- .../distributed/planner/distributed_planner.c | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/backend/distributed/planner/distributed_planner.c b/src/backend/distributed/planner/distributed_planner.c index f8ca33704..331460b90 100644 --- a/src/backend/distributed/planner/distributed_planner.c +++ b/src/backend/distributed/planner/distributed_planner.c @@ -84,6 +84,8 @@ static List * CopyPlanParamList(List *originalPlanParamList); static PlannerRestrictionContext * CreateAndPushPlannerRestrictionContext(void); static PlannerRestrictionContext * CurrentPlannerRestrictionContext(void); static void PopPlannerRestrictionContext(void); +static void ResetPlannerRestrictionContext( + PlannerRestrictionContext *plannerRestrictionContext); static bool HasUnresolvedExternParamsWalker(Node *expression, ParamListInfo boundParams); @@ -700,12 +702,11 @@ CreateDistributedPlan(uint64 planId, Query *originalQuery, Query *query, ParamLi { Query *newQuery = copyObject(originalQuery); bool setPartitionedTablesInherited = false; + PlannerRestrictionContext *currentPlannerRestrictionContext = + CurrentPlannerRestrictionContext(); - /* remove the pre-transformation planner restrictions context */ - PopPlannerRestrictionContext(); - - /* create a fresh new planner context */ - plannerRestrictionContext = CreateAndPushPlannerRestrictionContext(); + /* reset the current planner restrictions context */ + ResetPlannerRestrictionContext(currentPlannerRestrictionContext); /* * We force standard_planner to treat partitioned tables as regular tables @@ -1534,6 +1535,24 @@ PopPlannerRestrictionContext(void) } +/* + * ResetPlannerRestrictionContext resets the element of the given planner + * restriction context. + */ +static void +ResetPlannerRestrictionContext(PlannerRestrictionContext *plannerRestrictionContext) +{ + plannerRestrictionContext->relationRestrictionContext = + palloc0(sizeof(RelationRestrictionContext)); + + plannerRestrictionContext->joinRestrictionContext = + palloc0(sizeof(JoinRestrictionContext)); + + /* we'll apply logical AND as we add tables */ + plannerRestrictionContext->relationRestrictionContext->allReferenceTables = true; +} + + /* * HasUnresolvedExternParamsWalker returns true if the passed in expression * has external parameters that are not contained in boundParams, false