@@ -99,19 +99,21 @@ pathman_join_pathlist_hook(PlannerInfo *root,
9999paramsel *=wrap -> paramsel ;
100100}
101101
102- /* Check that innerrel'sRestrictInfo contains partitioned column */
102+ /* Check that innerrel'sRestrictInfos contain partitioned column */
103103innerrel_rinfo_contains_part_attr =
104104get_partitioned_attr_clauses (innerrel -> baserestrictinfo ,
105105inner_prel ,innerrel -> relid )!= NULL ;
106106
107107foreach (lc ,innerrel -> pathlist )
108108{
109+ AppendPath * cur_inner_path = (AppendPath * )lfirst (lc );
109110Path * outer ,
110111* inner ;
111112NestPath * nest_path ;/* NestLoop we're creating */
112113ParamPathInfo * ppi ;/* parameterization info */
113114Relids inner_required ;/* required paremeterization relids */
114- AppendPath * cur_inner_path = (AppendPath * )lfirst (lc );
115+ List * filtered_joinclauses = NIL ;
116+ ListCell * rinfo_lc ;
115117
116118if (!IsA (cur_inner_path ,AppendPath ))
117119continue ;
@@ -136,8 +138,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
136138innerrel -> relid ))))
137139continue ;
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
142143initial_cost_nestloop (root ,& workspace ,jointype ,
143144outer ,inner ,/* built paths */
@@ -151,7 +152,29 @@ pathman_join_pathlist_hook(PlannerInfo *root,
151152pathkeys ,
152153calc_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 */
155178add_path (joinrel , (Path * )nest_path );
156179}
157180}
@@ -342,8 +365,16 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
342365ppi ,paramsel );
343366else if (IsA (cur_path ,MergeAppendPath )&&
344367pg_pathman_enable_runtime_merge_append )
368+ {
369+ /* Check struct layout compatibility */
370+ if (offsetof(AppendPath ,subpaths )!=
371+ offsetof(MergeAppendPath ,subpaths ))
372+ elog (FATAL ,"Struct layouts of AppendPath and "
373+ "MergeAppendPath differ" );
374+
345375inner_path = create_runtimemergeappend_path (root ,cur_path ,
346376ppi ,paramsel );
377+ }
347378
348379if (inner_path )
349380add_path (rel ,inner_path );