diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-04-28 19:54:29 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-04-28 19:54:29 +0000 |
commit | 6c5988694218a62c6bc90fc625cbc64f732520cc (patch) | |
tree | cdc64472760a6ecbf73e2334bf23ae0767bf2f21 /src/backend/optimizer/plan/setrefs.c | |
parent | c8996f9c6bd82765849da85a9cde5de27f8cae79 (diff) | |
download | postgresql-6c5988694218a62c6bc90fc625cbc64f732520cc.tar.gz postgresql-6c5988694218a62c6bc90fc625cbc64f732520cc.zip |
Second try at fixing join alias variables. Instead of attaching miscellaneous
lists to join RTEs, attach a list of Vars and COALESCE expressions that will
replace the join's alias variables during planning. This simplifies
flatten_join_alias_vars while still making it easy to fix up varno references
when transforming the query tree. Add regression test cases for interactions
of subqueries with outer joins.
Diffstat (limited to 'src/backend/optimizer/plan/setrefs.c')
-rw-r--r-- | src/backend/optimizer/plan/setrefs.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index 2f48821ece6..807876e4a72 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.74 2002/03/12 00:51:48 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.75 2002/04/28 19:54:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -31,7 +31,6 @@ typedef struct List *outer_tlist; List *inner_tlist; Index acceptable_rel; - Index join_rti; } join_references_context; typedef struct @@ -271,8 +270,7 @@ set_join_references(Query *root, Join *join) root, outer_tlist, inner_tlist, - (Index) 0, - join->joinrti); + (Index) 0); } /* @@ -367,8 +365,6 @@ set_uppernode_references(Plan *plan, Index subvarno) * 'inner_tlist' is the target list of the inner join relation, or NIL * 'acceptable_rel' is either zero or the rangetable index of a relation * whose Vars may appear in the clause without provoking an error. - * 'join_rti' is either zero or the join RTE index of join alias variables - * that should be expanded. * * Returns the new expression tree. The original clause structure is * not modified. @@ -378,8 +374,7 @@ join_references(List *clauses, Query *root, List *outer_tlist, List *inner_tlist, - Index acceptable_rel, - Index join_rti) + Index acceptable_rel) { join_references_context context; @@ -387,7 +382,6 @@ join_references(List *clauses, context.outer_tlist = outer_tlist; context.inner_tlist = inner_tlist; context.acceptable_rel = acceptable_rel; - context.join_rti = join_rti; return (List *) join_references_mutator((Node *) clauses, &context); } @@ -401,6 +395,7 @@ join_references_mutator(Node *node, { Var *var = (Var *) node; Resdom *resdom; + Node *newnode; /* First look for the var in the input tlists */ resdom = tlist_member((Node *) var, context->outer_tlist); @@ -423,13 +418,11 @@ join_references_mutator(Node *node, } /* Perhaps it's a join alias that can be resolved to input vars? */ - if (var->varno == context->join_rti) + newnode = flatten_join_alias_vars((Node *) var, + context->root, + true); + if (!equal(newnode, (Node *) var)) { - Node *newnode; - - newnode = flatten_join_alias_vars((Node *) var, - context->root, - context->join_rti); /* Must now resolve the input vars... */ newnode = join_references_mutator(newnode, context); return newnode; |