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/parser/parse_relation.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/parser/parse_relation.c')
-rw-r--r-- | src/backend/parser/parse_relation.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 9b386cb6366..b822a2378ba 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.67 2002/04/02 08:51:51 inoue Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.68 2002/04/28 19:54:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -681,10 +681,7 @@ RangeTblEntry * addRangeTableEntryForJoin(ParseState *pstate, List *colnames, JoinType jointype, - List *coltypes, - List *coltypmods, - List *leftcols, - List *rightcols, + List *aliasvars, Alias *alias, bool inFromCl) { @@ -696,10 +693,7 @@ addRangeTableEntryForJoin(ParseState *pstate, rte->relid = InvalidOid; rte->subquery = NULL; rte->jointype = jointype; - rte->joincoltypes = coltypes; - rte->joincoltypmods = coltypmods; - rte->joinleftcols = leftcols; - rte->joinrightcols = rightcols; + rte->joinaliasvars = aliasvars; rte->alias = alias; eref = alias ? (Alias *) copyObject(alias) : makeAlias("unnamed_join", NIL); @@ -922,13 +916,12 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte, { /* Join RTE */ List *aliasp = rte->eref->colnames; - List *coltypes = rte->joincoltypes; - List *coltypmods = rte->joincoltypmods; + List *aliasvars = rte->joinaliasvars; varattno = 0; while (aliasp) { - Assert(coltypes && coltypmods); + Assert(aliasvars); varattno++; if (colnames) @@ -940,21 +933,21 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte, if (colvars) { + Node *aliasvar = (Node *) lfirst(aliasvars); Var *varnode; varnode = makeVar(rtindex, varattno, - (Oid) lfirsti(coltypes), - (int32) lfirsti(coltypmods), + exprType(aliasvar), + exprTypmod(aliasvar), sublevels_up); *colvars = lappend(*colvars, varnode); } aliasp = lnext(aliasp); - coltypes = lnext(coltypes); - coltypmods = lnext(coltypmods); + aliasvars = lnext(aliasvars); } - Assert(coltypes == NIL && coltypmods == NIL); + Assert(aliasvars == NIL); } else elog(ERROR, "expandRTE: unsupported RTE kind %d", @@ -1091,10 +1084,13 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum, } else if (rte->rtekind == RTE_JOIN) { - /* Join RTE --- get type info directly from join RTE */ - Assert(attnum > 0 && attnum <= length(rte->joincoltypes)); - *vartype = (Oid) nthi(attnum-1, rte->joincoltypes); - *vartypmod = nthi(attnum-1, rte->joincoltypmods); + /* Join RTE --- get type info from join RTE's alias variable */ + Node *aliasvar; + + Assert(attnum > 0 && attnum <= length(rte->joinaliasvars)); + aliasvar = (Node *) nth(attnum-1, rte->joinaliasvars); + *vartype = exprType(aliasvar); + *vartypmod = exprTypmod(aliasvar); } else elog(ERROR, "get_rte_attribute_type: unsupported RTE kind %d", |