]> granicus.if.org Git - postgresql/commit
Fix mark_placeholder_maybe_needed to handle LATERAL references.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 1 Sep 2012 17:56:14 +0000 (13:56 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 1 Sep 2012 17:56:46 +0000 (13:56 -0400)
commit4da6439bd8553059766011e2a42c6e39df08717f
tree7ed07cbfc138f642c618bf96c8656fd167dbe9b8
parent53fa0c6db8e9ebbef9a2806193797735998520c6
Fix mark_placeholder_maybe_needed to handle LATERAL references.

If a PlaceHolderVar contains a pulled-up LATERAL reference, its minimum
possible evaluation level might be higher in the join tree than its
original syntactic location.  That in turn affects the ph_needed level for
any contained PlaceHolderVars (that is, those PHVs had better propagate up
the join tree at least to the evaluation level of the outer PHV).  We got
this mostly right, but mark_placeholder_maybe_needed() failed to account
for the effect, and in consequence could leave the inner PHVs with
ph_may_need less than what their ultimate ph_needed value will be.  That's
bad because it could lead to failure to select a join order that will allow
evaluation of the inner PHV at a valid location.  Fix that, and add an
Assert that checks that we don't ever set ph_needed to more than
ph_may_need.
src/backend/optimizer/plan/initsplan.c
src/backend/optimizer/util/placeholder.c
src/test/regress/expected/join.out
src/test/regress/sql/join.sql