mirror of
https://github.com/postgres/postgres.git
synced 2025-07-15 19:21:59 +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/util/relnode.c,v 1.91 2008/10/04 21:56:53 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.92 2008/10/21 20:42:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -17,6 +17,7 @@
|
||||
#include "optimizer/cost.h"
|
||||
#include "optimizer/pathnode.h"
|
||||
#include "optimizer/paths.h"
|
||||
#include "optimizer/placeholder.h"
|
||||
#include "optimizer/plancat.h"
|
||||
#include "optimizer/restrictinfo.h"
|
||||
#include "parser/parsetree.h"
|
||||
@ -354,6 +355,7 @@ build_join_rel(PlannerInfo *root,
|
||||
*/
|
||||
build_joinrel_tlist(root, joinrel, outer_rel);
|
||||
build_joinrel_tlist(root, joinrel, inner_rel);
|
||||
add_placeholders_to_joinrel(root, joinrel);
|
||||
|
||||
/*
|
||||
* Construct restrict and join clause lists for the new joinrel. (The
|
||||
@ -403,7 +405,8 @@ build_join_rel(PlannerInfo *root,
|
||||
|
||||
/*
|
||||
* build_joinrel_tlist
|
||||
* Builds a join relation's target list.
|
||||
* Builds a join relation's target list from an input relation.
|
||||
* (This is invoked twice to handle the two input relations.)
|
||||
*
|
||||
* The join's targetlist includes all Vars of its member relations that
|
||||
* will still be needed above the join. This subroutine adds all such
|
||||
@ -421,16 +424,23 @@ build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel,
|
||||
|
||||
foreach(vars, input_rel->reltargetlist)
|
||||
{
|
||||
Var *origvar = (Var *) lfirst(vars);
|
||||
Node *origvar = (Node *) lfirst(vars);
|
||||
Var *var;
|
||||
RelOptInfo *baserel;
|
||||
int ndx;
|
||||
|
||||
/*
|
||||
* Ignore PlaceHolderVars in the input tlists; we'll make our
|
||||
* own decisions about whether to copy them.
|
||||
*/
|
||||
if (IsA(origvar, PlaceHolderVar))
|
||||
continue;
|
||||
|
||||
/*
|
||||
* We can't run into any child RowExprs here, but we could find a
|
||||
* whole-row Var with a ConvertRowtypeExpr atop it.
|
||||
*/
|
||||
var = origvar;
|
||||
var = (Var *) origvar;
|
||||
while (!IsA(var, Var))
|
||||
{
|
||||
if (IsA(var, ConvertRowtypeExpr))
|
||||
|
Reference in New Issue
Block a user