aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/indexing.c4
-rw-r--r--src/backend/commands/comment.c101
-rw-r--r--src/backend/commands/tablecmds.c38
-rw-r--r--src/backend/nodes/copyfuncs.c17
-rw-r--r--src/backend/nodes/equalfuncs.c14
-rw-r--r--src/backend/parser/gram.y46
-rw-r--r--src/backend/rewrite/rewriteDefine.c39
-rw-r--r--src/backend/rewrite/rewriteRemove.c45
-rw-r--r--src/backend/rewrite/rewriteSupport.c9
-rw-r--r--src/backend/tcop/postgres.c6
-rw-r--r--src/backend/tcop/utility.c27
-rw-r--r--src/backend/utils/adt/ruleutils.c149
-rw-r--r--src/backend/utils/cache/relcache.c26
-rw-r--r--src/backend/utils/cache/syscache.c10
14 files changed, 330 insertions, 201 deletions
diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c
index 203df67f628..6ccb1ef0b2b 100644
--- a/src/backend/catalog/indexing.c
+++ b/src/backend/catalog/indexing.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.90 2002/04/17 20:57:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.91 2002/04/18 20:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -68,7 +68,7 @@ char *Name_pg_proc_indices[Num_pg_proc_indices] =
char *Name_pg_relcheck_indices[Num_pg_relcheck_indices] =
{RelCheckIndex};
char *Name_pg_rewrite_indices[Num_pg_rewrite_indices] =
-{RewriteOidIndex, RewriteRulenameIndex};
+{RewriteOidIndex, RewriteRelRulenameIndex};
char *Name_pg_shadow_indices[Num_pg_shadow_indices] =
{ShadowNameIndex, ShadowSysidIndex};
char *Name_pg_statistic_indices[Num_pg_statistic_indices] =
diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c
index 3eb9a5eb67a..07b14ca4fe2 100644
--- a/src/backend/commands/comment.c
+++ b/src/backend/commands/comment.c
@@ -7,7 +7,7 @@
* Copyright (c) 1999-2001, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.41 2002/04/16 23:08:10 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.42 2002/04/18 20:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -472,44 +472,105 @@ CommentDatabase(List *qualname, char *comment)
* CommentRule --
*
* This routine is used to add/drop any user-comments a user might
- * have regarding a specified RULE. The rule is specified by name
- * and, if found, and the user has appropriate permissions, a
- * comment will be added/dropped using the CreateComments() routine.
+ * have regarding a specified RULE. The rule for commenting is determined by
+ * both its name and the relation to which it refers. The arguments to this
+ * function are the rule name and relation name (merged into a qualified
+ * name), and the comment to add/drop.
+ *
+ * Before PG 7.3, rules had unique names across the whole database, and so
+ * the syntax was just COMMENT ON RULE rulename, with no relation name.
+ * For purposes of backwards compatibility, we support that as long as there
+ * is only one rule by the specified name in the database.
*/
static void
CommentRule(List *qualname, char *comment)
{
- char *rule;
+ int nnames;
+ List *relname;
+ char *rulename;
+ RangeVar *rel;
+ Relation relation;
HeapTuple tuple;
Oid reloid;
Oid ruleoid;
Oid classoid;
int32 aclcheck;
- /* XXX this is gonna change soon */
- if (length(qualname) != 1)
- elog(ERROR, "CommentRule: rule name may not be qualified");
- rule = strVal(lfirst(qualname));
-
- /* Find the rule's pg_rewrite tuple, get its OID and its table's OID */
+ /* Separate relname and trig name */
+ nnames = length(qualname);
+ if (nnames == 1)
+ {
+ /* Old-style: only a rule name is given */
+ Relation RewriteRelation;
+ HeapScanDesc scanDesc;
+ ScanKeyData scanKeyData;
+
+ rulename = strVal(lfirst(qualname));
+
+ /* Search pg_rewrite for such a rule */
+ ScanKeyEntryInitialize(&scanKeyData,
+ 0,
+ Anum_pg_rewrite_rulename,
+ F_NAMEEQ,
+ PointerGetDatum(rulename));
+
+ RewriteRelation = heap_openr(RewriteRelationName, AccessShareLock);
+ scanDesc = heap_beginscan(RewriteRelation,
+ 0, SnapshotNow, 1, &scanKeyData);
+
+ tuple = heap_getnext(scanDesc, 0);
+ if (HeapTupleIsValid(tuple))
+ {
+ reloid = ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class;
+ ruleoid = tuple->t_data->t_oid;
+ }
+ else
+ {
+ elog(ERROR, "rule '%s' does not exist", rulename);
+ reloid = ruleoid = 0; /* keep compiler quiet */
+ }
- tuple = SearchSysCache(RULENAME,
- PointerGetDatum(rule),
- 0, 0, 0);
- if (!HeapTupleIsValid(tuple))
- elog(ERROR, "rule '%s' does not exist", rule);
+ if (HeapTupleIsValid(tuple = heap_getnext(scanDesc, 0)))
+ elog(ERROR, "There are multiple rules '%s'"
+ "\n\tPlease specify a relation name as well as a rule name",
+ rulename);
- reloid = ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class;
- ruleoid = tuple->t_data->t_oid;
+ heap_endscan(scanDesc);
+ heap_close(RewriteRelation, AccessShareLock);
- ReleaseSysCache(tuple);
+ /* Open the owning relation to ensure it won't go away meanwhile */
+ relation = heap_open(reloid, AccessShareLock);
+ }
+ else
+ {
+ /* New-style: rule and relname both provided */
+ Assert(nnames >= 2);
+ relname = ltruncate(nnames-1, listCopy(qualname));
+ rulename = strVal(nth(nnames-1, qualname));
+
+ /* Open the owning relation to ensure it won't go away meanwhile */
+ rel = makeRangeVarFromNameList(relname);
+ relation = heap_openrv(rel, AccessShareLock);
+ reloid = RelationGetRelid(relation);
+
+ /* Find the rule's pg_rewrite tuple, get its OID */
+ tuple = SearchSysCache(RULERELNAME,
+ ObjectIdGetDatum(reloid),
+ PointerGetDatum(rulename),
+ 0, 0);
+ if (!HeapTupleIsValid(tuple))
+ elog(ERROR, "rule '%s' does not exist", rulename);
+ Assert(reloid == ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class);
+ ruleoid = tuple->t_data->t_oid;
+ ReleaseSysCache(tuple);
+ }
/* Check object security */
aclcheck = pg_class_aclcheck(reloid, GetUserId(), ACL_RULE);
if (aclcheck != ACLCHECK_OK)
elog(ERROR, "you are not permitted to comment on rule '%s'",
- rule);
+ rulename);
/* pg_rewrite doesn't have a hard-coded OID, so must look it up */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index f6c9b48c097..8abd8cf80de 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.2 2002/04/15 23:45:07 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.3 2002/04/18 20:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1423,8 +1423,8 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
Relation ridescs[Num_pg_class_indices];
Oid toast_relid;
Oid toast_idxid;
- char toast_relname[NAMEDATALEN + 1];
- char toast_idxname[NAMEDATALEN + 1];
+ char toast_relname[NAMEDATALEN];
+ char toast_idxname[NAMEDATALEN];
IndexInfo *indexInfo;
Oid classObjectId[2];
@@ -1667,7 +1667,7 @@ needs_toast_table(Relation rel)
Oid
DefineRelation(CreateStmt *stmt, char relkind)
{
- char *relname = palloc(NAMEDATALEN);
+ char relname[NAMEDATALEN];
Oid namespaceId;
List *schema = stmt->tableElts;
int numberOfAttributes;
@@ -1686,7 +1686,7 @@ DefineRelation(CreateStmt *stmt, char relkind)
* Truncate relname to appropriate length (probably a waste of time,
* as parser should have done this already).
*/
- StrNCpy(relname, (stmt->relation)->relname, NAMEDATALEN);
+ StrNCpy(relname, stmt->relation->relname, NAMEDATALEN);
/*
* Look up the namespace in which we are supposed to create the
@@ -2642,8 +2642,8 @@ renameatt(Oid relid,
0, 0))
elog(ERROR, "renameatt: attribute \"%s\" exists", newattname);
- StrNCpy(NameStr(((Form_pg_attribute) GETSTRUCT(atttup))->attname),
- newattname, NAMEDATALEN);
+ namestrcpy(&(((Form_pg_attribute) GETSTRUCT(atttup))->attname),
+ newattname);
simple_heap_update(attrelation, &atttup->t_self, atttup);
@@ -2699,8 +2699,8 @@ renameatt(Oid relid,
/*
* Update the (copied) attribute tuple.
*/
- StrNCpy(NameStr(((Form_pg_attribute) GETSTRUCT(atttup))->attname),
- newattname, NAMEDATALEN);
+ namestrcpy(&(((Form_pg_attribute) GETSTRUCT(atttup))->attname),
+ newattname);
simple_heap_update(attrelation, &atttup->t_self, atttup);
@@ -2753,6 +2753,7 @@ renamerel(Oid relid, const char *newrelname)
Relation relrelation; /* for RELATION relation */
HeapTuple reltup;
Oid namespaceId;
+ char *oldrelname;
char relkind;
bool relhastriggers;
Relation irelations[Num_pg_class_indices];
@@ -2763,13 +2764,14 @@ renamerel(Oid relid, const char *newrelname)
*/
targetrelation = relation_open(relid, AccessExclusiveLock);
+ oldrelname = pstrdup(RelationGetRelationName(targetrelation));
namespaceId = RelationGetNamespace(targetrelation);
/* Validity checks */
if (!allowSystemTableMods &&
IsSystemRelation(targetrelation))
elog(ERROR, "renamerel: system relation \"%s\" may not be renamed",
- RelationGetRelationName(targetrelation));
+ oldrelname);
relkind = targetrelation->rd_rel->relkind;
relhastriggers = (targetrelation->rd_rel->reltriggers > 0);
@@ -2785,7 +2787,7 @@ renamerel(Oid relid, const char *newrelname)
0, 0, 0);
if (!HeapTupleIsValid(reltup))
elog(ERROR, "renamerel: relation \"%s\" does not exist",
- RelationGetRelationName(targetrelation));
+ oldrelname);
if (get_relname_relid(newrelname, namespaceId) != InvalidOid)
elog(ERROR, "renamerel: relation \"%s\" exists", newrelname);
@@ -2794,8 +2796,7 @@ renamerel(Oid relid, const char *newrelname)
* Update pg_class tuple with new relname. (Scribbling on reltup is
* OK because it's a copy...)
*/
- StrNCpy(NameStr(((Form_pg_class) GETSTRUCT(reltup))->relname),
- newrelname, NAMEDATALEN);
+ namestrcpy(&(((Form_pg_class) GETSTRUCT(reltup))->relname), newrelname);
simple_heap_update(relrelation, &reltup->t_self, reltup);
@@ -2811,8 +2812,7 @@ renamerel(Oid relid, const char *newrelname)
* Also rename the associated type, if any.
*/
if (relkind != RELKIND_INDEX)
- TypeRename(RelationGetRelationName(targetrelation), namespaceId,
- newrelname);
+ TypeRename(oldrelname, namespaceId, newrelname);
/*
* If it's a view, must also rename the associated ON SELECT rule.
@@ -2822,9 +2822,9 @@ renamerel(Oid relid, const char *newrelname)
char *oldrulename,
*newrulename;
- oldrulename = MakeRetrieveViewRuleName(RelationGetRelationName(targetrelation));
+ oldrulename = MakeRetrieveViewRuleName(oldrelname);
newrulename = MakeRetrieveViewRuleName(newrelname);
- RenameRewriteRule(oldrulename, newrulename);
+ RenameRewriteRule(relid, oldrulename, newrulename);
}
/*
@@ -2834,12 +2834,12 @@ renamerel(Oid relid, const char *newrelname)
{
/* update tgargs where relname is primary key */
update_ri_trigger_args(relid,
- RelationGetRelationName(targetrelation),
+ oldrelname,
newrelname,
false, true);
/* update tgargs where relname is foreign key */
update_ri_trigger_args(relid,
- RelationGetRelationName(targetrelation),
+ oldrelname,
newrelname,
true, true);
}
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 8417f7a716c..d9d5d13d8d4 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -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.179 2002/04/17 20:57:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.180 2002/04/18 20:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2380,14 +2380,15 @@ _copyCreateTrigStmt(CreateTrigStmt *from)
return newnode;
}
-static DropTrigStmt *
-_copyDropTrigStmt(DropTrigStmt *from)
+static DropPropertyStmt *
+_copyDropPropertyStmt(DropPropertyStmt *from)
{
- DropTrigStmt *newnode = makeNode(DropTrigStmt);
+ DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
- if (from->trigname)
- newnode->trigname = pstrdup(from->trigname);
Node_Copy(from, newnode, relation);
+ if (from->property)
+ newnode->property = pstrdup(from->property);
+ newnode->removeType = from->removeType;
return newnode;
}
@@ -2915,8 +2916,8 @@ copyObject(void *from)
case T_CreateTrigStmt:
retval = _copyCreateTrigStmt(from);
break;
- case T_DropTrigStmt:
- retval = _copyDropTrigStmt(from);
+ case T_DropPropertyStmt:
+ retval = _copyDropPropertyStmt(from);
break;
case T_CreatePLangStmt:
retval = _copyCreatePLangStmt(from);
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index 58f6b5a5d63..42030b27268 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -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.127 2002/04/17 20:57:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.128 2002/04/18 20:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1232,12 +1232,14 @@ _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
}
static bool
-_equalDropTrigStmt(DropTrigStmt *a, DropTrigStmt *b)
+_equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
{
- if (!equalstr(a->trigname, b->trigname))
- return false;
if (!equal(a->relation, b->relation))
return false;
+ if (!equalstr(a->property, b->property))
+ return false;
+ if (a->removeType != b->removeType)
+ return false;
return true;
}
@@ -2080,8 +2082,8 @@ equal(void *a, void *b)
case T_CreateTrigStmt:
retval = _equalCreateTrigStmt(a, b);
break;
- case T_DropTrigStmt:
- retval = _equalDropTrigStmt(a, b);
+ case T_DropPropertyStmt:
+ retval = _equalDropPropertyStmt(a, b);
break;
case T_CreatePLangStmt:
retval = _equalCreatePLangStmt(a, b);
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 774f9fa743c..e4ec05abf24 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.303 2002/04/17 20:57:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.304 2002/04/18 20:01:09 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -134,7 +134,7 @@ static bool set_name_needs_quotes(const char *name);
CreateSchemaStmt, CreateSeqStmt, CreateStmt, CreateTrigStmt,
CreateUserStmt, CreatedbStmt, CursorStmt, DefineStmt, DeleteStmt,
DropGroupStmt, DropPLangStmt, DropSchemaStmt, DropStmt, DropTrigStmt,
- DropUserStmt, DropdbStmt, ExplainStmt, FetchStmt,
+ DropRuleStmt, DropUserStmt, DropdbStmt, ExplainStmt, FetchStmt,
GrantStmt, IndexStmt, InsertStmt, ListenStmt, LoadStmt, LockStmt,
NotifyStmt, OptimizableStmt, ProcedureStmt, ReindexStmt,
RemoveAggrStmt, RemoveFuncStmt, RemoveOperStmt,
@@ -469,6 +469,7 @@ stmt : AlterDatabaseSetStmt
| DropGroupStmt
| DropPLangStmt
| DropTrigStmt
+ | DropRuleStmt
| DropUserStmt
| ExplainStmt
| FetchStmt
@@ -2062,9 +2063,10 @@ ConstraintTimeSpec: INITIALLY IMMEDIATE
DropTrigStmt: DROP TRIGGER name ON qualified_name
{
- DropTrigStmt *n = makeNode(DropTrigStmt);
- n->trigname = $3;
+ DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = $5;
+ n->property = $3;
+ n->removeType = DROP_TRIGGER;
$$ = (Node *) n;
}
;
@@ -2154,7 +2156,6 @@ drop_type: TABLE { $$ = DROP_TABLE; }
| SEQUENCE { $$ = DROP_SEQUENCE; }
| VIEW { $$ = DROP_VIEW; }
| INDEX { $$ = DROP_INDEX; }
- | RULE { $$ = DROP_RULE; }
| TYPE_P { $$ = DROP_TYPE; }
| DOMAIN_P { $$ = DROP_DOMAIN; }
;
@@ -2191,11 +2192,11 @@ TruncateStmt: TRUNCATE opt_table qualified_name
* The COMMENT ON statement can take different forms based upon the type of
* the object associated with the comment. The form of the statement is:
*
- * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ]
+ * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW ]
* <objname> | AGGREGATE <aggname> (<aggtype>) | FUNCTION
* <funcname> (arg1, arg2, ...) | OPERATOR <op>
* (leftoperand_typ rightoperand_typ) | TRIGGER <triggername> ON
- * <relname> ] IS 'text'
+ * <relname> | RULE <rulename> ON <relname> ] IS 'text'
*
*****************************************************************************/
@@ -2244,12 +2245,30 @@ CommentStmt: COMMENT ON comment_type any_name IS comment_text
n->comment = $8;
$$ = (Node *) n;
}
+ | COMMENT ON RULE name ON any_name IS comment_text
+ {
+ CommentStmt *n = makeNode(CommentStmt);
+ n->objtype = RULE;
+ n->objname = lappend($6, makeString($4));
+ n->objargs = NIL;
+ n->comment = $8;
+ $$ = (Node *) n;
+ }
+ | COMMENT ON RULE name IS comment_text
+ {
+ /* Obsolete syntax supported for awhile for compatibility */
+ CommentStmt *n = makeNode(CommentStmt);
+ n->objtype = RULE;
+ n->objname = makeList1(makeString($4));
+ n->objargs = NIL;
+ n->comment = $6;
+ $$ = (Node *) n;
+ }
;
comment_type: COLUMN { $$ = COLUMN; }
| DATABASE { $$ = DATABASE; }
| INDEX { $$ = INDEX; }
- | RULE { $$ = RULE; }
| SEQUENCE { $$ = SEQUENCE; }
| TABLE { $$ = TABLE; }
| DOMAIN_P { $$ = TYPE_P; }
@@ -2977,6 +2996,17 @@ opt_instead: INSTEAD { $$ = TRUE; }
;
+DropRuleStmt: DROP RULE name ON qualified_name
+ {
+ DropPropertyStmt *n = makeNode(DropPropertyStmt);
+ n->relation = $5;
+ n->property = $3;
+ n->removeType = DROP_RULE;
+ $$ = (Node *) n;
+ }
+ ;
+
+
/*****************************************************************************
*
* QUERY:
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index f20c9a0d982..8b40aeb4f73 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.66 2002/03/26 19:16:02 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.67 2002/04/18 20:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -37,7 +37,7 @@ static bool setRuleCheckAsUser_walker(Node *node, Oid *context);
/*
* InsertRule -
- * takes the arguments and inserts them as attributes into the system
+ * takes the arguments and inserts them as a row into the system
* relation "pg_rewrite"
*/
static Oid
@@ -58,7 +58,7 @@ InsertRule(char *rulname,
HeapTuple tup;
Oid rewriteObjectId;
- if (IsDefinedRewriteRule(rulname))
+ if (IsDefinedRewriteRule(eventrel_oid, rulname))
elog(ERROR, "Attempt to insert rule \"%s\" failed: already exists",
rulname);
@@ -69,13 +69,13 @@ InsertRule(char *rulname,
i = 0;
namestrcpy(&rname, rulname);
- values[i++] = NameGetDatum(&rname);
- values[i++] = CharGetDatum(evtype + '0');
- values[i++] = ObjectIdGetDatum(eventrel_oid);
- values[i++] = Int16GetDatum(evslot_index);
- values[i++] = BoolGetDatum(evinstead);
- values[i++] = DirectFunctionCall1(textin, CStringGetDatum(evqual));
- values[i++] = DirectFunctionCall1(textin, CStringGetDatum(actiontree));
+ values[i++] = NameGetDatum(&rname); /* rulename */
+ values[i++] = ObjectIdGetDatum(eventrel_oid); /* ev_class */
+ values[i++] = Int16GetDatum(evslot_index); /* ev_attr */
+ values[i++] = CharGetDatum(evtype + '0'); /* ev_type */
+ values[i++] = BoolGetDatum(evinstead); /* is_instead */
+ values[i++] = DirectFunctionCall1(textin, CStringGetDatum(evqual)); /* ev_qual */
+ values[i++] = DirectFunctionCall1(textin, CStringGetDatum(actiontree)); /* ev_action */
/*
* create a new pg_rewrite tuple
@@ -423,26 +423,27 @@ setRuleCheckAsUser_walker(Node *node, Oid *context)
* ON SELECT rule associated with a view, when the view is renamed.
*/
void
-RenameRewriteRule(char *oldname, char *newname)
+RenameRewriteRule(Oid owningRel, const char *oldName,
+ const char *newName)
{
Relation pg_rewrite_desc;
HeapTuple ruletup;
pg_rewrite_desc = heap_openr(RewriteRelationName, RowExclusiveLock);
- ruletup = SearchSysCacheCopy(RULENAME,
- PointerGetDatum(oldname),
- 0, 0, 0);
+ ruletup = SearchSysCacheCopy(RULERELNAME,
+ ObjectIdGetDatum(owningRel),
+ PointerGetDatum(oldName),
+ 0, 0);
if (!HeapTupleIsValid(ruletup))
- elog(ERROR, "RenameRewriteRule: rule \"%s\" does not exist", oldname);
+ elog(ERROR, "RenameRewriteRule: rule \"%s\" does not exist", oldName);
/* should not already exist */
- if (IsDefinedRewriteRule(newname))
+ if (IsDefinedRewriteRule(owningRel, newName))
elog(ERROR, "Attempt to rename rule \"%s\" failed: \"%s\" already exists",
- oldname, newname);
+ oldName, newName);
- StrNCpy(NameStr(((Form_pg_rewrite) GETSTRUCT(ruletup))->rulename),
- newname, NAMEDATALEN);
+ namestrcpy(&(((Form_pg_rewrite) GETSTRUCT(ruletup))->rulename), newName);
simple_heap_update(pg_rewrite_desc, &ruletup->t_self, ruletup);
diff --git a/src/backend/rewrite/rewriteRemove.c b/src/backend/rewrite/rewriteRemove.c
index da8f1b8e540..df85fa504a0 100644
--- a/src/backend/rewrite/rewriteRemove.c
+++ b/src/backend/rewrite/rewriteRemove.c
@@ -8,15 +8,16 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.47 2002/03/29 19:06:13 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.48 2002/04/18 20:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#include "utils/builtins.h"
+#include "access/genam.h"
#include "access/heapam.h"
#include "catalog/catname.h"
+#include "catalog/indexing.h"
#include "catalog/pg_rewrite.h"
#include "commands/comment.h"
#include "miscadmin.h"
@@ -30,12 +31,11 @@
/*
* RemoveRewriteRule
*
- * Delete a rule given its (possibly qualified) rulename.
+ * Delete a rule given its name.
*/
void
-RemoveRewriteRule(List *names)
+RemoveRewriteRule(Oid owningRel, const char *ruleName)
{
- char *ruleName;
Relation RewriteRelation;
Relation event_relation;
HeapTuple tuple;
@@ -45,13 +45,6 @@ RemoveRewriteRule(List *names)
int32 aclcheck_result;
/*
- * XXX temporary until rules become schema-tized
- */
- if (length(names) != 1)
- elog(ERROR, "Qualified rule names not supported yet");
- ruleName = strVal(lfirst(names));
-
- /*
* Open the pg_rewrite relation.
*/
RewriteRelation = heap_openr(RewriteRelationName, RowExclusiveLock);
@@ -59,9 +52,10 @@ RemoveRewriteRule(List *names)
/*
* Find the tuple for the target rule.
*/
- tuple = SearchSysCacheCopy(RULENAME,
+ tuple = SearchSysCacheCopy(RULERELNAME,
+ ObjectIdGetDatum(owningRel),
PointerGetDatum(ruleName),
- 0, 0, 0);
+ 0, 0);
/*
* complain if no rule with such name existed
@@ -75,6 +69,7 @@ RemoveRewriteRule(List *names)
*/
ruleId = tuple->t_data->t_oid;
eventRelationOid = ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class;
+ Assert(eventRelationOid == owningRel);
/*
* We had better grab AccessExclusiveLock so that we know no other
@@ -137,10 +132,10 @@ RemoveRewriteRule(List *names)
void
RelationRemoveRules(Oid relid)
{
- Relation RewriteRelation = NULL;
- HeapScanDesc scanDesc = NULL;
+ Relation RewriteRelation;
+ SysScanDesc scanDesc;
ScanKeyData scanKeyData;
- HeapTuple tuple = NULL;
+ HeapTuple tuple;
/*
* Open the pg_rewrite relation.
@@ -148,18 +143,21 @@ RelationRemoveRules(Oid relid)
RewriteRelation = heap_openr(RewriteRelationName, RowExclusiveLock);
/*
- * Scan the RuleRelation ('pg_rewrite') for all the tuples that has
- * the same ev_class as relid (the relation to be removed).
+ * Scan pg_rewrite for all the tuples that have the same ev_class
+ * as relid (the relation to be removed).
*/
ScanKeyEntryInitialize(&scanKeyData,
0,
Anum_pg_rewrite_ev_class,
F_OIDEQ,
ObjectIdGetDatum(relid));
- scanDesc = heap_beginscan(RewriteRelation,
- 0, SnapshotNow, 1, &scanKeyData);
- while (HeapTupleIsValid(tuple = heap_getnext(scanDesc, 0)))
+ scanDesc = systable_beginscan(RewriteRelation,
+ RewriteRelRulenameIndex,
+ true, SnapshotNow,
+ 1, &scanKeyData);
+
+ while (HeapTupleIsValid(tuple = systable_getnext(scanDesc)))
{
/* Delete any comments associated with this rule */
DeleteComments(tuple->t_data->t_oid, RelationGetRelid(RewriteRelation));
@@ -167,6 +165,7 @@ RelationRemoveRules(Oid relid)
simple_heap_delete(RewriteRelation, &tuple->t_self);
}
- heap_endscan(scanDesc);
+ systable_endscan(scanDesc);
+
heap_close(RewriteRelation, RowExclusiveLock);
}
diff --git a/src/backend/rewrite/rewriteSupport.c b/src/backend/rewrite/rewriteSupport.c
index bc2f04932a4..62a951aaf6f 100644
--- a/src/backend/rewrite/rewriteSupport.c
+++ b/src/backend/rewrite/rewriteSupport.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.49 2001/08/12 21:35:19 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.50 2002/04/18 20:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -29,11 +29,12 @@
* Is there a rule by the given name?
*/
bool
-IsDefinedRewriteRule(const char *ruleName)
+IsDefinedRewriteRule(Oid owningRel, const char *ruleName)
{
- return SearchSysCacheExists(RULENAME,
+ return SearchSysCacheExists(RULERELNAME,
+ ObjectIdGetDatum(owningRel),
PointerGetDatum(ruleName),
- 0, 0, 0);
+ 0, 0);
}
/*
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index bef1b8064c7..d8c2065258b 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.260 2002/03/24 04:31:07 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.261 2002/04/18 20:01:09 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@@ -1688,7 +1688,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.260 $ $Date: 2002/03/24 04:31:07 $\n");
+ puts("$Revision: 1.261 $ $Date: 2002/04/18 20:01:09 $\n");
}
/*
@@ -2322,7 +2322,7 @@ CreateCommandTag(Node *parsetree)
tag = "CREATE";
break;
- case T_DropTrigStmt:
+ case T_DropPropertyStmt:
tag = "DROP";
break;
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 63e6b5dd9b2..24a1e3d2964 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.149 2002/04/15 05:22:04 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.150 2002/04/18 20:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -312,11 +312,6 @@ ProcessUtility(Node *parsetree,
RemoveIndex(rel);
break;
- case DROP_RULE:
- /* RemoveRewriteRule checks permissions */
- RemoveRewriteRule(names);
- break;
-
case DROP_TYPE:
/* RemoveType does its own permissions checks */
RemoveType(names);
@@ -714,12 +709,24 @@ ProcessUtility(Node *parsetree,
CreateTrigger((CreateTrigStmt *) parsetree);
break;
- case T_DropTrigStmt:
+ case T_DropPropertyStmt:
{
- DropTrigStmt *stmt = (DropTrigStmt *) parsetree;
+ DropPropertyStmt *stmt = (DropPropertyStmt *) parsetree;
+ Oid relId;
- DropTrigger(RangeVarGetRelid(stmt->relation, false),
- stmt->trigname);
+ relId = RangeVarGetRelid(stmt->relation, false);
+
+ switch (stmt->removeType)
+ {
+ case DROP_RULE:
+ /* RemoveRewriteRule checks permissions */
+ RemoveRewriteRule(relId, stmt->property);
+ break;
+ case DROP_TRIGGER:
+ /* DropTrigger checks permissions */
+ DropTrigger(relId, stmt->property);
+ break;
+ }
}
break;
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 501d5a2095f..5207488405b 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -3,7 +3,7 @@
* back to source text
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.96 2002/04/11 20:00:04 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.97 2002/04/18 20:01:09 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -42,6 +42,7 @@
#include "catalog/heap.h"
#include "catalog/index.h"
+#include "catalog/namespace.h"
#include "catalog/pg_index.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_operator.h"
@@ -97,11 +98,10 @@ typedef struct
* Global data
* ----------
*/
-static char *rulename = NULL;
-static void *plan_getrule = NULL;
-static char *query_getrule = "SELECT * FROM pg_rewrite WHERE rulename = $1";
-static void *plan_getview = NULL;
-static char *query_getview = "SELECT * FROM pg_rewrite WHERE rulename = $1";
+static void *plan_getrulebyoid = NULL;
+static char *query_getrulebyoid = "SELECT * FROM pg_rewrite WHERE oid = $1";
+static void *plan_getviewrule = NULL;
+static char *query_getviewrule = "SELECT * FROM pg_rewrite WHERE ev_class = $1 AND rulename = $2";
/* ----------
@@ -112,6 +112,7 @@ static char *query_getview = "SELECT * FROM pg_rewrite WHERE rulename = $1";
* as a parameter, and append their text output to its contents.
* ----------
*/
+static text *pg_do_getviewdef(Oid viewoid);
static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
static void get_query_def(Query *query, StringInfo buf, List *parentnamespace);
@@ -156,10 +157,10 @@ static char *get_relid_attribute_name(Oid relid, AttrNumber attnum);
Datum
pg_get_ruledef(PG_FUNCTION_ARGS)
{
- Name rname = PG_GETARG_NAME(0);
+ Oid ruleoid = PG_GETARG_OID(0);
text *ruledef;
Datum args[1];
- char nulls[2];
+ char nulls[1];
int spirc;
HeapTuple ruletup;
TupleDesc rulettc;
@@ -167,11 +168,6 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
int len;
/*
- * We need the rules name somewhere deep down: rulename is global
- */
- rulename = pstrdup(NameStr(*rname));
-
- /*
* Connect to SPI manager
*/
if (SPI_connect() != SPI_OK_CONNECT)
@@ -182,27 +178,26 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
* pg_rewrite over the SPI manager instead of using the syscache to be
* checked for read access on pg_rewrite.
*/
- if (plan_getrule == NULL)
+ if (plan_getrulebyoid == NULL)
{
Oid argtypes[1];
void *plan;
- argtypes[0] = NAMEOID;
- plan = SPI_prepare(query_getrule, 1, argtypes);
+ argtypes[0] = OIDOID;
+ plan = SPI_prepare(query_getrulebyoid, 1, argtypes);
if (plan == NULL)
- elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getrule);
- plan_getrule = SPI_saveplan(plan);
+ elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getrulebyoid);
+ plan_getrulebyoid = SPI_saveplan(plan);
}
/*
* Get the pg_rewrite tuple for this rule
*/
- args[0] = PointerGetDatum(rulename);
- nulls[0] = (rulename == NULL) ? 'n' : ' ';
- nulls[1] = '\0';
- spirc = SPI_execp(plan_getrule, args, nulls, 1);
+ args[0] = ObjectIdGetDatum(ruleoid);
+ nulls[0] = ' ';
+ spirc = SPI_execp(plan_getrulebyoid, args, nulls, 1);
if (spirc != SPI_OK_SELECT)
- elog(ERROR, "failed to get pg_rewrite tuple for %s", rulename);
+ elog(ERROR, "failed to get pg_rewrite tuple for %u", ruleoid);
if (SPI_processed != 1)
{
if (SPI_finish() != SPI_OK_FINISH)
@@ -248,23 +243,49 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
{
- Name vname = PG_GETARG_NAME(0);
+ /* By OID */
+ Oid viewoid = PG_GETARG_OID(0);
text *ruledef;
- Datum args[1];
- char nulls[1];
+
+ ruledef = pg_do_getviewdef(viewoid);
+ PG_RETURN_TEXT_P(ruledef);
+}
+
+Datum
+pg_get_viewdef_name(PG_FUNCTION_ARGS)
+{
+ /* By qualified name */
+ text *viewname = PG_GETARG_TEXT_P(0);
+ RangeVar *viewrel;
+ Oid viewoid;
+ text *ruledef;
+
+ viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname,
+ "get_viewdef"));
+ viewoid = RangeVarGetRelid(viewrel, false);
+
+ ruledef = pg_do_getviewdef(viewoid);
+ PG_RETURN_TEXT_P(ruledef);
+}
+
+/*
+ * Common code for by-OID and by-name variants of pg_get_viewdef
+ */
+static text *
+pg_do_getviewdef(Oid viewoid)
+{
+ text *ruledef;
+ Datum args[2];
+ char nulls[2];
int spirc;
HeapTuple ruletup;
TupleDesc rulettc;
StringInfoData buf;
int len;
+ char *viewname;
char *name;
/*
- * We need the view name somewhere deep down
- */
- rulename = pstrdup(NameStr(*vname));
-
- /*
* Connect to SPI manager
*/
if (SPI_connect() != SPI_OK_CONNECT)
@@ -275,28 +296,31 @@ pg_get_viewdef(PG_FUNCTION_ARGS)
* pg_rewrite over the SPI manager instead of using the syscache to be
* checked for read access on pg_rewrite.
*/
- if (plan_getview == NULL)
+ if (plan_getviewrule == NULL)
{
- Oid argtypes[1];
+ Oid argtypes[2];
void *plan;
- argtypes[0] = NAMEOID;
- plan = SPI_prepare(query_getview, 1, argtypes);
+ argtypes[0] = OIDOID;
+ argtypes[1] = NAMEOID;
+ plan = SPI_prepare(query_getviewrule, 2, argtypes);
if (plan == NULL)
- elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getview);
- plan_getview = SPI_saveplan(plan);
+ elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getviewrule);
+ plan_getviewrule = SPI_saveplan(plan);
}
/*
- * Get the pg_rewrite tuple for this rule: rulename is actually
- * viewname here
+ * Get the pg_rewrite tuple for the view's SELECT rule
*/
- name = MakeRetrieveViewRuleName(rulename);
- args[0] = PointerGetDatum(name);
+ viewname = get_rel_name(viewoid);
+ name = MakeRetrieveViewRuleName(viewname);
+ args[0] = ObjectIdGetDatum(viewoid);
+ args[1] = PointerGetDatum(name);
nulls[0] = ' ';
- spirc = SPI_execp(plan_getview, args, nulls, 1);
+ nulls[1] = ' ';
+ spirc = SPI_execp(plan_getviewrule, args, nulls, 2);
if (spirc != SPI_OK_SELECT)
- elog(ERROR, "failed to get pg_rewrite tuple for view %s", rulename);
+ elog(ERROR, "failed to get pg_rewrite tuple for view %s", viewname);
initStringInfo(&buf);
if (SPI_processed != 1)
appendStringInfo(&buf, "Not a view");
@@ -322,10 +346,7 @@ pg_get_viewdef(PG_FUNCTION_ARGS)
if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "get_viewdef: SPI_finish() failed");
- /*
- * Easy - isn't it?
- */
- PG_RETURN_TEXT_P(ruledef);
+ return ruledef;
}
@@ -633,8 +654,6 @@ deparse_expression(Node *expr, List *dpcontext, bool forceprefix)
context.namespaces = dpcontext;
context.varprefix = forceprefix;
- rulename = ""; /* in case of errors */
-
get_rule_expr(expr, &context);
return buf.data;
@@ -792,6 +811,7 @@ deparse_context_for_subplan(const char *name, List *tlist,
static void
make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
{
+ char *rulename;
char ev_type;
Oid ev_class;
int2 ev_attr;
@@ -800,23 +820,38 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
char *ev_action;
List *actions = NIL;
int fno;
+ Datum dat;
bool isnull;
/*
* Get the attribute values from the rules tuple
*/
+ fno = SPI_fnumber(rulettc, "rulename");
+ dat = SPI_getbinval(ruletup, rulettc, fno, &isnull);
+ Assert(!isnull);
+ rulename = NameStr(*(DatumGetName(dat)));
+
fno = SPI_fnumber(rulettc, "ev_type");
- ev_type = (char) SPI_getbinval(ruletup, rulettc, fno, &isnull);
+ dat = SPI_getbinval(ruletup, rulettc, fno, &isnull);
+ Assert(!isnull);
+ ev_type = DatumGetChar(dat);
fno = SPI_fnumber(rulettc, "ev_class");
- ev_class = (Oid) SPI_getbinval(ruletup, rulettc, fno, &isnull);
+ dat = SPI_getbinval(ruletup, rulettc, fno, &isnull);
+ Assert(!isnull);
+ ev_class = DatumGetObjectId(dat);
fno = SPI_fnumber(rulettc, "ev_attr");
- ev_attr = (int2) SPI_getbinval(ruletup, rulettc, fno, &isnull);
+ dat = SPI_getbinval(ruletup, rulettc, fno, &isnull);
+ Assert(!isnull);
+ ev_attr = DatumGetInt16(dat);
fno = SPI_fnumber(rulettc, "is_instead");
- is_instead = (bool) SPI_getbinval(ruletup, rulettc, fno, &isnull);
+ dat = SPI_getbinval(ruletup, rulettc, fno, &isnull);
+ Assert(!isnull);
+ is_instead = DatumGetBool(dat);
+ /* these could be nulls */
fno = SPI_fnumber(rulettc, "ev_qual");
ev_qual = SPI_getvalue(ruletup, rulettc, fno);
@@ -1051,8 +1086,8 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace)
break;
default:
- elog(ERROR, "get_ruledef of %s: query command type %d not implemented yet",
- rulename, query->commandType);
+ elog(ERROR, "get_query_def: unknown query command type %d",
+ query->commandType);
break;
}
}
@@ -1901,9 +1936,7 @@ get_rule_expr(Node *node, deparse_context *context)
break;
default:
- printf("\n%s\n", nodeToString(node));
- elog(ERROR, "get_ruledef of %s: unknown node type %d in get_rule_expr()",
- rulename, nodeTag(node));
+ elog(ERROR, "get_rule_expr: unknown node type %d", nodeTag(node));
break;
}
}
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 9a8e76f4926..686fcc8416b 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.160 2002/04/12 20:38:29 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.161 2002/04/18 20:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -675,17 +675,18 @@ RelationBuildRuleLock(Relation relation)
/*
* open pg_rewrite and begin a scan
- *
- * XXX: there is no suitable index for this scan. FIXME.
*/
pg_rewrite_desc = heap_openr(RewriteRelationName, AccessShareLock);
pg_rewrite_tupdesc = RelationGetDescr(pg_rewrite_desc);
- pg_rewrite_scan = systable_beginscan(pg_rewrite_desc, NULL, false,
+ pg_rewrite_scan = systable_beginscan(pg_rewrite_desc,
+ RewriteRelRulenameIndex,
+ criticalRelcachesBuilt,
SnapshotNow,
1, &key);
while (HeapTupleIsValid(pg_rewrite_tuple = systable_getnext(pg_rewrite_scan)))
{
+ Form_pg_rewrite rewrite_form = (Form_pg_rewrite) GETSTRUCT(pg_rewrite_tuple);
bool isnull;
Datum ruleaction;
Datum rule_evqual;
@@ -698,18 +699,11 @@ RelationBuildRuleLock(Relation relation)
rule->ruleId = pg_rewrite_tuple->t_data->t_oid;
- rule->event = DatumGetInt32(heap_getattr(pg_rewrite_tuple,
- Anum_pg_rewrite_ev_type,
- pg_rewrite_tupdesc,
- &isnull)) - 48;
- rule->attrno = DatumGetInt16(heap_getattr(pg_rewrite_tuple,
- Anum_pg_rewrite_ev_attr,
- pg_rewrite_tupdesc,
- &isnull));
- rule->isInstead = DatumGetBool(heap_getattr(pg_rewrite_tuple,
- Anum_pg_rewrite_is_instead,
- pg_rewrite_tupdesc,
- &isnull));
+ rule->event = rewrite_form->ev_type - '0';
+ rule->attrno = rewrite_form->ev_attr;
+ rule->isInstead = rewrite_form->is_instead;
+
+ /* Must use heap_getattr to fetch ev_qual and ev_action */
ruleaction = heap_getattr(pg_rewrite_tuple,
Anum_pg_rewrite_ev_action,
diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c
index 5deea860897..03acac91b02 100644
--- a/src/backend/utils/cache/syscache.c
+++ b/src/backend/utils/cache/syscache.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.78 2002/04/17 20:57:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.79 2002/04/18 20:01:10 tgl Exp $
*
* NOTES
* These routines allow the parser/planner/executor to perform
@@ -333,14 +333,14 @@ static const struct cachedesc cacheinfo[] = {
0,
0
}},
- {RewriteRelationName, /* RULENAME */
- RewriteRulenameIndex,
+ {RewriteRelationName, /* RULERELNAME */
+ RewriteRelRulenameIndex,
Anum_pg_rewrite_ev_class,
- 1,
+ 2,
{
+ Anum_pg_rewrite_ev_class,
Anum_pg_rewrite_rulename,
0,
- 0,
0
}},
{ShadowRelationName, /* SHADOWNAME */