mirror of
https://github.com/postgres/postgres.git
synced 2025-08-24 09:27:52 +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:
@@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.168 2002/03/08 04:37:16 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.169 2002/03/12 00:51:37 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -323,6 +323,7 @@ CopyJoinFields(Join *from, Join *newnode)
|
||||
{
|
||||
newnode->jointype = from->jointype;
|
||||
Node_Copy(from, newnode, joinqual);
|
||||
newnode->joinrti = from->joinrti;
|
||||
/* subPlan list must point to subplans in the new subtree, not the old */
|
||||
if (from->plan.subPlan != NIL)
|
||||
newnode->plan.subPlan = nconc(newnode->plan.subPlan,
|
||||
@@ -970,8 +971,7 @@ _copyJoinExpr(JoinExpr *from)
|
||||
Node_Copy(from, newnode, using);
|
||||
Node_Copy(from, newnode, quals);
|
||||
Node_Copy(from, newnode, alias);
|
||||
Node_Copy(from, newnode, colnames);
|
||||
Node_Copy(from, newnode, colvars);
|
||||
newnode->rtindex = from->rtindex;
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@@ -1081,16 +1081,13 @@ _copyArrayRef(ArrayRef *from)
|
||||
* _copyRelOptInfo
|
||||
* ----------------
|
||||
*/
|
||||
/*
|
||||
* when you change this, also make sure to fix up xfunc_copyRelOptInfo in
|
||||
* planner/path/xfunc.c accordingly!!!
|
||||
* -- JMH, 8/2/93
|
||||
*/
|
||||
static RelOptInfo *
|
||||
_copyRelOptInfo(RelOptInfo *from)
|
||||
{
|
||||
RelOptInfo *newnode = makeNode(RelOptInfo);
|
||||
|
||||
newnode->reloptkind = from->reloptkind;
|
||||
|
||||
newnode->relids = listCopy(from->relids);
|
||||
|
||||
newnode->rows = from->rows;
|
||||
@@ -1109,6 +1106,9 @@ _copyRelOptInfo(RelOptInfo *from)
|
||||
newnode->tuples = from->tuples;
|
||||
Node_Copy(from, newnode, subplan);
|
||||
|
||||
newnode->joinrti = from->joinrti;
|
||||
newnode->joinrteids = listCopy(from->joinrteids);
|
||||
|
||||
Node_Copy(from, newnode, baserestrictinfo);
|
||||
newnode->baserestrictcost = from->baserestrictcost;
|
||||
newnode->outerjoinset = listCopy(from->outerjoinset);
|
||||
@@ -1487,10 +1487,16 @@ _copyRangeTblEntry(RangeTblEntry *from)
|
||||
{
|
||||
RangeTblEntry *newnode = makeNode(RangeTblEntry);
|
||||
|
||||
newnode->rtekind = from->rtekind;
|
||||
if (from->relname)
|
||||
newnode->relname = pstrdup(from->relname);
|
||||
newnode->relid = from->relid;
|
||||
Node_Copy(from, newnode, subquery);
|
||||
newnode->jointype = from->jointype;
|
||||
newnode->joincoltypes = listCopy(from->joincoltypes);
|
||||
newnode->joincoltypmods = listCopy(from->joincoltypmods);
|
||||
newnode->joinleftcols = listCopy(from->joinleftcols);
|
||||
newnode->joinrightcols = listCopy(from->joinrightcols);
|
||||
Node_Copy(from, newnode, alias);
|
||||
Node_Copy(from, newnode, eref);
|
||||
newnode->inh = from->inh;
|
||||
|
@@ -20,7 +20,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.116 2002/03/08 04:37:16 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.117 2002/03/12 00:51:37 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -335,9 +335,7 @@ _equalJoinExpr(JoinExpr *a, JoinExpr *b)
|
||||
return false;
|
||||
if (!equal(a->alias, b->alias))
|
||||
return false;
|
||||
if (!equal(a->colnames, b->colnames))
|
||||
return false;
|
||||
if (!equal(a->colvars, b->colvars))
|
||||
if (a->rtindex != b->rtindex)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -1639,12 +1637,24 @@ _equalTargetEntry(TargetEntry *a, TargetEntry *b)
|
||||
static bool
|
||||
_equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
|
||||
{
|
||||
if (a->rtekind != b->rtekind)
|
||||
return false;
|
||||
if (!equalstr(a->relname, b->relname))
|
||||
return false;
|
||||
if (a->relid != b->relid)
|
||||
return false;
|
||||
if (!equal(a->subquery, b->subquery))
|
||||
return false;
|
||||
if (a->jointype != b->jointype)
|
||||
return false;
|
||||
if (!equali(a->joincoltypes, b->joincoltypes))
|
||||
return false;
|
||||
if (!equali(a->joincoltypmods, b->joincoltypmods))
|
||||
return false;
|
||||
if (!equali(a->joinleftcols, b->joinleftcols))
|
||||
return false;
|
||||
if (!equali(a->joinrightcols, b->joinrightcols))
|
||||
return false;
|
||||
if (!equal(a->alias, b->alias))
|
||||
return false;
|
||||
if (!equal(a->eref, b->eref))
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.148 2002/03/06 06:09:49 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.149 2002/03/12 00:51:39 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every (plan) node in POSTGRES has an associated "out" routine which
|
||||
@@ -410,6 +410,8 @@ _outJoin(StringInfo str, Join *node)
|
||||
appendStringInfo(str, " :jointype %d :joinqual ",
|
||||
(int) node->jointype);
|
||||
_outNode(str, node->joinqual);
|
||||
appendStringInfo(str, " :joinrti %d ",
|
||||
node->joinrti);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -423,6 +425,8 @@ _outNestLoop(StringInfo str, NestLoop *node)
|
||||
appendStringInfo(str, " :jointype %d :joinqual ",
|
||||
(int) node->join.jointype);
|
||||
_outNode(str, node->join.joinqual);
|
||||
appendStringInfo(str, " :joinrti %d ",
|
||||
node->join.joinrti);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -436,6 +440,8 @@ _outMergeJoin(StringInfo str, MergeJoin *node)
|
||||
appendStringInfo(str, " :jointype %d :joinqual ",
|
||||
(int) node->join.jointype);
|
||||
_outNode(str, node->join.joinqual);
|
||||
appendStringInfo(str, " :joinrti %d ",
|
||||
node->join.joinrti);
|
||||
|
||||
appendStringInfo(str, " :mergeclauses ");
|
||||
_outNode(str, node->mergeclauses);
|
||||
@@ -452,6 +458,8 @@ _outHashJoin(StringInfo str, HashJoin *node)
|
||||
appendStringInfo(str, " :jointype %d :joinqual ",
|
||||
(int) node->join.jointype);
|
||||
_outNode(str, node->join.joinqual);
|
||||
appendStringInfo(str, " :joinrti %d ",
|
||||
node->join.joinrti);
|
||||
|
||||
appendStringInfo(str, " :hashclauses ");
|
||||
_outNode(str, node->hashclauses);
|
||||
@@ -939,10 +947,7 @@ _outJoinExpr(StringInfo str, JoinExpr *node)
|
||||
_outNode(str, node->quals);
|
||||
appendStringInfo(str, " :alias ");
|
||||
_outNode(str, node->alias);
|
||||
appendStringInfo(str, " :colnames ");
|
||||
_outNode(str, node->colnames);
|
||||
appendStringInfo(str, " :colvars ");
|
||||
_outNode(str, node->colvars);
|
||||
appendStringInfo(str, " :rtindex %d ", node->rtindex);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -961,12 +966,21 @@ _outTargetEntry(StringInfo str, TargetEntry *node)
|
||||
static void
|
||||
_outRangeTblEntry(StringInfo str, RangeTblEntry *node)
|
||||
{
|
||||
appendStringInfo(str, " RTE :relname ");
|
||||
appendStringInfo(str, " RTE :rtekind %d :relname ",
|
||||
(int) node->rtekind);
|
||||
_outToken(str, node->relname);
|
||||
appendStringInfo(str, " :relid %u ",
|
||||
appendStringInfo(str, " :relid %u :subquery ",
|
||||
node->relid);
|
||||
appendStringInfo(str, " :subquery ");
|
||||
_outNode(str, node->subquery);
|
||||
appendStringInfo(str, " :jointype %d :joincoltypes ",
|
||||
(int) node->jointype);
|
||||
_outOidList(str, node->joincoltypes);
|
||||
appendStringInfo(str, " :joincoltypmods ");
|
||||
_outIntList(str, node->joincoltypmods);
|
||||
appendStringInfo(str, " :joinleftcols ");
|
||||
_outIntList(str, node->joinleftcols);
|
||||
appendStringInfo(str, " :joinrightcols ");
|
||||
_outIntList(str, node->joinrightcols);
|
||||
appendStringInfo(str, " :alias ");
|
||||
_outNode(str, node->alias);
|
||||
appendStringInfo(str, " :eref ");
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.115 2002/03/01 06:01:18 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.116 2002/03/12 00:51:39 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Most of the read functions for plan nodes are tested. (In fact, they
|
||||
@@ -421,6 +421,10 @@ _getJoin(Join *node)
|
||||
|
||||
token = pg_strtok(&length); /* skip the :joinqual */
|
||||
node->joinqual = nodeRead(true); /* get the joinqual */
|
||||
|
||||
token = pg_strtok(&length); /* skip the :joinrti */
|
||||
token = pg_strtok(&length); /* get the joinrti */
|
||||
node->joinrti = atoi(token);
|
||||
}
|
||||
|
||||
|
||||
@@ -1343,7 +1347,7 @@ _readJoinExpr(void)
|
||||
local_node->jointype = (JoinType) atoi(token);
|
||||
|
||||
token = pg_strtok(&length); /* eat :isNatural */
|
||||
token = pg_strtok(&length); /* get :isNatural */
|
||||
token = pg_strtok(&length); /* get isNatural */
|
||||
local_node->isNatural = strtobool(token);
|
||||
|
||||
token = pg_strtok(&length); /* eat :larg */
|
||||
@@ -1361,11 +1365,9 @@ _readJoinExpr(void)
|
||||
token = pg_strtok(&length); /* eat :alias */
|
||||
local_node->alias = nodeRead(true); /* now read it */
|
||||
|
||||
token = pg_strtok(&length); /* eat :colnames */
|
||||
local_node->colnames = nodeRead(true); /* now read it */
|
||||
|
||||
token = pg_strtok(&length); /* eat :colvars */
|
||||
local_node->colvars = nodeRead(true); /* now read it */
|
||||
token = pg_strtok(&length); /* eat :rtindex */
|
||||
token = pg_strtok(&length); /* get rtindex */
|
||||
local_node->rtindex = atoi(token);
|
||||
|
||||
return local_node;
|
||||
}
|
||||
@@ -1424,6 +1426,10 @@ _readRangeTblEntry(void)
|
||||
|
||||
local_node = makeNode(RangeTblEntry);
|
||||
|
||||
token = pg_strtok(&length); /* eat :rtekind */
|
||||
token = pg_strtok(&length); /* get :rtekind */
|
||||
local_node->rtekind = (RTEKind) atoi(token);
|
||||
|
||||
token = pg_strtok(&length); /* eat :relname */
|
||||
token = pg_strtok(&length); /* get :relname */
|
||||
local_node->relname = nullable_string(token, length);
|
||||
@@ -1435,6 +1441,22 @@ _readRangeTblEntry(void)
|
||||
token = pg_strtok(&length); /* eat :subquery */
|
||||
local_node->subquery = nodeRead(true); /* now read it */
|
||||
|
||||
token = pg_strtok(&length); /* eat :jointype */
|
||||
token = pg_strtok(&length); /* get jointype */
|
||||
local_node->jointype = (JoinType) atoi(token);
|
||||
|
||||
token = pg_strtok(&length); /* eat :joincoltypes */
|
||||
local_node->joincoltypes = toOidList(nodeRead(true));
|
||||
|
||||
token = pg_strtok(&length); /* eat :joincoltypmods */
|
||||
local_node->joincoltypmods = toIntList(nodeRead(true));
|
||||
|
||||
token = pg_strtok(&length); /* eat :joinleftcols */
|
||||
local_node->joinleftcols = toIntList(nodeRead(true));
|
||||
|
||||
token = pg_strtok(&length); /* eat :joinrightcols */
|
||||
local_node->joinrightcols = toIntList(nodeRead(true));
|
||||
|
||||
token = pg_strtok(&length); /* eat :alias */
|
||||
local_node->alias = nodeRead(true); /* now read it */
|
||||
|
||||
|
Reference in New Issue
Block a user