]> granicus.if.org Git - postgresql/commit
Fix nested PlaceHolderVar expressions that appear only in targetlists.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 9 Aug 2011 04:49:04 +0000 (00:49 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 9 Aug 2011 04:49:04 +0000 (00:49 -0400)
commit8a14bdb10f0a9b123e5c6f70f33334b132b3da29
tree8227793f9274593813d187d84ee5a454a12966dc
parentf60078232d587d62c7343780ce1c470e5f5c66a5
Fix nested PlaceHolderVar expressions that appear only in targetlists.

A PlaceHolderVar's expression might contain another, lower-level
PlaceHolderVar.  If the outer PlaceHolderVar is used, the inner one
certainly will be also, and so we have to make sure that both of them get
into the placeholder_list with correct ph_may_need values during the
initial pre-scan of the query (before deconstruct_jointree starts).
We did this correctly for PlaceHolderVars appearing in the query quals,
but overlooked the issue for those appearing in the top-level targetlist;
with the result that nested placeholders referenced only in the targetlist
did not work correctly, as illustrated in bug #6154.

While at it, add some error checking to find_placeholder_info to ensure
that we don't try to create new placeholders after it's too late to do so;
they have to all be created before deconstruct_jointree starts.

Back-patch to 8.4 where the PlaceHolderVar mechanism was introduced.
src/backend/optimizer/path/costsize.c
src/backend/optimizer/path/equivclass.c
src/backend/optimizer/plan/initsplan.c
src/backend/optimizer/util/placeholder.c
src/include/optimizer/placeholder.h
src/include/optimizer/planmain.h
src/test/regress/expected/join.out
src/test/regress/sql/join.sql