diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 971da18..ab5c02d 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -2593,8 +2593,6 @@ inheritance_make_rel_from_joinlist(PlannerInfo *root,
 		RelOptInfo *childrel;
 		AppendRelInfo *appinfo = lfirst(lc);
 		List	   *translated_joinlist;
-		Relids		child_relids,
-					top_parent_relids;
 
 		/* Only consider this parent's children. */
 		if (appinfo->parent_relid != parent->relid)
@@ -2608,36 +2606,35 @@ inheritance_make_rel_from_joinlist(PlannerInfo *root,
 			continue;
 
 		/*
+		 * Modify joinlist such that relations joined to the top parent rel
+		 * appear to be joined to the child rel instead.  Do the same for
+		 * any SpecialJoinInfo structs.
+		 */
+		Assert(childrel->inh_root_parent > 0);
+		translated_joinlist = (List *)
+						adjust_appendrel_attrs(root, (Node *) joinlist,
+											   1, &appinfo);
+
+		root->join_info_list = (List *)
+						adjust_appendrel_attrs(root, (Node *) join_info_list,
+											   1, &appinfo);
+
+		/*
 		 * Sub-partitions have to be processed recursively, because
 		 * AppendRelInfoss link sub-partitions to their immediate parents, not
 		 * the root partitioned table.
 		 */
 		if (childrel->part_scheme != NULL)
 		{
-			inheritance_make_rel_from_joinlist(root, childrel, joinlist);
+			inheritance_make_rel_from_joinlist(root, childrel,
+											   translated_joinlist);
+
+			/* Restore the original for processing the next child. */
+			root->join_info_list = join_info_list;
 			continue;
 		}
 
 		/*
-		 * Modify joinlist such that relations joined to the top parent rel
-		 * appear to be joined to the child rel instead.  Do the same for
-		 * any SpecialJoinInfo structs.
-		 */
-		child_relids = bms_make_singleton(appinfo->child_relid);
-		Assert(childrel->inh_root_parent > 0);
-		top_parent_relids = bms_make_singleton(childrel->inh_root_parent);
-		translated_joinlist = (List *)
-						adjust_appendrel_attrs_multilevel(root,
-														  (Node *) joinlist,
-														  child_relids,
-														  top_parent_relids);
-		root->join_info_list = (List *)
-				adjust_appendrel_attrs_multilevel(root,
-												  (Node *) join_info_list,
-												  child_relids,
-												  top_parent_relids);
-
-		/*
 		 * Since we added the child rel directly into the join tree, we must
 		 * modify it to be a "base" rel instead of an "other" rel, which the
 		 * join planning code expects the relations being joined to be.
