diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-03-12 00:52:10 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-03-12 00:52:10 +0000 |
commit | 6eeb95f0f56bb5e8a0a9328aeec04c9e6de87272 (patch) | |
tree | 5f209c5926768472f9d4fd7210065c18831dbd9c /src/backend/parser/parse_target.c | |
parent | 66b6bf67a197db73a880d2a4d9dab05168cde8e0 (diff) | |
download | postgresql-6eeb95f0f56bb5e8a0a9328aeec04c9e6de87272.tar.gz postgresql-6eeb95f0f56bb5e8a0a9328aeec04c9e6de87272.zip |
Restructure representation of join alias variables. An explicit JOIN
now has an RTE of its own, and references to its outputs now are Vars
referencing the JOIN RTE, rather than CASE-expressions. This allows
reverse-listing in ruleutils.c to use the correct alias easily, rather
than painfully reverse-engineering the alias namespace as it used to do.
Also, nested FULL JOINs work correctly, because the result of the inner
joins are simple Vars that the planner can cope with. This fixes a bug
reported a couple times now, notably by Tatsuo on 18-Nov-01. The alias
Vars are expanded into COALESCE expressions where needed at the very end
of planning, rather than during parsing.
Also, beginnings of support for showing plan qualifier expressions in
EXPLAIN. There are probably still cases that need work.
initdb forced due to change of stored-rule representation.
Diffstat (limited to 'src/backend/parser/parse_target.c')
-rw-r--r-- | src/backend/parser/parse_target.c | 66 |
1 files changed, 24 insertions, 42 deletions
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index bb398a7068f..f5791298f31 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -8,12 +8,13 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.76 2001/11/05 17:46:26 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.77 2002/03/12 00:51:56 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" + #include "nodes/makefuncs.h" #include "parser/parsetree.h" #include "parser/parse_coerce.h" @@ -118,30 +119,16 @@ transformTargetList(ParseState *pstate, List *targetlist) * Target item is relation.*, expand that table (eg. * SELECT emp.*, dname FROM emp, dept) */ - Node *rteorjoin; + RangeTblEntry *rte; int sublevels_up; - rteorjoin = refnameRangeOrJoinEntry(pstate, att->relname, - &sublevels_up); - - if (rteorjoin == NULL) - { - rteorjoin = (Node *) addImplicitRTE(pstate, att->relname); - sublevels_up = 0; - } + rte = refnameRangeTblEntry(pstate, att->relname, + &sublevels_up); + if (rte == NULL) + rte = addImplicitRTE(pstate, att->relname); - if (IsA(rteorjoin, RangeTblEntry)) - p_target = nconc(p_target, - expandRelAttrs(pstate, - (RangeTblEntry *) rteorjoin)); - else if (IsA(rteorjoin, JoinExpr)) - p_target = nconc(p_target, - expandJoinAttrs(pstate, - (JoinExpr *) rteorjoin, - sublevels_up)); - else - elog(ERROR, "transformTargetList: unexpected node type %d", - nodeTag(rteorjoin)); + p_target = nconc(p_target, + expandRelAttrs(pstate, rte)); } else { @@ -405,34 +392,29 @@ ExpandAllTables(ParseState *pstate) foreach(ns, pstate->p_namespace) { Node *n = (Node *) lfirst(ns); + RangeTblEntry *rte; if (IsA(n, RangeTblRef)) - { - RangeTblEntry *rte; - rte = rt_fetch(((RangeTblRef *) n)->rtindex, pstate->p_rtable); - - /* - * Ignore added-on relations that were not listed in the FROM - * clause. - */ - if (!rte->inFromCl) - continue; - - target = nconc(target, expandRelAttrs(pstate, rte)); - } else if (IsA(n, JoinExpr)) - { - /* A newfangled join expression */ - JoinExpr *j = (JoinExpr *) n; - - /* Currently, a join expr could only have come from FROM. */ - target = nconc(target, expandJoinAttrs(pstate, j, 0)); - } + rte = rt_fetch(((JoinExpr *) n)->rtindex, + pstate->p_rtable); else + { elog(ERROR, "ExpandAllTables: unexpected node (internal error)" "\n\t%s", nodeToString(n)); + rte = NULL; /* keep compiler quiet */ + } + + /* + * Ignore added-on relations that were not listed in the FROM + * clause. + */ + if (!rte->inFromCl) + continue; + + target = nconc(target, expandRelAttrs(pstate, rte)); } /* Check for SELECT *; */ |