diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-03-24 16:21:39 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-03-24 16:21:39 -0400 |
commit | 8279eb4191c7ab9920c72ec8eec5df0e7b8c7530 (patch) | |
tree | 7b8c98f6b214bd4017d517a86ea5ea2b9a65f93b /src/include/nodes/relation.h | |
parent | ed61127be483d8939e13a151773549f1517d6e67 (diff) | |
download | postgresql-8279eb4191c7ab9920c72ec8eec5df0e7b8c7530.tar.gz postgresql-8279eb4191c7ab9920c72ec8eec5df0e7b8c7530.zip |
Fix planner's handling of outer PlaceHolderVars within subqueries.
For some reason, in the original coding of the PlaceHolderVar mechanism
I had supposed that PlaceHolderVars couldn't propagate into subqueries.
That is of course entirely possible. When it happens, we need to treat
an outer-level PlaceHolderVar much like an outer Var or Aggref, that is
SS_replace_correlation_vars() needs to replace the PlaceHolderVar with
a Param, and then when building the finished SubPlan we have to provide
the PlaceHolderVar expression as an actual parameter for the SubPlan.
The handling of the contained expression is a bit delicate but it can be
treated exactly like an Aggref's expression.
In addition to the missing logic in subselect.c, prepjointree.c was failing
to search subqueries for PlaceHolderVars that need their relids adjusted
during subquery pullup. It looks like everyplace else that touches
PlaceHolderVars got it right, though.
Per report from Mark Murawski. In 9.1 and HEAD, queries affected by this
oversight would fail with "ERROR: Upper-level PlaceHolderVar found where
not expected". But in 9.0 and 8.4, you'd silently get possibly-wrong
answers, since the value transmitted into the subquery wouldn't go to null
when it should.
Diffstat (limited to 'src/include/nodes/relation.h')
-rw-r--r-- | src/include/nodes/relation.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index d901a85e7ac..6606e67055b 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -1445,8 +1445,10 @@ typedef struct MinMaxAggInfo * from a NestLoop node of that level to its inner scan. The varlevelsup * value in the Var will always be zero. * - * A PlaceHolderVar: this works much like the Var case. It is currently - * only needed for NestLoop parameters, not outer references. + * A PlaceHolderVar: this works much like the Var case, except that the + * entry is a PlaceHolderVar node with a contained expression. The PHV + * will have phlevelsup = 0, and the contained expression is adjusted + * to match in level. * * An Aggref (with an expression tree representing its argument): the slot * represents an aggregate expression that is an outer reference for some |