mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
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.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.174 2008/10/04 21:56:53 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.175 2008/10/21 20:42:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -423,6 +423,10 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
|
||||
Var *parentvar = (Var *) lfirst(parentvars);
|
||||
Var *childvar = (Var *) lfirst(childvars);
|
||||
|
||||
/*
|
||||
* Accumulate per-column estimates too. Whole-row Vars and
|
||||
* PlaceHolderVars can be ignored here.
|
||||
*/
|
||||
if (IsA(parentvar, Var) &&
|
||||
IsA(childvar, Var))
|
||||
{
|
||||
@ -1105,12 +1109,25 @@ qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
|
||||
* Examine all Vars used in clause; since it's a restriction clause, all
|
||||
* such Vars must refer to subselect output columns.
|
||||
*/
|
||||
vars = pull_var_clause(qual, false);
|
||||
vars = pull_var_clause(qual, true);
|
||||
foreach(vl, vars)
|
||||
{
|
||||
Var *var = (Var *) lfirst(vl);
|
||||
TargetEntry *tle;
|
||||
|
||||
/*
|
||||
* XXX Punt if we find any PlaceHolderVars in the restriction clause.
|
||||
* It's not clear whether a PHV could safely be pushed down, and even
|
||||
* less clear whether such a situation could arise in any cases of
|
||||
* practical interest anyway. So for the moment, just refuse to push
|
||||
* down.
|
||||
*/
|
||||
if (!IsA(var, Var))
|
||||
{
|
||||
safe = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Assert(var->varno == rti);
|
||||
|
||||
/* Check point 2 */
|
||||
|
Reference in New Issue
Block a user