@@ -369,6 +369,8 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
369369 * FROM test.tmp2 t2
370370 * WHERE id = t.id);
371371 *
372+ * or unions, multilevel partitioning, etc.
373+ *
372374 * Since we disable optimizations on 9.5, we
373375 * have to skip parent table that has already
374376 * been expanded by standard inheritance.
@@ -378,23 +380,18 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
378380foreach (lc ,root -> append_rel_list )
379381{
380382AppendRelInfo * appinfo = (AppendRelInfo * )lfirst (lc );
381- RangeTblEntry * cur_parent_rte ,
382- * cur_child_rte ;
383-
384- /* This 'appinfo' is not for this child */
385- if (appinfo -> child_relid != rti )
386- continue ;
387-
388- cur_parent_rte = root -> simple_rte_array [appinfo -> parent_relid ];
389- cur_child_rte = rte ;/* we already have it, saves time */
390383
391- /* This child == its own parent table! */
392- if (cur_parent_rte -> relid == cur_child_rte -> relid )
384+ /*
385+ * If there's an 'appinfo', it means that somebody
386+ * (PG?) has already processed this partitioned table
387+ * and added its children to the plan.
388+ */
389+ if (appinfo -> child_relid == rti )
393390return ;
394391}
395392}
396393
397- /* Make copy of partitioning expression and fix Var's varno attributes */
394+ /* Make copy of partitioning expression and fix Var's varno attributes */
398395part_expr = PrelExpressionForRelid (prel ,rti );
399396
400397/* Get partitioning-related clauses (do this before append_child_relation()) */