From e6ae3b5dbf2c07bceb737c5a0ff199b1156051d1 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 21 Oct 2008 20:42:53 +0000 Subject: 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. --- src/backend/optimizer/util/tlist.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/backend/optimizer/util/tlist.c') diff --git a/src/backend/optimizer/util/tlist.c b/src/backend/optimizer/util/tlist.c index 2fd16afb5f..968f4ae367 100644 --- a/src/backend/optimizer/util/tlist.c +++ b/src/backend/optimizer/util/tlist.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.82 2008/08/25 22:42:33 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.83 2008/10/21 20:42:53 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -91,7 +91,7 @@ tlist_member_ignore_relabel(Node *node, List *targetlist) List * flatten_tlist(List *tlist) { - List *vlist = pull_var_clause((Node *) tlist, false); + List *vlist = pull_var_clause((Node *) tlist, true); List *new_tlist; new_tlist = add_to_flat_tlist(NIL, vlist); @@ -104,7 +104,7 @@ flatten_tlist(List *tlist) * Add more vars to a flattened tlist (if they're not already in it) * * 'tlist' is the flattened tlist - * 'vars' is a list of var nodes + * 'vars' is a list of Var and/or PlaceHolderVar nodes * * Returns the extended tlist. */ @@ -116,9 +116,9 @@ add_to_flat_tlist(List *tlist, List *vars) foreach(v, vars) { - Var *var = (Var *) lfirst(v); + Node *var = (Node *) lfirst(v); - if (!tlist_member((Node *) var, tlist)) + if (!tlist_member(var, tlist)) { TargetEntry *tle; -- cgit v1.2.1