@@ -44,6 +44,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
4444 ListCell * lc ;
4545 double paramsel ;
4646 WalkerContext context ;
47+ bool innerrel_rinfo_contains_part_attr ;
4748
4849 if (set_join_pathlist_next )
4950 set_join_pathlist_next (root , joinrel , outerrel ,
@@ -92,6 +93,11 @@ pathman_join_pathlist_hook(PlannerInfo *root,
9293 paramsel *= 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+
95101 foreach (lc , innerrel -> pathlist )
96102 {
97103 AppendPath * cur_inner_path = (AppendPath * ) lfirst (lc );
@@ -107,6 +113,16 @@ pathman_join_pathlist_hook(PlannerInfo *root,
107113
108114 ppi = 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+
110126 inner = create_runtimeappend_path (root , cur_inner_path ,
111127 ppi ,
112128 paramsel );
@@ -162,6 +178,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
162178 double paramsel = 1.0 ;
163179 WalkerContext context ;
164180 int i ;
181+ bool rel_rinfo_contains_part_attr = false;
165182
166183 if (prel -> parttype == PT_RANGE )
167184 {
@@ -280,6 +297,11 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
280297 if (!clause_contains_params ((Node * ) get_actual_clauses (rel -> baserestrictinfo )))
281298 return ;
282299
300+ rel_rinfo_contains_part_attr =
301+ check_rinfo_for_partitioned_attr (rel -> baserestrictinfo ,
302+ rel -> relid ,
303+ prel -> attnum );
304+
283305 foreach (lc , rel -> pathlist )
284306 {
285307 AppendPath * cur_path = (AppendPath * ) lfirst (lc );
@@ -295,6 +317,16 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
295317 continue ;
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+
298330 if (IsA (cur_path , AppendPath ) && pg_pathman_enable_runtimeappend )
299331 inner_path = create_runtimeappend_path (root , cur_path ,
300332 ppi , paramsel );
0 commit comments