1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-31 17:02:12 +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:
Tom Lane
2008-10-21 20:42:53 +00:00
parent 831abae506
commit e6ae3b5dbf
28 changed files with 1135 additions and 226 deletions

View File

@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.408 2008/10/07 19:27:04 tgl Exp $
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.409 2008/10/21 20:42:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1592,6 +1592,22 @@ _copyFlattenedSubLink(FlattenedSubLink *from)
return newnode;
}
/*
* _copyPlaceHolderVar
*/
static PlaceHolderVar *
_copyPlaceHolderVar(PlaceHolderVar *from)
{
PlaceHolderVar *newnode = makeNode(PlaceHolderVar);
COPY_NODE_FIELD(phexpr);
COPY_BITMAPSET_FIELD(phrels);
COPY_SCALAR_FIELD(phid);
COPY_SCALAR_FIELD(phlevelsup);
return newnode;
}
/*
* _copySpecialJoinInfo
*/
@@ -1631,6 +1647,23 @@ _copyAppendRelInfo(AppendRelInfo *from)
return newnode;
}
/*
* _copyPlaceHolderInfo
*/
static PlaceHolderInfo *
_copyPlaceHolderInfo(PlaceHolderInfo *from)
{
PlaceHolderInfo *newnode = makeNode(PlaceHolderInfo);
COPY_SCALAR_FIELD(phid);
COPY_NODE_FIELD(ph_var);
COPY_BITMAPSET_FIELD(ph_eval_at);
COPY_BITMAPSET_FIELD(ph_needed);
COPY_SCALAR_FIELD(ph_width);
return newnode;
}
/* ****************************************************************
* parsenodes.h copy functions
* ****************************************************************
@@ -3438,12 +3471,18 @@ copyObject(void *from)
case T_FlattenedSubLink:
retval = _copyFlattenedSubLink(from);
break;
case T_PlaceHolderVar:
retval = _copyPlaceHolderVar(from);
break;
case T_SpecialJoinInfo:
retval = _copySpecialJoinInfo(from);
break;
case T_AppendRelInfo:
retval = _copyAppendRelInfo(from);
break;
case T_PlaceHolderInfo:
retval = _copyPlaceHolderInfo(from);
break;
/*
* VALUE NODES