pgsql-v9.3-alter-namespace-specials.patch
application/octet-stream
Filename: pgsql-v9.3-alter-namespace-specials.patch
Type: application/octet-stream
Part: 0
Patch
Format: unified
Series: patch v9
| File | + | − |
|---|---|---|
| src/backend/commands/alter.c | 10 | 18 |
| src/backend/commands/collationcmds.c | 1 | 24 |
| src/backend/commands/functioncmds.c | 1 | 30 |
| src/include/commands/collationcmds.h | 2 | 2 |
| src/include/commands/defrem.h | 2 | 3 |
src/backend/commands/alter.c | 28 ++++++++++------------------
src/backend/commands/collationcmds.c | 25 +------------------------
src/backend/commands/functioncmds.c | 31 +------------------------------
src/include/commands/collationcmds.h | 4 ++--
src/include/commands/defrem.h | 5 ++---
5 files changed, 16 insertions(+), 77 deletions(-)
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c
index f628754..85d4a2c 100644
--- a/src/backend/commands/alter.c
+++ b/src/backend/commands/alter.c
@@ -19,9 +19,11 @@
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
+#include "catalog/pg_collation.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "catalog/pg_namespace.h"
+#include "catalog/pg_proc.h"
#include "commands/alter.h"
#include "commands/collationcmds.h"
#include "commands/conversioncmds.h"
@@ -146,20 +148,9 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
{
switch (stmt->objectType)
{
- case OBJECT_AGGREGATE:
- return AlterFunctionNamespace(stmt->object, stmt->objarg, true,
- stmt->newschema);
-
- case OBJECT_COLLATION:
- return AlterCollationNamespace(stmt->object, stmt->newschema);
-
case OBJECT_EXTENSION:
return AlterExtensionNamespace(stmt->object, stmt->newschema);
- case OBJECT_FUNCTION:
- return AlterFunctionNamespace(stmt->object, stmt->objarg, false,
- stmt->newschema);
-
case OBJECT_SEQUENCE:
case OBJECT_TABLE:
case OBJECT_VIEW:
@@ -172,6 +163,9 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
stmt->objectType);
/* generic code path */
+ case OBJECT_AGGREGATE:
+ case OBJECT_FUNCTION:
+ case OBJECT_COLLATION:
case OBJECT_CONVERSION:
case OBJECT_OPERATOR:
case OBJECT_OPCLASS:
@@ -253,18 +247,12 @@ AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid,
break;
}
- case OCLASS_PROC:
- oldNspOid = AlterFunctionNamespace_oid(objid, nspOid);
- break;
-
case OCLASS_TYPE:
oldNspOid = AlterTypeNamespace_oid(objid, nspOid, objsMoved);
break;
+ case OCLASS_PROC:
case OCLASS_COLLATION:
- oldNspOid = AlterCollationNamespace_oid(objid, nspOid);
- break;
-
case OCLASS_CONVERSION:
case OCLASS_OPERATOR:
case OCLASS_OPCLASS:
@@ -380,6 +368,10 @@ AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
errmsg("%s already exists in schema \"%s\"",
getObjectDescriptionOids(classId, objid),
get_namespace_name(nspOid))));
+ else if (classId == ProcedureRelationId)
+ AlterFunctionNamespace_oid(rel, objid, nspOid);
+ else if (classId == CollationRelationId)
+ AlterCollationNamespace_oid(rel, objid, nspOid);
/* Build modified tuple */
values = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(Datum));
diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c
index b763f15..0450e3a 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -213,35 +213,14 @@ RenameCollation(List *name, const char *newname)
}
/*
- * Execute ALTER COLLATION SET SCHEMA
- */
-Oid
-AlterCollationNamespace(List *name, const char *newschema)
-{
- Oid collOid,
- nspOid;
-
- collOid = get_collation_oid(name, false);
-
- nspOid = LookupCreationNamespace(newschema);
-
- AlterCollationNamespace_oid(collOid, nspOid);
-
- return collOid;
-}
-
-/*
* Change collation schema, by oid
*/
Oid
-AlterCollationNamespace_oid(Oid collOid, Oid newNspOid)
+AlterCollationNamespace_oid(Relation rel, Oid collOid, Oid newNspOid)
{
Oid oldNspOid;
- Relation rel;
char *collation_name;
- rel = heap_open(CollationRelationId, RowExclusiveLock);
-
/*
* We have to check for name collision ourselves, because
* AlterObjectNamespace_internal doesn't know how to deal with the encoding
@@ -277,7 +256,5 @@ AlterCollationNamespace_oid(Oid collOid, Oid newNspOid)
/* OK, do the work */
oldNspOid = AlterObjectNamespace_internal(rel, collOid, newNspOid);
- heap_close(rel, RowExclusiveLock);
-
return oldNspOid;
}
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index c858511..ec34358 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1693,36 +1693,12 @@ DropCastById(Oid castOid)
* These commands are identical except for the lookup procedure, so share code.
*/
Oid
-AlterFunctionNamespace(List *name, List *argtypes, bool isagg,
- const char *newschema)
-{
- Oid procOid;
- Oid nspOid;
-
- /* get function OID */
- if (isagg)
- procOid = LookupAggNameTypeNames(name, argtypes, false);
- else
- procOid = LookupFuncNameTypeNames(name, argtypes, false);
-
- /* get schema OID and check its permissions */
- nspOid = LookupCreationNamespace(newschema);
-
- AlterFunctionNamespace_oid(procOid, nspOid);
-
- return procOid;
-}
-
-Oid
-AlterFunctionNamespace_oid(Oid procOid, Oid nspOid)
+AlterFunctionNamespace_oid(Relation procRel, Oid procOid, Oid nspOid)
{
Oid oldNspOid;
HeapTuple tup;
- Relation procRel;
Form_pg_proc proc;
- procRel = heap_open(ProcedureRelationId, RowExclusiveLock);
-
/*
* We have to check for name collisions ourselves, because
* AlterObjectNamespace_internal doesn't know how to deal with the
@@ -1744,11 +1720,6 @@ AlterFunctionNamespace_oid(Oid procOid, Oid nspOid)
NameStr(proc->proname),
get_namespace_name(nspOid))));
- /* OK, do the work */
- oldNspOid = AlterObjectNamespace_internal(procRel, procOid, nspOid);
-
- heap_close(procRel, RowExclusiveLock);
-
return oldNspOid;
}
diff --git a/src/include/commands/collationcmds.h b/src/include/commands/collationcmds.h
index c7b536a..debab8e 100644
--- a/src/include/commands/collationcmds.h
+++ b/src/include/commands/collationcmds.h
@@ -19,7 +19,7 @@
extern Oid DefineCollation(List *names, List *parameters);
extern Oid RenameCollation(List *name, const char *newname);
-extern Oid AlterCollationNamespace(List *name, const char *newschema);
-extern Oid AlterCollationNamespace_oid(Oid collOid, Oid newNspOid);
+extern Oid AlterCollationNamespace_oid(Relation rel,
+ Oid collOid, Oid newNspOid);
#endif /* COLLATIONCMDS_H */
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index c327136..981060f 100644
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -15,6 +15,7 @@
#define DEFREM_H
#include "nodes/parsenodes.h"
+#include "utils/rel.h"
/* commands/dropcmds.c */
extern void RemoveObjects(DropStmt *stmt);
@@ -50,9 +51,7 @@ extern Oid RenameFunction(List *name, List *argtypes, const char *newname);
extern Oid AlterFunction(AlterFunctionStmt *stmt);
extern Oid CreateCast(CreateCastStmt *stmt);
extern void DropCastById(Oid castOid);
-extern Oid AlterFunctionNamespace(List *name, List *argtypes, bool isagg,
- const char *newschema);
-extern Oid AlterFunctionNamespace_oid(Oid procOid, Oid nspOid);
+extern Oid AlterFunctionNamespace_oid(Relation rel, Oid procOid, Oid nspOid);
extern void ExecuteDoStmt(DoStmt *stmt);
extern Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok);