1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Merge Resdom nodes into TargetEntry nodes to simplify code and save a

few palloc's.  I also chose to eliminate the restype and restypmod fields
entirely, since they are redundant with information stored in the node's
contained expression; re-examining the expression at need seems simpler
and more reliable than trying to keep restype/restypmod up to date.

initdb forced due to change in contents of stored rules.
This commit is contained in:
Tom Lane
2005-04-06 16:34:07 +00:00
parent 0f3748a28c
commit ad161bcc8a
43 changed files with 537 additions and 799 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.192 2005/03/31 22:46:09 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.193 2005/04/06 16:34:06 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@ -966,22 +966,22 @@ has_distinct_on_clause(Query *query)
{
TargetEntry *tle = (TargetEntry *) lfirst(l);
if (tle->resdom->ressortgroupref == 0)
if (tle->ressortgroupref == 0)
{
if (tle->resdom->resjunk)
if (tle->resjunk)
continue; /* we can ignore unsorted junk cols */
return true; /* definitely not in DISTINCT list */
}
if (targetIsInSortList(tle, query->distinctClause))
{
if (tle->resdom->resjunk)
if (tle->resjunk)
return true; /* junk TLE in DISTINCT means DISTINCT ON */
/* else this TLE is okay, keep looking */
}
else
{
/* This TLE is not in DISTINCT list */
if (!tle->resdom->resjunk)
if (!tle->resjunk)
return true; /* non-junk, non-DISTINCT, so DISTINCT ON */
if (targetIsInSortList(tle, query->sortClause))
return true; /* sorted, non-distinct junk */
@ -3314,10 +3314,6 @@ expression_tree_mutator(Node *node,
break;
case T_TargetEntry:
{
/*
* We mutate the expression, but not the resdom, by
* default.
*/
TargetEntry *targetentry = (TargetEntry *) node;
TargetEntry *newnode;

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.114 2005/03/27 06:29:42 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.115 2005/04/06 16:34:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -789,7 +789,7 @@ is_distinct_query(Query *query)
TargetEntry *tle = get_sortgroupclause_tle(grpcl,
query->targetList);
if (tle->resdom->resjunk)
if (tle->resjunk)
break;
}
if (!gl) /* got to the end? */

View File

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.103 2005/03/29 00:17:02 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.104 2005/04/06 16:34:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -378,6 +378,7 @@ build_physical_tlist(Query *root, RelOptInfo *rel)
for (attrno = 1; attrno <= numattrs; attrno++)
{
Form_pg_attribute att_tup = relation->rd_att->attrs[attrno - 1];
Var *var;
if (att_tup->attisdropped)
{
@ -386,13 +387,17 @@ build_physical_tlist(Query *root, RelOptInfo *rel)
break;
}
var = makeVar(varno,
attrno,
att_tup->atttypid,
att_tup->atttypmod,
0);
tlist = lappend(tlist,
create_tl_element(makeVar(varno,
attrno,
att_tup->atttypid,
att_tup->atttypmod,
0),
attrno));
makeTargetEntry((Expr *) var,
attrno,
NULL,
false));
}
heap_close(relation, AccessShareLock);

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.68 2004/12/31 22:00:23 pgsql Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.69 2005/04/06 16:34:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -25,12 +25,12 @@
*****************************************************************************/
/*
* tlistentry_member
* tlist_member
* Finds the (first) member of the given tlist whose expression is
* equal() to the given expression. Result is NULL if no such member.
*/
TargetEntry *
tlistentry_member(Node *node, List *targetlist)
tlist_member(Node *node, List *targetlist)
{
ListCell *temp;
@ -44,77 +44,6 @@ tlistentry_member(Node *node, List *targetlist)
return NULL;
}
#ifdef NOT_USED
/*
* matching_tlist_expr
* Same as tlistentry_member(), except returns the tlist expression
* rather than its parent TargetEntry node.
*/
Node *
matching_tlist_expr(Node *node, List *targetlist)
{
TargetEntry *tlentry;
tlentry = tlistentry_member(node, targetlist);
if (tlentry)
return tlentry->expr;
return NULL;
}
#endif
/*
* tlist_member
* Same as tlistentry_member(), except returns the Resdom node
* rather than its parent TargetEntry node.
*/
Resdom *
tlist_member(Node *node, List *targetlist)
{
TargetEntry *tlentry;
tlentry = tlistentry_member(node, targetlist);
if (tlentry)
return tlentry->resdom;
return NULL;
}
/*
* create_tl_element
* Creates a target list entry node and its associated (resdom var) pair
* with its resdom number equal to 'resdomno'.
*
* Note: the argument is almost always a Var, but occasionally not.
*/
TargetEntry *
create_tl_element(Var *var, int resdomno)
{
Oid vartype;
int32 vartypmod;
if (IsA(var, Var))
{
vartype = var->vartype;
vartypmod = var->vartypmod;
}
else
{
vartype = exprType((Node *) var);
vartypmod = exprTypmod((Node *) var);
}
return makeTargetEntry(makeResdom(resdomno,
vartype,
vartypmod,
NULL,
false),
(Expr *) var);
}
/*****************************************************************************
* ---------- GENERAL target list routines ----------
*****************************************************************************/
/*
* flatten_tlist
* Create a target list that only contains unique variables.
@ -153,24 +82,22 @@ flatten_tlist(List *tlist)
List *
add_to_flat_tlist(List *tlist, List *vars)
{
int next_resdomno = list_length(tlist) + 1;
int next_resno = list_length(tlist) + 1;
ListCell *v;
foreach(v, vars)
{
Var *var = (Var *) lfirst(v);
if (!tlistentry_member((Node *) var, tlist))
if (!tlist_member((Node *) var, tlist))
{
Resdom *r;
TargetEntry *tle;
r = makeResdom(next_resdomno++,
var->vartype,
var->vartypmod,
NULL,
false);
tlist = lappend(tlist,
makeTargetEntry(r, copyObject(var)));
tle = makeTargetEntry(copyObject(var), /* copy needed?? */
next_resno++,
NULL,
false);
tlist = lappend(tlist, tle);
}
}
return tlist;
@ -195,7 +122,7 @@ get_sortgroupclause_tle(SortClause *sortClause,
{
TargetEntry *tle = (TargetEntry *) lfirst(l);
if (tle->resdom->ressortgroupref == refnumber)
if (tle->ressortgroupref == refnumber)
return tle;
}