diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 9269418a074c3bce26af742d8fbb3550b65e130e..fb61e6e7978c4c9ad683a8d36c4cca08eafcba7d 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -7044,8 +7044,6 @@ foreign_join_ok(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype,
 	PgFdwRelationInfo *fpinfo_i;
 	ListCell   *lc;
 	List	   *joinclauses;
-	bool		outer_is_function = false;
-	bool		inner_is_function = false;
 
 	/*
 	 * We support pushing down INNER, LEFT, RIGHT, FULL OUTER and SEMI joins.
@@ -7075,34 +7073,6 @@ foreign_join_ok(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype,
 		(fpinfo_o = (PgFdwRelationInfo *) outerrel->fdw_private) &&
 		fpinfo_o->pushdown_safe &&
 		function_rte_pushdown_ok(root, innerrel, outerrel))
-	{
-		inner_is_function = true;
-	}
-	else if (jointype == JOIN_INNER && outerrel->rtekind == RTE_FUNCTION &&
-			 (fpinfo_i = (PgFdwRelationInfo *) innerrel->fdw_private) &&
-			 fpinfo_i->pushdown_safe &&
-			 function_rte_pushdown_ok(root, outerrel, innerrel))
-	{
-		outer_is_function = true;
-	}
-	else
-	{
-		fpinfo_o = (PgFdwRelationInfo *) outerrel->fdw_private;
-		fpinfo_i = (PgFdwRelationInfo *) innerrel->fdw_private;
-		if (!fpinfo_o || !fpinfo_o->pushdown_safe ||
-			!fpinfo_i || !fpinfo_i->pushdown_safe)
-			return false;
-	}
-
-	/*
-	 * If one side is a function RTE, allocate a stub fpinfo so the rest of
-	 * this function and the cost estimator can treat it uniformly.  We hand
-	 * the stub to the joinrel's deparser via the same path the foreign side
-	 * uses, but we never permanently attach it to the function rel's
-	 * fdw_private (different joinrels may pair the same function RTE with
-	 * different foreign servers).
-	 */
-	if (inner_is_function)
 	{
 		fpinfo_i = init_func_stub_fpinfo(fpinfo_o, innerrel);
 
@@ -7117,7 +7087,10 @@ foreign_join_ok(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype,
 						   &fpinfo_i->remote_conds, &fpinfo_i->local_conds);
 		fpinfo->inner_func_fpinfo = fpinfo_i;
 	}
-	else if (outer_is_function)
+	else if (jointype == JOIN_INNER && outerrel->rtekind == RTE_FUNCTION &&
+			 (fpinfo_i = (PgFdwRelationInfo *) innerrel->fdw_private) &&
+			 fpinfo_i->pushdown_safe &&
+			 function_rte_pushdown_ok(root, outerrel, innerrel))
 	{
 		fpinfo_o = init_func_stub_fpinfo(fpinfo_i, outerrel);
 
@@ -7126,6 +7099,14 @@ foreign_join_ok(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype,
 						   &fpinfo_o->remote_conds, &fpinfo_o->local_conds);
 		fpinfo->outer_func_fpinfo = fpinfo_o;
 	}
+	else
+	{
+		fpinfo_o = (PgFdwRelationInfo *) outerrel->fdw_private;
+		fpinfo_i = (PgFdwRelationInfo *) innerrel->fdw_private;
+		if (!fpinfo_o || !fpinfo_o->pushdown_safe ||
+			!fpinfo_i || !fpinfo_i->pushdown_safe)
+			return false;
+	}
 
 	/*
 	 * If joining relations have local conditions, those conditions are
