@@ -44,6 +44,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
4444ListCell * lc ;
4545double paramsel ;
4646WalkerContext context ;
47+ bool innerrel_rinfo_contains_part_attr ;
4748
4849if (set_join_pathlist_next )
4950set_join_pathlist_next (root ,joinrel ,outerrel ,
@@ -92,6 +93,11 @@ pathman_join_pathlist_hook(PlannerInfo *root,
9293paramsel *=wrap -> paramsel ;
9394}
9495
96+ innerrel_rinfo_contains_part_attr =
97+ check_rinfo_for_partitioned_attr (innerrel -> baserestrictinfo ,
98+ innerrel -> relid ,
99+ inner_prel -> attnum );
100+
95101foreach (lc ,innerrel -> pathlist )
96102{
97103AppendPath * cur_inner_path = (AppendPath * )lfirst (lc );
@@ -107,6 +113,16 @@ pathman_join_pathlist_hook(PlannerInfo *root,
107113
108114ppi = get_baserel_parampathinfo (root ,innerrel ,inner_required );
109115
116+ /*
117+ * Skip if neither rel->baserestrictinfo nor
118+ * ppi->ppi_clauses reference partition attribute
119+ */
120+ if (!(innerrel_rinfo_contains_part_attr ||
121+ (ppi && check_rinfo_for_partitioned_attr (ppi -> ppi_clauses ,
122+ innerrel -> relid ,
123+ inner_prel -> attnum ))))
124+ continue ;
125+
110126inner = create_runtimeappend_path (root ,cur_inner_path ,
111127ppi ,
112128paramsel );
@@ -162,6 +178,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
162178double paramsel = 1.0 ;
163179WalkerContext context ;
164180int i ;
181+ bool rel_rinfo_contains_part_attr = false;
165182
166183if (prel -> parttype == PT_RANGE )
167184{
@@ -280,6 +297,11 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
280297if (!clause_contains_params ((Node * )get_actual_clauses (rel -> baserestrictinfo )))
281298return ;
282299
300+ rel_rinfo_contains_part_attr =
301+ check_rinfo_for_partitioned_attr (rel -> baserestrictinfo ,
302+ rel -> relid ,
303+ prel -> attnum );
304+
283305foreach (lc ,rel -> pathlist )
284306{
285307AppendPath * cur_path = (AppendPath * )lfirst (lc );
@@ -295,6 +317,16 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
295317continue ;
296318}
297319
320+ /*
321+ * Skip if neither rel->baserestrictinfo nor
322+ * ppi->ppi_clauses reference partition attribute
323+ */
324+ if (!(rel_rinfo_contains_part_attr ||
325+ (ppi && check_rinfo_for_partitioned_attr (ppi -> ppi_clauses ,
326+ rel -> relid ,
327+ prel -> attnum ))))
328+ continue ;
329+
298330if (IsA (cur_path ,AppendPath )&& pg_pathman_enable_runtimeappend )
299331inner_path = create_runtimeappend_path (root ,cur_path ,
300332ppi ,paramsel );