summaryrefslogtreecommitdiff
path: root/src/backend/nodes/outfuncs.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/outfuncs.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/outfuncs.c')
-rw-r--r--src/backend/nodes/outfuncs.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 75a04ce2fa1..d1130760f9e 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.342 2008/10/07 19:27:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.343 2008/10/21 20:42:52 tgl Exp $
*
* NOTES
* Every node type that can appear in stored rules' parsetrees *must*
@@ -1412,6 +1412,8 @@ _outPlannerGlobal(StringInfo str, PlannerGlobal *node)
WRITE_NODE_FIELD(finalrtable);
WRITE_NODE_FIELD(relationOids);
WRITE_NODE_FIELD(invalItems);
+ WRITE_UINT_FIELD(lastPHId);
+ WRITE_BOOL_FIELD(transientPlan);
}
static void
@@ -1435,6 +1437,7 @@ _outPlannerInfo(StringInfo str, PlannerInfo *node)
WRITE_NODE_FIELD(full_join_clauses);
WRITE_NODE_FIELD(join_info_list);
WRITE_NODE_FIELD(append_rel_list);
+ WRITE_NODE_FIELD(placeholder_list);
WRITE_NODE_FIELD(query_pathkeys);
WRITE_NODE_FIELD(group_pathkeys);
WRITE_NODE_FIELD(distinct_pathkeys);
@@ -1591,6 +1594,17 @@ _outFlattenedSubLink(StringInfo str, FlattenedSubLink *node)
}
static void
+_outPlaceHolderVar(StringInfo str, PlaceHolderVar *node)
+{
+ WRITE_NODE_TYPE("PLACEHOLDERVAR");
+
+ WRITE_NODE_FIELD(phexpr);
+ WRITE_BITMAPSET_FIELD(phrels);
+ WRITE_UINT_FIELD(phid);
+ WRITE_UINT_FIELD(phlevelsup);
+}
+
+static void
_outSpecialJoinInfo(StringInfo str, SpecialJoinInfo *node)
{
WRITE_NODE_TYPE("SPECIALJOININFO");
@@ -1620,6 +1634,18 @@ _outAppendRelInfo(StringInfo str, AppendRelInfo *node)
}
static void
+_outPlaceHolderInfo(StringInfo str, PlaceHolderInfo *node)
+{
+ WRITE_NODE_TYPE("PLACEHOLDERINFO");
+
+ WRITE_UINT_FIELD(phid);
+ WRITE_NODE_FIELD(ph_var);
+ WRITE_BITMAPSET_FIELD(ph_eval_at);
+ WRITE_BITMAPSET_FIELD(ph_needed);
+ WRITE_INT_FIELD(ph_width);
+}
+
+static void
_outPlannerParamItem(StringInfo str, PlannerParamItem *node)
{
WRITE_NODE_TYPE("PLANNERPARAMITEM");
@@ -2539,12 +2565,18 @@ _outNode(StringInfo str, void *obj)
case T_FlattenedSubLink:
_outFlattenedSubLink(str, obj);
break;
+ case T_PlaceHolderVar:
+ _outPlaceHolderVar(str, obj);
+ break;
case T_SpecialJoinInfo:
_outSpecialJoinInfo(str, obj);
break;
case T_AppendRelInfo:
_outAppendRelInfo(str, obj);
break;
+ case T_PlaceHolderInfo:
+ _outPlaceHolderInfo(str, obj);
+ break;
case T_PlannerParamItem:
_outPlannerParamItem(str, obj);
break;