mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
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.
This commit is contained in:
@ -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);
|
||||
rte = refnameRangeTblEntry(pstate, att->relname,
|
||||
&sublevels_up);
|
||||
if (rte == NULL)
|
||||
rte = addImplicitRTE(pstate, att->relname);
|
||||
|
||||
if (rteorjoin == NULL)
|
||||
{
|
||||
rteorjoin = (Node *) addImplicitRTE(pstate, att->relname);
|
||||
sublevels_up = 0;
|
||||
}
|
||||
|
||||
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 *; */
|
||||
|
Reference in New Issue
Block a user