Remember the restrictInfo clauses which were pushed down to inner parameterised
authorPavan Deolasee <[email protected]>
Tue, 18 Aug 2015 11:33:53 +0000 (17:03 +0530)
committerPavan Deolasee <[email protected]>
Tue, 18 Aug 2015 11:33:53 +0000 (17:03 +0530)
scans

We later use them to decide the actual subset of nodes where joins must be
pushed down. Without that we may push the plan to more nodes than necessary
because we would never look at the restrictInfo clauses which were removed
because of parameterised scans

src/backend/nodes/outfuncs.c
src/backend/optimizer/util/pathnode.c
src/include/nodes/relation.h

index bda40f2f1778c936a70b914dc23eb4cdb5b6f639..7c789ba7ad7695a5024122a0fb289bb323b74606 100644 (file)
@@ -2662,6 +2662,7 @@ _outJoinPathInfo(StringInfo str, const JoinPath *node)
        WRITE_NODE_FIELD(outerjoinpath);
        WRITE_NODE_FIELD(innerjoinpath);
        WRITE_NODE_FIELD(joinrestrictinfo);
+       WRITE_NODE_FIELD(movedrestrictinfo);
 }
 
 static void
index b393b5021a911f34cc5365c3cf2530a7ec90b643..81ae3d26dac74dfd8ce90ab4655ed4b53d43a0ec 100644 (file)
@@ -1015,6 +1015,7 @@ set_joinpath_distribution(PlannerInfo *root, JoinPath *pathnode)
        Distribution   *outerd = pathnode->outerjoinpath->distribution;
        Distribution   *targetd;
        List               *alternate = NIL;
+       List               *restrictClauses = NIL;
 
        /* Catalog join */
        if (innerd == NULL && outerd == NULL)
@@ -1102,6 +1103,10 @@ set_joinpath_distribution(PlannerInfo *root, JoinPath *pathnode)
        }
 
 
+       restrictClauses = list_copy(pathnode->joinrestrictinfo);
+       restrictClauses = list_concat(restrictClauses,
+                       pathnode->movedrestrictinfo);
+
        /*
         * This join is still allowed if inner and outer paths have
         * equivalent distribution and joined along the distribution keys.
@@ -1129,7 +1134,7 @@ set_joinpath_distribution(PlannerInfo *root, JoinPath *pathnode)
                 * Equivalence Class.
                 * Try to figure out if such restriction exists.
                 */
-               foreach(lc, pathnode->joinrestrictinfo)
+               foreach(lc, restrictClauses)
                {
                        RestrictInfo *ri = (RestrictInfo *) lfirst(lc);
                        ListCell   *emc;
@@ -1345,7 +1350,7 @@ not_allowed_join:
                 * 1. one argument is already a partitioning key of one subplan.
                 * 2. restriction is cheaper to calculate
                 */
-               foreach(lc, pathnode->joinrestrictinfo)
+               foreach(lc, restrictClauses)
                {
                        RestrictInfo   *ri = (RestrictInfo *) lfirst(lc);
 
@@ -2746,6 +2751,7 @@ create_nestloop_path(PlannerInfo *root,
 #ifdef XCP
        List       *alternate;
        ListCell   *lc;
+       List       *mclauses = NIL;
 #endif
        Relids          inner_req_outer = PATH_REQ_OUTER(inner_path);
 
@@ -2771,6 +2777,10 @@ create_nestloop_path(PlannerInfo *root,
                                                                                         inner_path->parent->relids,
                                                                                         inner_and_outer))
                                jclauses = lappend(jclauses, rinfo);
+#ifdef XCP
+                       else
+                               mclauses = lappend(mclauses, rinfo);
+#endif
                }
                restrict_clauses = jclauses;
        }
@@ -2792,6 +2802,8 @@ create_nestloop_path(PlannerInfo *root,
        pathnode->joinrestrictinfo = restrict_clauses;
 
 #ifdef XCP
+       pathnode->movedrestrictinfo = mclauses;
+
        alternate = set_joinpath_distribution(root, pathnode);
 #endif
        final_cost_nestloop(root, pathnode, workspace, sjinfo, semifactors);
index 4c284cfcba18932844eaeba66005256add9811cb..f7df205fe11b9f477de82b34eca3b76efe1c2956 100644 (file)
@@ -1112,6 +1112,10 @@ typedef struct JoinPath
 
        List       *joinrestrictinfo;           /* RestrictInfos to apply to join */
 
+#ifdef XCP
+       List       *movedrestrictinfo;          /* RestrictInfos moved down to inner path */
+#endif
+
        /*
         * See the notes for RelOptInfo and ParamPathInfo to understand why
         * joinrestrictinfo is needed in JoinPath, and can't be merged into the