mirror of
https://github.com/postgres/postgres.git
synced 2025-11-16 15:02:33 +03:00
Change naming rule for ON SELECT rules of views: they're all just
_RETURN now, since there's no need to keep 'em unique anymore.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.4 2002/04/19 16:36:08 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.5 2002/04/19 23:13:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -40,8 +40,6 @@
|
||||
#include "parser/parse_expr.h"
|
||||
#include "parser/parse_relation.h"
|
||||
#include "parser/parse_type.h"
|
||||
#include "rewrite/rewriteDefine.h"
|
||||
#include "rewrite/rewriteSupport.h"
|
||||
#include "utils/acl.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
@@ -2814,19 +2812,6 @@ renamerel(Oid relid, const char *newrelname)
|
||||
if (relkind != RELKIND_INDEX)
|
||||
TypeRename(oldrelname, namespaceId, newrelname);
|
||||
|
||||
/*
|
||||
* If it's a view, must also rename the associated ON SELECT rule.
|
||||
*/
|
||||
if (relkind == RELKIND_VIEW)
|
||||
{
|
||||
char *oldrulename,
|
||||
*newrulename;
|
||||
|
||||
oldrulename = MakeRetrieveViewRuleName(oldrelname);
|
||||
newrulename = MakeRetrieveViewRuleName(newrelname);
|
||||
RenameRewriteRule(relid, oldrulename, newrulename);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update rel name in any RI triggers associated with the relation.
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: view.c,v 1.62 2002/04/15 05:22:03 tgl Exp $
|
||||
* $Id: view.c,v 1.63 2002/04/19 23:13:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -99,17 +99,14 @@ static RuleStmt *
|
||||
FormViewRetrieveRule(const RangeVar *view, Query *viewParse)
|
||||
{
|
||||
RuleStmt *rule;
|
||||
char *rname;
|
||||
|
||||
/*
|
||||
* Create a RuleStmt that corresponds to the suitable rewrite rule
|
||||
* args for DefineQueryRewrite();
|
||||
*/
|
||||
rname = MakeRetrieveViewRuleName(view->relname);
|
||||
|
||||
rule = makeNode(RuleStmt);
|
||||
rule->relation = copyObject((RangeVar *) view);
|
||||
rule->rulename = pstrdup(rname);
|
||||
rule->rulename = pstrdup(ViewSelectRuleName);
|
||||
rule->whereClause = NULL;
|
||||
rule->event = CMD_SELECT;
|
||||
rule->instead = true;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.67 2002/04/18 20:01:09 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.68 2002/04/19 23:13:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -176,7 +176,6 @@ DefineQueryRewrite(RuleStmt *stmt)
|
||||
{
|
||||
List *tllist;
|
||||
int i;
|
||||
char *expected_name;
|
||||
|
||||
/*
|
||||
* So there cannot be INSTEAD NOTHING, ...
|
||||
@@ -265,15 +264,26 @@ DefineQueryRewrite(RuleStmt *stmt)
|
||||
}
|
||||
|
||||
/*
|
||||
* ... and finally the rule must be named _RETviewname.
|
||||
* ... and finally the rule must be named _RETURN.
|
||||
*/
|
||||
expected_name = MakeRetrieveViewRuleName(event_obj->relname);
|
||||
if (strcmp(expected_name, stmt->rulename) != 0)
|
||||
if (strcmp(stmt->rulename, ViewSelectRuleName) != 0)
|
||||
{
|
||||
elog(ERROR, "view rule for \"%s\" must be named \"%s\"",
|
||||
event_obj->relname, expected_name);
|
||||
/*
|
||||
* In versions before 7.3, the expected name was _RETviewname.
|
||||
* For backwards compatibility with old pg_dump output, accept
|
||||
* that and silently change it to _RETURN. Since this is just
|
||||
* a quick backwards-compatibility hack, limit the number of
|
||||
* characters checked to a few less than NAMEDATALEN; this
|
||||
* saves having to worry about where a multibyte character might
|
||||
* have gotten truncated.
|
||||
*/
|
||||
if (strncmp(stmt->rulename, "_RET", 4) != 0 ||
|
||||
strncmp(stmt->rulename + 4, event_obj->relname,
|
||||
NAMEDATALEN - 4 - 4) != 0)
|
||||
elog(ERROR, "view rule for \"%s\" must be named \"%s\"",
|
||||
event_obj->relname, ViewSelectRuleName);
|
||||
stmt->rulename = pstrdup(ViewSelectRuleName);
|
||||
}
|
||||
pfree(expected_name);
|
||||
|
||||
/*
|
||||
* Are we converting a relation to a view?
|
||||
@@ -418,9 +428,7 @@ setRuleCheckAsUser_walker(Node *node, Oid *context)
|
||||
/*
|
||||
* Rename an existing rewrite rule.
|
||||
*
|
||||
* There is not currently a user command to invoke this directly
|
||||
* (perhaps there should be). But we need it anyway to rename the
|
||||
* ON SELECT rule associated with a view, when the view is renamed.
|
||||
* This is unused code at the moment.
|
||||
*/
|
||||
void
|
||||
RenameRewriteRule(Oid owningRel, const char *oldName,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.50 2002/04/18 20:01:09 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.51 2002/04/19 23:13:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -20,10 +20,6 @@
|
||||
#include "rewrite/rewriteSupport.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
#include "mb/pg_wchar.h"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Is there a rule by the given name?
|
||||
@@ -37,35 +33,6 @@ IsDefinedRewriteRule(Oid owningRel, const char *ruleName)
|
||||
0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* makeViewRetrieveRuleName
|
||||
*
|
||||
* Given a view name, returns the name for the associated ON SELECT rule.
|
||||
*
|
||||
* XXX this is not the only place in the backend that knows about the _RET
|
||||
* name-forming convention.
|
||||
*/
|
||||
char *
|
||||
MakeRetrieveViewRuleName(const char *viewName)
|
||||
{
|
||||
char *buf;
|
||||
int buflen,
|
||||
maxlen;
|
||||
|
||||
buflen = strlen(viewName) + 5;
|
||||
buf = palloc(buflen);
|
||||
snprintf(buf, buflen, "_RET%s", viewName);
|
||||
/* clip to less than NAMEDATALEN bytes, if necessary */
|
||||
#ifdef MULTIBYTE
|
||||
maxlen = pg_mbcliplen(buf, strlen(buf), NAMEDATALEN - 1);
|
||||
#else
|
||||
maxlen = NAMEDATALEN - 1;
|
||||
#endif
|
||||
if (maxlen < buflen)
|
||||
buf[maxlen] = '\0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* SetRelationRuleStatus
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* back to source text
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.97 2002/04/18 20:01:09 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.98 2002/04/19 23:13:54 tgl Exp $
|
||||
*
|
||||
* This software is copyrighted by Jan Wieck - Hamburg.
|
||||
*
|
||||
@@ -283,7 +283,6 @@ pg_do_getviewdef(Oid viewoid)
|
||||
StringInfoData buf;
|
||||
int len;
|
||||
char *viewname;
|
||||
char *name;
|
||||
|
||||
/*
|
||||
* Connect to SPI manager
|
||||
@@ -313,9 +312,8 @@ pg_do_getviewdef(Oid viewoid)
|
||||
* Get the pg_rewrite tuple for the view's SELECT rule
|
||||
*/
|
||||
viewname = get_rel_name(viewoid);
|
||||
name = MakeRetrieveViewRuleName(viewname);
|
||||
args[0] = ObjectIdGetDatum(viewoid);
|
||||
args[1] = PointerGetDatum(name);
|
||||
args[1] = PointerGetDatum(ViewSelectRuleName);
|
||||
nulls[0] = ' ';
|
||||
nulls[1] = ' ';
|
||||
spirc = SPI_execp(plan_getviewrule, args, nulls, 2);
|
||||
@@ -338,7 +336,6 @@ pg_do_getviewdef(Oid viewoid)
|
||||
VARATT_SIZEP(ruledef) = len;
|
||||
memcpy(VARDATA(ruledef), buf.data, buf.len);
|
||||
pfree(buf.data);
|
||||
pfree(name);
|
||||
|
||||
/*
|
||||
* Disconnect from SPI manager
|
||||
|
||||
Reference in New Issue
Block a user