@@ -99,19 +99,21 @@ pathman_join_pathlist_hook(PlannerInfo *root,
9999 paramsel *= wrap -> paramsel ;
100100 }
101101
102- /* Check that innerrel's RestrictInfo contains partitioned column */
102+ /* Check that innerrel's RestrictInfos contain partitioned column */
103103 innerrel_rinfo_contains_part_attr =
104104 get_partitioned_attr_clauses (innerrel -> baserestrictinfo ,
105105 inner_prel , innerrel -> relid ) != NULL ;
106106
107107 foreach (lc , innerrel -> pathlist )
108108 {
109+ AppendPath * cur_inner_path = (AppendPath * ) lfirst (lc );
109110 Path * outer ,
110111 * inner ;
111112 NestPath * nest_path ; /* NestLoop we're creating */
112113 ParamPathInfo * ppi ; /* parameterization info */
113114 Relids inner_required ; /* required paremeterization relids */
114- AppendPath * cur_inner_path = (AppendPath * ) lfirst (lc );
115+ List * filtered_joinclauses = NIL ;
116+ ListCell * rinfo_lc ;
115117
116118 if (!IsA (cur_inner_path , AppendPath ))
117119 continue ;
@@ -136,8 +138,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
136138 innerrel -> relid ))))
137139 continue ;
138140
139- inner = create_runtimeappend_path (root , cur_inner_path ,
140- ppi , paramsel );
141+ inner = create_runtimeappend_path (root , cur_inner_path , ppi , paramsel );
141142
142143 initial_cost_nestloop (root , & workspace , jointype ,
143144 outer , inner , /* built paths */
@@ -151,7 +152,29 @@ pathman_join_pathlist_hook(PlannerInfo *root,
151152 pathkeys ,
152153 calc_nestloop_required_outer (outer , inner ));
153154
154- /* Finally we can add new NestLoop path */
155+ /* Discard all clauses that are to be evaluated by 'inner' */
156+ foreach (rinfo_lc , extra -> restrictlist )
157+ {
158+ RestrictInfo * rinfo = (RestrictInfo * ) lfirst (rinfo_lc );
159+
160+ Assert (IsA (rinfo , RestrictInfo ));
161+ if (!join_clause_is_movable_to (rinfo , inner -> parent ))
162+ filtered_joinclauses = lappend (filtered_joinclauses , rinfo );
163+ }
164+
165+ /*
166+ * Override 'rows' value produced by standard estimator.
167+ * Currently we use get_parameterized_joinrel_size() since
168+ * it works just fine, but this might change some day.
169+ */
170+ nest_path -> path .rows = get_parameterized_joinrel_size (root ,
171+ joinrel ,
172+ outer -> rows ,
173+ inner -> rows ,
174+ extra -> sjinfo ,
175+ filtered_joinclauses );
176+
177+ /* Finally we can add the new NestLoop path */
155178 add_path (joinrel , (Path * ) nest_path );
156179 }
157180}
0 commit comments