Handle params correctly within Subplan nodes
authorPavan Deolasee <[email protected]>
Mon, 21 Aug 2017 05:37:47 +0000 (11:07 +0530)
committerPavan Deolasee <[email protected]>
Mon, 21 Aug 2017 05:41:16 +0000 (11:11 +0530)
We were not dealing with the params in Subplan correctly, thus those params
were not sent to the remote nodes correctly during RemoteSubplan exectution.
This patch fixes that by traversing the Subplan node correctly. The regression
failure in the 'join' test case is addressed too.

Patch by senhu ([email protected])

src/backend/pgxc/pool/execRemote.c

index d1a4e4d4b33f81489b3bee4a3748c5b691f4f0ba..7ce5549521c7e8bac125d88031d6c3aac8b086bc 100644 (file)
@@ -77,6 +77,13 @@ typedef struct
        void *fparams;
 } abort_callback_type;
 
+struct find_params_context
+{
+       RemoteParam *rparams;
+       Bitmapset *defineParams;
+       List *subplans;
+};
+
 /*
  * Buffer size does not affect performance significantly, just do not allow
  * connection buffer grows infinitely
@@ -115,6 +122,8 @@ static void pgxc_connections_cleanup(ResponseCombiner *combiner);
 
 static void pgxc_node_report_error(ResponseCombiner *combiner);
 
+static bool determine_param_types(Plan *plan,  struct find_params_context *context);
+
 #define REMOVE_CURR_CONN(combiner) \
        if ((combiner)->current_conn < --((combiner)->conn_count)) \
        { \
@@ -4952,12 +4961,6 @@ RemoteSubplanMakeUnique(Node *plan, int unique)
        }
 }
 
-struct find_params_context
-{
-       RemoteParam *rparams;
-       Bitmapset *defineParams;
-};
-
 static bool
 determine_param_types_walker(Node *node, struct find_params_context *context)
 {
@@ -4981,6 +4984,17 @@ determine_param_types_walker(Node *node, struct find_params_context *context)
                        return bms_is_empty(context->defineParams);
                }
        }
+
+       if (IsA(node, SubPlan) && context->subplans)
+       {
+               Plan *plan;
+               SubPlan *subplan = (SubPlan *) node;
+
+               plan = (Plan *) list_nth(context->subplans, subplan->plan_id - 1);
+               if (determine_param_types(plan, context))
+                       return true;
+       }
+
        return expression_tree_walker(node, determine_param_types_walker,
                                                                  (void *) context);
 
@@ -5219,6 +5233,18 @@ determine_param_types(Plan *plan,  struct find_params_context *context)
                                 (int) nodeTag(plan));
        }
 
+       /* check initplan if exists */
+       if (plan->initPlan)
+       {
+               ListCell *l;
+
+               foreach(l, plan->initPlan)
+               {
+                       SubPlan  *subplan = (SubPlan *) lfirst(l);
+                       if (determine_param_types_walker((Node *) subplan, context))
+                               return true;
+               }
+       }
 
        /* recurse into subplans */
        return determine_param_types(plan->lefttree, context) ||
@@ -5496,6 +5522,7 @@ ExecInitRemoteSubplan(RemoteSubplan *node, EState *estate, int eflags)
 
                                        context.rparams = rstmt.remoteparams;
                                        context.defineParams = defineParams;
+                                       context.subplans = estate->es_plannedstmt->subplans;
 
                                        all_found = determine_param_types(node->scan.plan.lefttree,
                                                                                                          &context);