diff options
Diffstat (limited to 'src/backend/optimizer/prep/prepjointree.c')
-rw-r--r-- | src/backend/optimizer/prep/prepjointree.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c index 9e05ac476c3..4333d1e5ad6 100644 --- a/src/backend/optimizer/prep/prepjointree.c +++ b/src/backend/optimizer/prep/prepjointree.c @@ -1875,8 +1875,6 @@ reduce_outer_joins_pass2(Node *jtnode, * * Find any PlaceHolderVar nodes in the given tree that reference the * pulled-up relid, and change them to reference the replacement relid(s). - * We do not need to recurse into subqueries, since no subquery of the current - * top query could (yet) contain such a reference. * * NOTE: although this has the form of a walker, we cheat and modify the * nodes in-place. This should be OK since the tree was copied by @@ -1887,6 +1885,7 @@ reduce_outer_joins_pass2(Node *jtnode, typedef struct { int varno; + int sublevels_up; Relids subrelids; } substitute_multiple_relids_context; @@ -1900,7 +1899,8 @@ substitute_multiple_relids_walker(Node *node, { PlaceHolderVar *phv = (PlaceHolderVar *) node; - if (bms_is_member(context->varno, phv->phrels)) + if (phv->phlevelsup == context->sublevels_up && + bms_is_member(context->varno, phv->phrels)) { phv->phrels = bms_union(phv->phrels, context->subrelids); @@ -1909,6 +1909,18 @@ substitute_multiple_relids_walker(Node *node, } /* fall through to examine children */ } + if (IsA(node, Query)) + { + /* Recurse into subselects */ + bool result; + + context->sublevels_up++; + result = query_tree_walker((Query *) node, + substitute_multiple_relids_walker, + (void *) context, 0); + context->sublevels_up--; + return result; + } /* Shouldn't need to handle planner auxiliary nodes here */ Assert(!IsA(node, SpecialJoinInfo)); Assert(!IsA(node, AppendRelInfo)); @@ -1924,6 +1936,7 @@ substitute_multiple_relids(Node *node, int varno, Relids subrelids) substitute_multiple_relids_context context; context.varno = varno; + context.sublevels_up = 0; context.subrelids = subrelids; /* |