Add a concept of "placeholder" variables to the planner. These are variables
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 21 Oct 2008 20:42:53 +0000 (20:42 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 21 Oct 2008 20:42:53 +0000 (20:42 +0000)
commit578387b5210bdf0c2b57168c23e3959f79187a9b
tree232236a6eff252afc0f17d9a639ed3e4be720f56
parent71d12b593d9a61f0fe16da6bb0d8daf90ec5ea3f
Add a concept of "placeholder" variables to the planner.  These are variables
that represent some expression that we desire to compute below the top level
of the plan, and then let that value "bubble up" as though it were a plain
Var (ie, a column value).

The immediate application is to allow sub-selects to be flattened even when
they are below an outer join and have non-nullable output expressions.
Formerly we couldn't flatten because such an expression wouldn't properly
go to NULL when evaluated above the outer join.  Now, we wrap it in a
PlaceHolderVar and arrange for the actual evaluation to occur below the outer
join.  When the resulting Var bubbles up through the join, it will be set to
NULL if necessary, yielding the correct results.  This fixes a planner
limitation that's existed since 7.1.

In future we might want to use this mechanism to re-introduce some form of
Hellerstein's "expensive functions" optimization, ie place the evaluation of
an expensive function at the most suitable point in the plan tree.
28 files changed:
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/nodeFuncs.c
src/backend/nodes/outfuncs.c
src/backend/optimizer/path/allpaths.c
src/backend/optimizer/path/costsize.c
src/backend/optimizer/path/equivclass.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/initsplan.c
src/backend/optimizer/plan/planmain.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/setrefs.c
src/backend/optimizer/plan/subselect.c
src/backend/optimizer/prep/prepjointree.c
src/backend/optimizer/prep/preptlist.c
src/backend/optimizer/prep/prepunion.c
src/backend/optimizer/util/Makefile
src/backend/optimizer/util/clauses.c
src/backend/optimizer/util/placeholder.c [new file with mode: 0644]
src/backend/optimizer/util/relnode.c
src/backend/optimizer/util/tlist.c
src/backend/optimizer/util/var.c
src/backend/rewrite/rewriteManip.c
src/backend/utils/adt/selfuncs.c
src/include/nodes/nodes.h
src/include/nodes/relation.h
src/include/optimizer/placeholder.h [new file with mode: 0644]
src/include/optimizer/var.h