Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
1b5cffac
Commit
1b5cffac
authored
Aug 12, 2001
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ALTER TABLE RENAME on a view rename the view's on-select rule too.
Needed to keep pg_dump from getting confused.
parent
a0c449a0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
117 additions
and
45 deletions
+117
-45
src/backend/commands/rename.c
src/backend/commands/rename.c
+16
-1
src/backend/commands/view.c
src/backend/commands/view.c
+2
-34
src/backend/rewrite/rewriteDefine.c
src/backend/rewrite/rewriteDefine.c
+50
-1
src/backend/rewrite/rewriteSupport.c
src/backend/rewrite/rewriteSupport.c
+39
-2
src/backend/utils/adt/ruleutils.c
src/backend/utils/adt/ruleutils.c
+2
-2
src/include/commands/view.h
src/include/commands/view.h
+1
-2
src/include/rewrite/rewriteDefine.h
src/include/rewrite/rewriteDefine.h
+3
-1
src/include/rewrite/rewriteSupport.h
src/include/rewrite/rewriteSupport.h
+4
-2
No files found.
src/backend/commands/rename.c
View file @
1b5cffac
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.5
6 2001/03/22 03:59:23 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.5
7 2001/08/12 21:35:18 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -26,6 +26,8 @@
...
@@ -26,6 +26,8 @@
#include "miscadmin.h"
#include "miscadmin.h"
#include "storage/smgr.h"
#include "storage/smgr.h"
#include "optimizer/prep.h"
#include "optimizer/prep.h"
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteSupport.h"
#include "utils/acl.h"
#include "utils/acl.h"
#include "utils/relcache.h"
#include "utils/relcache.h"
#include "utils/syscache.h"
#include "utils/syscache.h"
...
@@ -265,4 +267,17 @@ renamerel(const char *oldrelname, const char *newrelname)
...
@@ -265,4 +267,17 @@ renamerel(const char *oldrelname, const char *newrelname)
*/
*/
if
(
relkind
!=
RELKIND_INDEX
)
if
(
relkind
!=
RELKIND_INDEX
)
TypeRename
(
oldrelname
,
newrelname
);
TypeRename
(
oldrelname
,
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
(
oldrulename
,
newrulename
);
}
}
}
src/backend/commands/view.c
View file @
1b5cffac
...
@@ -6,11 +6,10 @@
...
@@ -6,11 +6,10 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: view.c,v 1.5
5 2001/08/10 18:57:35
tgl Exp $
* $Id: view.c,v 1.5
6 2001/08/12 21:35:18
tgl Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
#include "postgres.h"
#include "postgres.h"
#include "access/xact.h"
#include "access/xact.h"
...
@@ -24,10 +23,8 @@
...
@@ -24,10 +23,8 @@
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteManip.h"
#include "rewrite/rewriteManip.h"
#include "rewrite/rewriteRemove.h"
#include "rewrite/rewriteRemove.h"
#include "rewrite/rewriteSupport.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
#endif
/*---------------------------------------------------------------------
/*---------------------------------------------------------------------
* DefineVirtualRelation
* DefineVirtualRelation
...
@@ -100,35 +97,6 @@ DefineVirtualRelation(char *relname, List *tlist)
...
@@ -100,35 +97,6 @@ DefineVirtualRelation(char *relname, List *tlist)
DefineRelation
(
createStmt
,
RELKIND_VIEW
);
DefineRelation
(
createStmt
,
RELKIND_VIEW
);
}
}
/*------------------------------------------------------------------
* makeViewRetrieveRuleName
*
* Given a view name, returns the name for the 'on retrieve to "view"'
* rule.
*------------------------------------------------------------------
*/
char
*
MakeRetrieveViewRuleName
(
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
;
}
static
RuleStmt
*
static
RuleStmt
*
FormViewRetrieveRule
(
char
*
viewName
,
Query
*
viewParse
)
FormViewRetrieveRule
(
char
*
viewName
,
Query
*
viewParse
)
{
{
...
...
src/backend/rewrite/rewriteDefine.c
View file @
1b5cffac
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.6
2 2001/05/03 21:16:4
8 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.6
3 2001/08/12 21:35:1
8 tgl Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
#include "rewrite/rewriteSupport.h"
#include "rewrite/rewriteSupport.h"
#include "storage/smgr.h"
#include "storage/smgr.h"
#include "utils/builtins.h"
#include "utils/builtins.h"
#include "utils/syscache.h"
static
void
setRuleCheckAsUser
(
Query
*
qry
,
Oid
userid
);
static
void
setRuleCheckAsUser
(
Query
*
qry
,
Oid
userid
);
...
@@ -478,3 +479,51 @@ setRuleCheckAsUser_walker(Node *node, Oid *context)
...
@@ -478,3 +479,51 @@ setRuleCheckAsUser_walker(Node *node, Oid *context)
return
expression_tree_walker
(
node
,
setRuleCheckAsUser_walker
,
return
expression_tree_walker
(
node
,
setRuleCheckAsUser_walker
,
(
void
*
)
context
);
(
void
*
)
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.
*/
void
RenameRewriteRule
(
char
*
oldname
,
char
*
newname
)
{
Relation
pg_rewrite_desc
;
HeapTuple
ruletup
;
pg_rewrite_desc
=
heap_openr
(
RewriteRelationName
,
RowExclusiveLock
);
ruletup
=
SearchSysCacheCopy
(
RULENAME
,
PointerGetDatum
(
oldname
),
0
,
0
,
0
);
if
(
!
HeapTupleIsValid
(
ruletup
))
elog
(
ERROR
,
"RenameRewriteRule: rule
\"
%s
\"
does not exist"
,
oldname
);
/* should not already exist */
if
(
IsDefinedRewriteRule
(
newname
))
elog
(
ERROR
,
"Attempt to rename rule
\"
%s
\"
failed:
\"
%s
\"
already exists"
,
oldname
,
newname
);
StrNCpy
(
NameStr
(((
Form_pg_rewrite
)
GETSTRUCT
(
ruletup
))
->
rulename
),
newname
,
NAMEDATALEN
);
simple_heap_update
(
pg_rewrite_desc
,
&
ruletup
->
t_self
,
ruletup
);
/* keep system catalog indices current */
if
(
RelationGetForm
(
pg_rewrite_desc
)
->
relhasindex
)
{
Relation
idescs
[
Num_pg_rewrite_indices
];
CatalogOpenIndices
(
Num_pg_rewrite_indices
,
Name_pg_rewrite_indices
,
idescs
);
CatalogIndexInsert
(
idescs
,
Num_pg_rewrite_indices
,
pg_rewrite_desc
,
ruletup
);
CatalogCloseIndices
(
Num_pg_rewrite_indices
,
idescs
);
}
heap_freetuple
(
ruletup
);
heap_close
(
pg_rewrite_desc
,
RowExclusiveLock
);
}
src/backend/rewrite/rewriteSupport.c
View file @
1b5cffac
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.4
8 2001/03/22 03:59:44 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.4
9 2001/08/12 21:35:19 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -20,15 +20,52 @@
...
@@ -20,15 +20,52 @@
#include "rewrite/rewriteSupport.h"
#include "rewrite/rewriteSupport.h"
#include "utils/syscache.h"
#include "utils/syscache.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
#endif
/*
* Is there a rule by the given name?
*/
bool
bool
IsDefinedRewriteRule
(
char
*
ruleName
)
IsDefinedRewriteRule
(
c
onst
c
har
*
ruleName
)
{
{
return
SearchSysCacheExists
(
RULENAME
,
return
SearchSysCacheExists
(
RULENAME
,
PointerGetDatum
(
ruleName
),
PointerGetDatum
(
ruleName
),
0
,
0
,
0
);
0
,
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
* SetRelationRuleStatus
* Set the value of the relation's relhasrules field in pg_class;
* Set the value of the relation's relhasrules field in pg_class;
...
...
src/backend/utils/adt/ruleutils.c
View file @
1b5cffac
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
* back to source text
* back to source text
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.8
1 2001/07/31 17:56:31
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.8
2 2001/08/12 21:35:19
tgl Exp $
*
*
* This software is copyrighted by Jan Wieck - Hamburg.
* This software is copyrighted by Jan Wieck - Hamburg.
*
*
...
@@ -44,7 +44,6 @@
...
@@ -44,7 +44,6 @@
#include "catalog/pg_index.h"
#include "catalog/pg_index.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_shadow.h"
#include "catalog/pg_shadow.h"
#include "commands/view.h"
#include "executor/spi.h"
#include "executor/spi.h"
#include "lib/stringinfo.h"
#include "lib/stringinfo.h"
#include "optimizer/clauses.h"
#include "optimizer/clauses.h"
...
@@ -53,6 +52,7 @@
...
@@ -53,6 +52,7 @@
#include "parser/parse_expr.h"
#include "parser/parse_expr.h"
#include "parser/parsetree.h"
#include "parser/parsetree.h"
#include "rewrite/rewriteManip.h"
#include "rewrite/rewriteManip.h"
#include "rewrite/rewriteSupport.h"
#include "utils/lsyscache.h"
#include "utils/lsyscache.h"
...
...
src/include/commands/view.h
View file @
1b5cffac
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: view.h,v 1.
9 2001/01/24 19:43:23 momjian
Exp $
* $Id: view.h,v 1.
10 2001/08/12 21:35:19 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
#include "nodes/parsenodes.h"
#include "nodes/parsenodes.h"
extern
char
*
MakeRetrieveViewRuleName
(
char
*
view_name
);
extern
void
DefineView
(
char
*
view_name
,
Query
*
view_parse
);
extern
void
DefineView
(
char
*
view_name
,
Query
*
view_parse
);
extern
void
RemoveView
(
char
*
view_name
);
extern
void
RemoveView
(
char
*
view_name
);
...
...
src/include/rewrite/rewriteDefine.h
View file @
1b5cffac
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: rewriteDefine.h,v 1.
9 2001/01/24 19:43:27 momjian
Exp $
* $Id: rewriteDefine.h,v 1.
10 2001/08/12 21:35:19 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -18,4 +18,6 @@
...
@@ -18,4 +18,6 @@
extern
void
DefineQueryRewrite
(
RuleStmt
*
args
);
extern
void
DefineQueryRewrite
(
RuleStmt
*
args
);
extern
void
RenameRewriteRule
(
char
*
oldname
,
char
*
newname
);
#endif
/* REWRITEDEFINE_H */
#endif
/* REWRITEDEFINE_H */
src/include/rewrite/rewriteSupport.h
View file @
1b5cffac
...
@@ -7,14 +7,16 @@
...
@@ -7,14 +7,16 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: rewriteSupport.h,v 1.1
6 2001/03/22 04:01:04 momjian
Exp $
* $Id: rewriteSupport.h,v 1.1
7 2001/08/12 21:35:19 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
#ifndef REWRITESUPPORT_H
#ifndef REWRITESUPPORT_H
#define REWRITESUPPORT_H
#define REWRITESUPPORT_H
extern
bool
IsDefinedRewriteRule
(
char
*
ruleName
);
extern
bool
IsDefinedRewriteRule
(
const
char
*
ruleName
);
extern
char
*
MakeRetrieveViewRuleName
(
const
char
*
view_name
);
extern
void
SetRelationRuleStatus
(
Oid
relationId
,
bool
relHasRules
,
extern
void
SetRelationRuleStatus
(
Oid
relationId
,
bool
relHasRules
,
bool
relIsBecomingView
);
bool
relIsBecomingView
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment