1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +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/rewrite/rewriteDefine.c,v 1.101 2005/01/27 23:24:05 neilc Exp $
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.102 2005/04/06 16:34:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,6 +22,7 @@
#include "commands/view.h"
#include "miscadmin.h"
#include "optimizer/clauses.h"
#include "parser/parse_expr.h"
#include "parser/parse_relation.h"
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteManip.h"
@@ -290,11 +291,11 @@ DefineQueryRewrite(RuleStmt *stmt)
foreach(tllist, query->targetList)
{
TargetEntry *tle = (TargetEntry *) lfirst(tllist);
Resdom *resdom = tle->resdom;
int32 tletypmod;
Form_pg_attribute attr;
char *attname;
if (resdom->resjunk)
if (tle->resjunk)
continue;
i++;
if (i > event_relation->rd_att->natts)
@@ -318,12 +319,12 @@ DefineQueryRewrite(RuleStmt *stmt)
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert relation containing dropped columns to view")));
if (strcmp(resdom->resname, attname) != 0)
if (strcmp(tle->resname, attname) != 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("SELECT rule's target entry %d has different column name from \"%s\"", i, attname)));
if (attr->atttypid != resdom->restype)
if (attr->atttypid != exprType((Node *) tle->expr))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("SELECT rule's target entry %d has different type from column \"%s\"", i, attname)));
@@ -335,8 +336,9 @@ DefineQueryRewrite(RuleStmt *stmt)
* length but the select rule's expression will probably have
* typmod = -1.
*/
if (attr->atttypmod != resdom->restypmod &&
attr->atttypmod != -1 && resdom->restypmod != -1)
tletypmod = exprTypmod((Node *) tle->expr);
if (attr->atttypmod != tletypmod &&
attr->atttypmod != -1 && tletypmod != -1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("SELECT rule's target entry %d has different size from column \"%s\"", i, attname)));

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.149 2005/03/26 05:53:01 tgl Exp $
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.150 2005/04/06 16:34:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -312,12 +312,11 @@ rewriteTargetList(Query *parsetree, Relation target_relation)
foreach(temp, parsetree->targetList)
{
TargetEntry *old_tle = (TargetEntry *) lfirst(temp);
Resdom *resdom = old_tle->resdom;
if (!resdom->resjunk)
if (!old_tle->resjunk)
{
/* Normal attr: stash it into new_tles[] */
attrno = resdom->resno;
attrno = old_tle->resno;
if (attrno < 1 || attrno > numattrs)
elog(ERROR, "bogus resno %d in targetlist", attrno);
att_tup = target_relation->rd_att->attrs[attrno - 1];
@@ -344,11 +343,10 @@ rewriteTargetList(Query *parsetree, Relation target_relation)
*/
/* Get the resno right, but don't copy unnecessarily */
if (resdom->resno != next_junk_attrno)
if (old_tle->resno != next_junk_attrno)
{
resdom = (Resdom *) copyObject((Node *) resdom);
resdom->resno = next_junk_attrno;
old_tle = makeTargetEntry(resdom, old_tle->expr);
old_tle = flatCopyTargetEntry(old_tle);
old_tle->resno = next_junk_attrno;
}
junk_tlist = lappend(junk_tlist, old_tle);
next_junk_attrno++;
@@ -407,12 +405,10 @@ rewriteTargetList(Query *parsetree, Relation target_relation)
}
if (new_expr)
new_tle = makeTargetEntry(makeResdom(attrno,
att_tup->atttypid,
att_tup->atttypmod,
pstrdup(NameStr(att_tup->attname)),
false),
(Expr *) new_expr);
new_tle = makeTargetEntry((Expr *) new_expr,
attrno,
pstrdup(NameStr(att_tup->attname)),
false);
}
if (new_tle)
@@ -436,7 +432,7 @@ process_matched_tle(TargetEntry *src_tle,
TargetEntry *prior_tle,
const char *attrName)
{
Resdom *resdom = src_tle->resdom;
TargetEntry *result;
Node *src_expr;
Node *prior_expr;
Node *src_input;
@@ -547,7 +543,9 @@ process_matched_tle(TargetEntry *src_tle,
newexpr = NULL;
}
return makeTargetEntry(resdom, (Expr *) newexpr);
result = flatCopyTargetEntry(src_tle);
result->expr = (Expr *) newexpr;
return result;
}
/*