diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 86d5bb71b0a0a3811a2d5fa2f0682b8964ff037d..8fc933bc0769d5c6957be7f81e53a1ed1b53f43d 100644
*** a/src/backend/optimizer/path/allpaths.c
--- b/src/backend/optimizer/path/allpaths.c
*************** set_subquery_pathlist(PlannerInfo *root,
*** 1159,1165 ****
  	/*
  	 * It's possible that constraint exclusion proved the subquery empty. If
  	 * so, it's convenient to turn it back into a dummy path so that we will
! 	 * recognize appropriate optimizations at this level.
  	 */
  	if (is_dummy_plan(rel->subplan))
  	{
--- 1159,1166 ----
  	/*
  	 * It's possible that constraint exclusion proved the subquery empty. If
  	 * so, it's convenient to turn it back into a dummy path so that we will
! 	 * recognize appropriate optimizations at this level.  (But see
! 	 * create_append_plan in createplan.c, which has to partially undo this.)
  	 */
  	if (is_dummy_plan(rel->subplan))
  	{
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 65a2e38fc33e168621bbe9c0becb9d101129d862..b8055c79da7131752d555d86ad0a44506954cea7 100644
*** a/src/backend/optimizer/plan/createplan.c
--- b/src/backend/optimizer/plan/createplan.c
*************** static Plan *
*** 678,707 ****
  create_append_plan(PlannerInfo *root, AppendPath *best_path)
  {
  	Append	   *plan;
! 	List	   *tlist = build_relation_tlist(best_path->path.parent);
  	List	   *subplans = NIL;
  	ListCell   *subpaths;
  
  	/*
! 	 * It is possible for the subplans list to contain only one entry, or even
! 	 * no entries.	Handle these cases specially.
  	 *
! 	 * XXX ideally, if there's just one entry, we'd not bother to generate an
! 	 * Append node but just return the single child.  At the moment this does
! 	 * not work because the varno of the child scan plan won't match the
! 	 * parent-rel Vars it'll be asked to emit.
  	 */
  	if (best_path->subpaths == NIL)
  	{
  		/* Generate a Result plan with constant-FALSE gating qual */
! 		return (Plan *) make_result(root,
! 									tlist,
! 									(Node *) list_make1(makeBoolConst(false,
! 																	  false)),
! 									NULL);
  	}
  
! 	/* Normal case with multiple subpaths */
  	foreach(subpaths, best_path->subpaths)
  	{
  		Path	   *subpath = (Path *) lfirst(subpaths);
--- 678,727 ----
  create_append_plan(PlannerInfo *root, AppendPath *best_path)
  {
  	Append	   *plan;
! 	RelOptInfo *rel = best_path->path.parent;
! 	List	   *tlist = build_relation_tlist(rel);
  	List	   *subplans = NIL;
  	ListCell   *subpaths;
  
  	/*
! 	 * The subpaths list could be empty, if every child was proven empty by
! 	 * constraint exclusion.  In that case generate a dummy plan that returns
! 	 * no rows.
  	 *
! 	 * Note that an AppendPath with no members is also generated in certain
! 	 * cases where there was no appending construct at all, but we know the
! 	 * relation is empty (see set_dummy_rel_pathlist).
  	 */
  	if (best_path->subpaths == NIL)
  	{
+ 		Plan	   *res;
+ 
  		/* Generate a Result plan with constant-FALSE gating qual */
! 		res = (Plan *) make_result(root,
! 								   tlist,
! 								   (Node *) list_make1(makeBoolConst(false,
! 																	 false)),
! 								   NULL);
! 
! 		/*
! 		 * If this is a dummy path for a subquery, we have to wrap it in a
! 		 * SubqueryScan so that setrefs.c will do the right things (in
! 		 * particular, it must pull up the subquery's rangetable so that the
! 		 * executor will apply permissions checks to those rels at runtime).
! 		 */
! 		if (rel->rtekind == RTE_SUBQUERY)
! 		{
! 			Assert(is_dummy_plan(rel->subplan));
! 			res = (Plan *) make_subqueryscan(tlist,
! 											 NIL,
! 											 rel->relid,
! 											 rel->subplan);
! 		}
! 
! 		return res;
  	}
  
! 	/* Build the plan for each child */
  	foreach(subpaths, best_path->subpaths)
  	{
  		Path	   *subpath = (Path *) lfirst(subpaths);
*************** create_append_plan(PlannerInfo *root, Ap
*** 709,714 ****
--- 729,741 ----
  		subplans = lappend(subplans, create_plan_recurse(root, subpath));
  	}
  
+ 	/*
+ 	 * XXX ideally, if there's just one child, we'd not bother to generate an
+ 	 * Append node but just return the single child.  At the moment this does
+ 	 * not work because the varno of the child scan plan won't match the
+ 	 * parent-rel Vars it'll be asked to emit.
+ 	 */
+ 
  	plan = make_append(subplans, tlist);
  
  	return (Plan *) plan;
