From: Pavan Deolasee Date: Fri, 24 Feb 2017 10:05:24 +0000 (+0530) Subject: Look into the initPlans attached to lefttree of RemoteSubplan while deciding X-Git-Tag: XL_10_R1BETA1~385 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=22bcfa3812a25a367ad53862096519d773ff25f1;p=postgres-xl.git Look into the initPlans attached to lefttree of RemoteSubplan while deciding whether correct variables are being referenced This helps us to fix issue #81. It's not immediately clear if we should handle this is more elegant manner than what we've done here. In PostgreSQL the initplans are always attached to the top level plan, but in XL we add a RemoteSubplan node on top of the top level plan. Unless we take into account vars generated by the initPlans, we might incorrectly conclude that certain var is not accessible by the subquery. --- diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index cd65adc82f..bc2cbcee6b 100644 --- a/src/backend/optimizer/plan/subselect.c +++ b/src/backend/optimizer/plan/subselect.c @@ -2298,6 +2298,7 @@ finalize_plan(PlannerInfo *root, Plan *plan, Bitmapset *valid_params, Bitmapset *initSetParam; Bitmapset *child_params; ListCell *l; + List *initPlan; if (plan == NULL) return NULL; @@ -2313,7 +2314,18 @@ finalize_plan(PlannerInfo *root, Plan *plan, Bitmapset *valid_params, * SS_finalize_plan was run on them already.) */ initExtParam = initSetParam = NULL; - foreach(l, plan->initPlan) + + /* + * Usually initPlans are attached to the top level plan, but in Postgres-XL + * we might add a RemoteSubplan plan on top the top level plan. If we don't + * look at the initPlans, we might fail to conclude that param references + * are valid (issue #81). + */ + initPlan = plan->initPlan; + if ((initPlan == NULL) && IsA(plan, RemoteSubplan) && plan->lefttree) + initPlan = plan->lefttree->initPlan; + + foreach(l, initPlan) { SubPlan *initsubplan = (SubPlan *) lfirst(l); Plan *initplan = planner_subplan_get_plan(root, initsubplan);