mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +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:
28
src/include/optimizer/placeholder.h
Normal file
28
src/include/optimizer/placeholder.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* placeholder.h
|
||||
* prototypes for optimizer/util/placeholder.c.
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/optimizer/placeholder.h,v 1.1 2008/10/21 20:42:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef PLACEHOLDER_H
|
||||
#define PLACEHOLDER_H
|
||||
|
||||
#include "nodes/relation.h"
|
||||
|
||||
|
||||
extern PlaceHolderVar *make_placeholder_expr(PlannerInfo *root, Expr *expr,
|
||||
Relids phrels);
|
||||
extern PlaceHolderInfo *find_placeholder_info(PlannerInfo *root,
|
||||
PlaceHolderVar *phv);
|
||||
extern void fix_placeholder_eval_levels(PlannerInfo *root);
|
||||
extern void add_placeholders_to_joinrel(PlannerInfo *root,
|
||||
RelOptInfo *joinrel);
|
||||
|
||||
#endif /* PLACEHOLDER_H */
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/optimizer/var.h,v 1.38 2008/09/01 20:42:45 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/optimizer/var.h,v 1.39 2008/10/21 20:42:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -24,7 +24,7 @@ extern bool contain_vars_of_level(Node *node, int levelsup);
|
||||
extern int locate_var_of_level(Node *node, int levelsup);
|
||||
extern int locate_var_of_relation(Node *node, int relid, int levelsup);
|
||||
extern int find_minimum_var_level(Node *node);
|
||||
extern List *pull_var_clause(Node *node, bool includeUpperVars);
|
||||
extern List *pull_var_clause(Node *node, bool includePlaceHolderVars);
|
||||
extern Node *flatten_join_alias_vars(PlannerInfo *root, Node *node);
|
||||
|
||||
#endif /* VAR_H */
|
||||
|
||||
Reference in New Issue
Block a user