@@ -40,7 +40,7 @@ init_partition_filter_static_data(void)
4040}
4141
4242Plan *
43- make_partition_filter_plan (Plan * subplan ,Oid partitioned_table ,
43+ make_partition_filter (Plan * subplan ,Oid partitioned_table ,
4444OnConflictAction conflict_action )
4545{
4646CustomScan * cscan = makeNode (CustomScan );
@@ -265,27 +265,73 @@ pfilter_build_tlist(List *tlist)
265265return result_tlist ;
266266}
267267
268- /* Add proxy PartitionFilter nodes to subplans of ModifyTable node */
269268void
270- add_partition_filters (List * rtable ,ModifyTable * modify_table )
269+ add_partition_filters (List * rtable ,Plan * plan )
271270{
272- ListCell * lc1 ,
273- * lc2 ;
271+ ListCell * l ;
274272
275- Assert (IsA (modify_table ,ModifyTable ));
276-
277- if (!pg_pathman_enable_partition_filter )
273+ if (plan == NULL || !pg_pathman_enable_partition_filter )
278274return ;
279275
280- forboth (lc1 ,modify_table -> plans ,lc2 ,modify_table -> resultRelations )
276+ /* Plan-type-specific fixes*/
277+ switch (nodeTag (plan ))
281278{
282- Index rindex = lfirst_int (lc2 );
283- Oid relid = getrelid (rindex ,rtable );
284- PartRelationInfo * prel = get_pathman_relation_info (relid ,NULL );
285-
286- if (prel )
287- lfirst (lc1 )= make_partition_filter_plan ((Plan * )lfirst (lc1 ),
288- relid ,
289- modify_table -> onConflictAction );
279+ case T_SubqueryScan :
280+ add_partition_filters (rtable , ((SubqueryScan * )plan )-> subplan );
281+ break ;
282+
283+ case T_CustomScan :
284+ foreach (l , ((CustomScan * )plan )-> custom_plans )
285+ add_partition_filters (rtable , (Plan * )lfirst (l ));
286+ break ;
287+
288+ /*
289+ * Add proxy PartitionFilter nodes
290+ * to subplans of ModifyTable node
291+ */
292+ case T_ModifyTable :
293+ {
294+ ModifyTable * modify_table = ((ModifyTable * )plan );
295+ ListCell * lc1 ,
296+ * lc2 ;
297+
298+ forboth (lc1 ,modify_table -> plans ,lc2 ,modify_table -> resultRelations )
299+ {
300+ Index rindex = lfirst_int (lc2 );
301+ Oid relid = getrelid (rindex ,rtable );
302+ PartRelationInfo * prel = get_pathman_relation_info (relid ,NULL );
303+
304+ add_partition_filters (rtable , (Plan * )lfirst (lc1 ));
305+
306+ if (prel )
307+ lfirst (lc1 )= make_partition_filter ((Plan * )lfirst (lc1 ),
308+ relid ,
309+ modify_table -> onConflictAction );
310+ }
311+ }
312+ break ;
313+
314+ /* Since they look alike */
315+ case T_MergeAppend :
316+ case T_Append :
317+ foreach (l , ((Append * )plan )-> appendplans )
318+ add_partition_filters (rtable , (Plan * )lfirst (l ));
319+ break ;
320+
321+ case T_BitmapAnd :
322+ foreach (l , ((BitmapAnd * )plan )-> bitmapplans )
323+ add_partition_filters (rtable , (Plan * )lfirst (l ));
324+ break ;
325+
326+ case T_BitmapOr :
327+ foreach (l , ((BitmapOr * )plan )-> bitmapplans )
328+ add_partition_filters (rtable , (Plan * )lfirst (l ));
329+ break ;
330+
331+ default :
332+ break ;
290333}
334+
335+ add_partition_filters (rtable ,plan -> lefttree );
336+ add_partition_filters (rtable ,plan -> righttree );
291337}