summaryrefslogtreecommitdiff
path: root/src/backend/nodes/copyfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-10-21 20:42:53 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-10-21 20:42:53 +0000
commite6ae3b5dbf2c07bceb737c5a0ff199b1156051d1 (patch)
treeb8616c6b889741b53c282574195fc41317778dfd /src/backend/nodes/copyfuncs.c
parent831abae5061b98b7f203a24af7badeaaeb15808f (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/nodes/copyfuncs.c')
-rw-r--r--src/backend/nodes/copyfuncs.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index f0a49155024..2dce7bab18f 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -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 $
*
*-------------------------------------------------------------------------
*/
@@ -1593,6 +1593,22 @@ _copyFlattenedSubLink(FlattenedSubLink *from)
}
/*
+ * _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
*/
static SpecialJoinInfo *
@@ -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