mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +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/plan/planner.c,v 1.244 2008/10/04 21:56:53 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.245 2008/10/21 20:42:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -55,7 +55,7 @@ planner_hook_type planner_hook = NULL;
|
||||
#define EXPRKIND_RTFUNC 2
|
||||
#define EXPRKIND_VALUES 3
|
||||
#define EXPRKIND_LIMIT 4
|
||||
#define EXPRKIND_APPINFO 5
|
||||
#define EXPRKIND_AUXINFO 5
|
||||
|
||||
|
||||
static Node *preprocess_expression(PlannerInfo *root, Node *expr, int kind);
|
||||
@ -141,6 +141,7 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
|
||||
glob->finalrtable = NIL;
|
||||
glob->relationOids = NIL;
|
||||
glob->invalItems = NIL;
|
||||
glob->lastPHId = 0;
|
||||
glob->transientPlan = false;
|
||||
|
||||
/* Determine what fraction of the plan is likely to be scanned */
|
||||
@ -273,6 +274,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
|
||||
root->cte_plan_ids = NIL;
|
||||
root->eq_classes = NIL;
|
||||
root->append_rel_list = NIL;
|
||||
root->placeholder_list = NIL;
|
||||
|
||||
root->hasRecursion = hasRecursion;
|
||||
if (hasRecursion)
|
||||
@ -378,7 +380,10 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
|
||||
|
||||
root->append_rel_list = (List *)
|
||||
preprocess_expression(root, (Node *) root->append_rel_list,
|
||||
EXPRKIND_APPINFO);
|
||||
EXPRKIND_AUXINFO);
|
||||
root->placeholder_list = (List *)
|
||||
preprocess_expression(root, (Node *) root->placeholder_list,
|
||||
EXPRKIND_AUXINFO);
|
||||
|
||||
/* Also need to preprocess expressions for function and values RTEs */
|
||||
foreach(l, parse->rtable)
|
||||
@ -656,7 +661,12 @@ inheritance_planner(PlannerInfo *root)
|
||||
subroot.parse = (Query *)
|
||||
adjust_appendrel_attrs((Node *) parse,
|
||||
appinfo);
|
||||
subroot.returningLists = NIL;
|
||||
subroot.init_plans = NIL;
|
||||
/* We needn't modify the child's append_rel_list */
|
||||
subroot.placeholder_list = (List *)
|
||||
adjust_appendrel_attrs((Node *) root->placeholder_list,
|
||||
appinfo);
|
||||
/* There shouldn't be any OJ info to translate, as yet */
|
||||
Assert(subroot.join_info_list == NIL);
|
||||
|
||||
@ -2046,7 +2056,7 @@ make_subplanTargetList(PlannerInfo *root,
|
||||
* Vars; they will be replaced by Params later on).
|
||||
*/
|
||||
sub_tlist = flatten_tlist(tlist);
|
||||
extravars = pull_var_clause(parse->havingQual, false);
|
||||
extravars = pull_var_clause(parse->havingQual, true);
|
||||
sub_tlist = add_to_flat_tlist(sub_tlist, extravars);
|
||||
list_free(extravars);
|
||||
*need_tlist_eval = false; /* only eval if not flat tlist */
|
||||
|
Reference in New Issue
Block a user