diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-10-21 20:42:53 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-10-21 20:42:53 +0000 |
commit | e6ae3b5dbf2c07bceb737c5a0ff199b1156051d1 (patch) | |
tree | b8616c6b889741b53c282574195fc41317778dfd /src/backend/optimizer/plan/subselect.c | |
parent | 831abae5061b98b7f203a24af7badeaaeb15808f (diff) |
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.
Diffstat (limited to 'src/backend/optimizer/plan/subselect.c')
-rw-r--r-- | src/backend/optimizer/plan/subselect.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index 00d84d56823..b80427f041e 100644 --- a/src/backend/optimizer/plan/subselect.c +++ b/src/backend/optimizer/plan/subselect.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.141 2008/10/04 21:56:53 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.142 2008/10/21 20:42:53 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1040,6 +1040,10 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink, /* * And finally, build the FlattenedSubLink node. + * + * Note: at this point left_varnos may well contain join relids, since + * the testexpr hasn't been run through flatten_join_alias_vars. This + * will get fixed when flatten_join_alias_vars is run. */ fslink = makeNode(FlattenedSubLink); fslink->jointype = JOIN_SEMI; @@ -1189,6 +1193,9 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink, /* * And finally, build the FlattenedSubLink node. + * + * Note: at this point left_varnos and subselect_varnos may well contain + * join relids. This will get fixed when flatten_join_alias_vars is run. */ fslink = makeNode(FlattenedSubLink); fslink->jointype = under_not ? JOIN_ANTI : JOIN_SEMI; |