Dimitri Fontaine <dimi...@2ndquadrant.fr> writes:
> I think we shouldn't change the content of pg_depend lightly here, and

So here's a patch following that idea.

Even for TIP I don't want us to change how pg_depend tracking is done,
because I want to propose a fix for the pg_dump bug wrt sequences and
pg_extension_config_dump() wherein you can actually register a sequence
(owned by a table or not) but then pg_dump fails to dump it (see report
from Marko Kreen)

  
http://archives.postgresql.org/message-id/cacmqxcjjauc9jpa64vxskrn67byjuymodz-mgy-_aoz6erg...@mail.gmail.com

Regards,
-- 
Dimitri Fontaine
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support
*** a/src/backend/commands/alter.c
--- b/src/backend/commands/alter.c
***************
*** 18,23 ****
--- 18,24 ----
  #include "catalog/dependency.h"
  #include "catalog/indexing.h"
  #include "catalog/namespace.h"
+ #include "catalog/pg_constraint.h"
  #include "catalog/pg_largeobject.h"
  #include "catalog/pg_namespace.h"
  #include "commands/alter.h"
***************
*** 268,278 **** AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid)
  
  				classRel = heap_open(RelationRelationId, RowExclusiveLock);
  
! 				AlterRelationNamespaceInternal(classRel,
! 											   objid,
! 											   oldNspOid,
! 											   nspOid,
! 											   true);
  
  				heap_close(classRel, RowExclusiveLock);
  
--- 269,282 ----
  
  				classRel = heap_open(RelationRelationId, RowExclusiveLock);
  
! 				AlterRelationNamespace_oid(rel,
! 										   classRel,
! 										   objid,
! 										   oldNspOid,
! 										   nspOid,
! 										   true,
! 										   false,
! 										   NULL);
  
  				heap_close(classRel, RowExclusiveLock);
  
*** a/src/backend/commands/tablecmds.c
--- b/src/backend/commands/tablecmds.c
***************
*** 260,267 **** static void StoreCatalogInheritance(Oid relationId, List *supers);
  static void StoreCatalogInheritance1(Oid relationId, Oid parentOid,
  						 int16 seqNumber, Relation inhRelation);
  static int	findAttrByName(const char *attributeName, List *schema);
- static void AlterIndexNamespaces(Relation classRel, Relation rel,
- 					 Oid oldNspOid, Oid newNspOid);
  static void AlterSeqNamespaces(Relation classRel, Relation rel,
  				   Oid oldNspOid, Oid newNspOid,
  				   const char *newNspName, LOCKMODE lockmode);
--- 260,265 ----
***************
*** 9755,9761 **** AlterTableNamespace(AlterObjectSchemaStmt *stmt)
  	/* OK, modify the pg_class row and pg_depend entry */
  	classRel = heap_open(RelationRelationId, RowExclusiveLock);
  
! 	AlterRelationNamespaceInternal(classRel, relid, oldNspOid, nspOid, true);
  
  	/* Fix the table's row type too */
  	AlterTypeNamespaceInternal(rel->rd_rel->reltype, nspOid, false, false);
--- 9753,9789 ----
  	/* OK, modify the pg_class row and pg_depend entry */
  	classRel = heap_open(RelationRelationId, RowExclusiveLock);
  
! 	AlterRelationNamespace_oid(rel,
! 							   classRel,
! 							   relid,
! 							   oldNspOid,
! 							   nspOid,
! 							   true,
! 							   true,
! 							   stmt->newschema);
! 
! 	heap_close(classRel, RowExclusiveLock);
! 
! 	/* close rel, but keep lock until commit */
! 	relation_close(rel, NoLock);
! }
! 
! /*
!  * Relocating a relation to another namespace, and its related objects too.
!  *
!  * Extensions track both the main table and its owned sequences so it's not
!  * necessary to alter the namespace of those sequences when doing ALTER
!  * EXTENSION ... SET SCHEMA. alterSeqNamespaces is then false and newschema is
!  * NULL.
!  */
! void
! AlterRelationNamespace_oid(Relation rel, Relation classRel, Oid relOid,
! 						   Oid oldNspOid, Oid nspOid,
! 						   bool hasDependEntry,
! 						   bool alterSeqNamespaces,
! 						   char *newschema)
! {
! 	AlterRelationNamespaceInternal(classRel, relOid, oldNspOid, nspOid, true);
  
  	/* Fix the table's row type too */
  	AlterTypeNamespaceInternal(rel->rd_rel->reltype, nspOid, false, false);
***************
*** 9764,9778 **** AlterTableNamespace(AlterObjectSchemaStmt *stmt)
  	if (rel->rd_rel->relkind == RELKIND_RELATION)
  	{
  		AlterIndexNamespaces(classRel, rel, oldNspOid, nspOid);
- 		AlterSeqNamespaces(classRel, rel, oldNspOid, nspOid, stmt->newschema,
- 						   AccessExclusiveLock);
- 		AlterConstraintNamespaces(relid, oldNspOid, nspOid, false);
- 	}
- 
- 	heap_close(classRel, RowExclusiveLock);
  
! 	/* close rel, but keep lock until commit */
! 	relation_close(rel, NoLock);
  }
  
  /*
--- 9792,9804 ----
  	if (rel->rd_rel->relkind == RELKIND_RELATION)
  	{
  		AlterIndexNamespaces(classRel, rel, oldNspOid, nspOid);
  
! 		if (alterSeqNamespaces)
! 			AlterSeqNamespaces(classRel, rel, oldNspOid, nspOid,
! 							   newschema,
! 							   AccessExclusiveLock);
! 		AlterConstraintNamespaces(relOid, oldNspOid, nspOid, false);
! 	}
  }
  
  /*
***************
*** 9826,9832 **** AlterRelationNamespaceInternal(Relation classRel, Oid relOid,
   * Note: we assume adequate permission checking was done by the caller,
   * and that the caller has a suitable lock on the owning relation.
   */
! static void
  AlterIndexNamespaces(Relation classRel, Relation rel,
  					 Oid oldNspOid, Oid newNspOid)
  {
--- 9852,9858 ----
   * Note: we assume adequate permission checking was done by the caller,
   * and that the caller has a suitable lock on the owning relation.
   */
! void
  AlterIndexNamespaces(Relation classRel, Relation rel,
  					 Oid oldNspOid, Oid newNspOid)
  {
*** a/src/include/commands/tablecmds.h
--- b/src/include/commands/tablecmds.h
***************
*** 36,41 **** extern void AlterTableInternal(Oid relid, List *cmds, bool recurse);
--- 36,51 ----
  
  extern void AlterTableNamespace(AlterObjectSchemaStmt *stmt);
  
+ extern void AlterIndexNamespaces(Relation classRel, Relation rel,
+ 								 Oid oldNspOid, Oid newNspOid);
+ 
+ extern void AlterRelationNamespace_oid(Relation rel,
+ 									   Relation classRel, Oid relOid,
+ 									   Oid oldNspOid, Oid newNspOid,
+ 									   bool hasDependEntry,
+ 									   bool alterSeqNamespaces,
+ 									   char *newschema);
+ 
  extern void AlterRelationNamespaceInternal(Relation classRel, Oid relOid,
  							   Oid oldNspOid, Oid newNspOid,
  							   bool hasDependEntry);
-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to