summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorAlvaro Herrera2012-10-31 13:52:55 +0000
committerAlvaro Herrera2012-10-31 13:52:55 +0000
commit04f28bdb8477ad48c7f9987950595764eae3218e (patch)
tree50a351b9699ce36e50f93f3181460cccaca4d937 /src/include
parent4af3dda13601d859a20425e3554533fde0549056 (diff)
Fix ALTER EXTENSION / SET SCHEMA
In its original conception, it was leaving some objects into the old schema, but without their proper pg_depend entries; this meant that the old schema could be dropped, causing future pg_dump calls to fail on the affected database. This was originally reported by Jeff Frost as #6704; there have been other complaints elsewhere that can probably be traced to this bug. To fix, be more consistent about altering a table's subsidiary objects along the table itself; this requires some restructuring in how tables are relocated when altering an extension -- hence the new AlterTableNamespaceInternal routine which encapsulates it for both the ALTER TABLE and the ALTER EXTENSION cases. There was another bug lurking here, which was unmasked after fixing the previous one: certain objects would be reached twice via the dependency graph, and the second attempt to move them would cause the entire operation to fail. Per discussion, it seems the best fix for this is to do more careful tracking of objects already moved: we now maintain a list of moved objects, to avoid attempting to do it twice for the same object. Authors: Alvaro Herrera, Dimitri Fontaine Reviewed by Tom Lane
Diffstat (limited to 'src/include')
-rw-r--r--src/include/catalog/pg_constraint.h3
-rw-r--r--src/include/commands/alter.h4
-rw-r--r--src/include/commands/tablecmds.h7
-rw-r--r--src/include/commands/typecmds.h8
4 files changed, 16 insertions, 6 deletions
diff --git a/src/include/catalog/pg_constraint.h b/src/include/catalog/pg_constraint.h
index 9a1c8906843..e4e9c40ca75 100644
--- a/src/include/catalog/pg_constraint.h
+++ b/src/include/catalog/pg_constraint.h
@@ -20,6 +20,7 @@
#define PG_CONSTRAINT_H
#include "catalog/genbki.h"
+#include "catalog/dependency.h"
#include "nodes/pg_list.h"
/* ----------------
@@ -244,7 +245,7 @@ extern char *ChooseConstraintName(const char *name1, const char *name2,
List *others);
extern void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
- Oid newNspId, bool isType);
+ Oid newNspId, bool isType, ObjectAddresses *objsMoved);
extern Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok);
extern Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok);
diff --git a/src/include/commands/alter.h b/src/include/commands/alter.h
index 84135457d11..4493985ad38 100644
--- a/src/include/commands/alter.h
+++ b/src/include/commands/alter.h
@@ -14,13 +14,15 @@
#ifndef ALTER_H
#define ALTER_H
+#include "catalog/dependency.h"
#include "nodes/parsenodes.h"
#include "utils/relcache.h"
extern void ExecRenameStmt(RenameStmt *stmt);
extern void ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt);
-extern Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid);
+extern Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid,
+ ObjectAddresses *objsMoved);
extern Oid AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid);
extern void ExecAlterOwnerStmt(AlterOwnerStmt *stmt);
diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h
index 15d4713cec1..4f32062056f 100644
--- a/src/include/commands/tablecmds.h
+++ b/src/include/commands/tablecmds.h
@@ -15,6 +15,7 @@
#define TABLECMDS_H
#include "access/htup.h"
+#include "catalog/dependency.h"
#include "nodes/parsenodes.h"
#include "storage/lock.h"
#include "utils/relcache.h"
@@ -36,9 +37,13 @@ extern void AlterTableInternal(Oid relid, List *cmds, bool recurse);
extern void AlterTableNamespace(AlterObjectSchemaStmt *stmt);
+extern void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid,
+ Oid nspOid, ObjectAddresses *objsMoved);
+
extern void AlterRelationNamespaceInternal(Relation classRel, Oid relOid,
Oid oldNspOid, Oid newNspOid,
- bool hasDependEntry);
+ bool hasDependEntry,
+ ObjectAddresses *objsMoved);
extern void CheckTableNotInUse(Relation rel, const char *stmt);
diff --git a/src/include/commands/typecmds.h b/src/include/commands/typecmds.h
index b72cfc4fd94..2351024c221 100644
--- a/src/include/commands/typecmds.h
+++ b/src/include/commands/typecmds.h
@@ -15,6 +15,7 @@
#define TYPECMDS_H
#include "access/htup.h"
+#include "catalog/dependency.h"
#include "nodes/parsenodes.h"
@@ -45,9 +46,10 @@ extern void AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype);
extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
bool hasDependEntry);
extern void AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype);
-extern Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid);
-extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
+extern Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses *objsMoved);
+extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
bool isImplicitArray,
- bool errorOnTableType);
+ bool errorOnTableType,
+ ObjectAddresses *objsMoved);
#endif /* TYPECMDS_H */