@@ -99,19 +99,21 @@ pathman_join_pathlist_hook(PlannerInfo *root,
99
99
paramsel *=wrap -> paramsel ;
100
100
}
101
101
102
- /* Check that innerrel'sRestrictInfo contains partitioned column */
102
+ /* Check that innerrel'sRestrictInfos contain partitioned column */
103
103
innerrel_rinfo_contains_part_attr =
104
104
get_partitioned_attr_clauses (innerrel -> baserestrictinfo ,
105
105
inner_prel ,innerrel -> relid )!= NULL ;
106
106
107
107
foreach (lc ,innerrel -> pathlist )
108
108
{
109
+ AppendPath * cur_inner_path = (AppendPath * )lfirst (lc );
109
110
Path * outer ,
110
111
* inner ;
111
112
NestPath * nest_path ;/* NestLoop we're creating */
112
113
ParamPathInfo * ppi ;/* parameterization info */
113
114
Relids inner_required ;/* required paremeterization relids */
114
- AppendPath * cur_inner_path = (AppendPath * )lfirst (lc );
115
+ List * filtered_joinclauses = NIL ;
116
+ ListCell * rinfo_lc ;
115
117
116
118
if (!IsA (cur_inner_path ,AppendPath ))
117
119
continue ;
@@ -136,8 +138,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
136
138
innerrel -> relid ))))
137
139
continue ;
138
140
139
- inner = create_runtimeappend_path (root ,cur_inner_path ,
140
- ppi ,paramsel );
141
+ inner = create_runtimeappend_path (root ,cur_inner_path ,ppi ,paramsel );
141
142
142
143
initial_cost_nestloop (root ,& workspace ,jointype ,
143
144
outer ,inner ,/* built paths */
@@ -151,7 +152,29 @@ pathman_join_pathlist_hook(PlannerInfo *root,
151
152
pathkeys ,
152
153
calc_nestloop_required_outer (outer ,inner ));
153
154
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 */
155
178
add_path (joinrel , (Path * )nest_path );
156
179
}
157
180
}
@@ -342,8 +365,16 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
342
365
ppi ,paramsel );
343
366
else if (IsA (cur_path ,MergeAppendPath )&&
344
367
pg_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
+
345
375
inner_path = create_runtimemergeappend_path (root ,cur_path ,
346
376
ppi ,paramsel );
377
+ }
347
378
348
379
if (inner_path )
349
380
add_path (rel ,inner_path );