aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/optimizer/plan/planner.c9
-rw-r--r--src/backend/optimizer/plan/setrefs.c3
2 files changed, 10 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 66707944a04..2eb862e2080 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -849,6 +849,13 @@ inheritance_planner(PlannerInfo *root)
subroot.rowMarks = (List *) copyObject(root->rowMarks);
/*
+ * The append_rel_list likewise might contain references to subquery
+ * RTEs (if any subqueries were flattenable UNION ALLs). So prepare
+ * to apply ChangeVarNodes to that, too.
+ */
+ subroot.append_rel_list = (List *) copyObject(root->append_rel_list);
+
+ /*
* Add placeholders to the child Query's rangetable list to fill the
* RT indexes already reserved for subqueries in previous children.
* These won't be referenced, so there's no need to make them very
@@ -888,6 +895,7 @@ inheritance_planner(PlannerInfo *root)
newrti = list_length(subroot.parse->rtable) + 1;
ChangeVarNodes((Node *) subroot.parse, rti, newrti, 0);
ChangeVarNodes((Node *) subroot.rowMarks, rti, newrti, 0);
+ ChangeVarNodes((Node *) subroot.append_rel_list, rti, newrti, 0);
rte = copyObject(rte);
subroot.parse->rtable = lappend(subroot.parse->rtable,
rte);
@@ -896,7 +904,6 @@ inheritance_planner(PlannerInfo *root)
}
}
- /* We needn't modify the child's append_rel_list */
/* There shouldn't be any OJ or LATERAL info to translate, as yet */
Assert(subroot.join_info_list == NIL);
Assert(subroot.lateral_info_list == NIL);
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5c9f3d64ce7..333efc2712f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -280,7 +280,8 @@ add_rtes_to_flat_rtable(PlannerInfo *root, bool recursing)
* RTEs without matching RelOptInfos, as they likewise have been
* pulled up.
*/
- if (rte->rtekind == RTE_SUBQUERY && !rte->inh)
+ if (rte->rtekind == RTE_SUBQUERY && !rte->inh &&
+ rti < root->simple_rel_array_size)
{
RelOptInfo *rel = root->simple_rel_array[rti];