Allow REASSIGNED OWNED to handle opclasses and opfamilies.
authorRobert Haas <rhaas@postgresql.org>
Sat, 3 Jul 2010 13:53:26 +0000 (13:53 +0000)
committerRobert Haas <rhaas@postgresql.org>
Sat, 3 Jul 2010 13:53:26 +0000 (13:53 +0000)
Backpatch to 8.3, which is as far back as we have opfamilies.
The opclass portion could probably be backpatched to 8.2, when
REASSIGN OWNED was added, but for now I have not done that.

Asko Tiidumaa, with minor adjustments by me.

src/backend/catalog/pg_shdepend.c
src/backend/commands/opclasscmds.c
src/include/commands/defrem.h

index 08977c38633e4643e7c1a07e672816bb11077b4b..d66b69157e6180abb99c29e239be339d92c13847 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.34 2009/06/11 14:48:55 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.34.2.1 2010/07/03 13:53:26 rhaas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -26,6 +26,8 @@
 #include "catalog/pg_language.h"
 #include "catalog/pg_namespace.h"
 #include "catalog/pg_operator.h"
+#include "catalog/pg_opclass.h"
+#include "catalog/pg_opfamily.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_shdepend.h"
 #include "catalog/pg_tablespace.h"
@@ -1365,6 +1367,14 @@ shdepReassignOwned(List *roleids, Oid newrole)
                                        AlterLanguageOwner_oid(sdepForm->objid, newrole);
                                        break;
 
+                               case OperatorClassRelationId:
+                                       AlterOpClassOwner_oid(sdepForm->objid, newrole);
+                                       break;
+
+                               case OperatorFamilyRelationId:
+                                       AlterOpFamilyOwner_oid(sdepForm->objid, newrole);
+                                       break;
+
                                default:
                                        elog(ERROR, "unexpected classid %d", sdepForm->classid);
                                        break;
index 4f0693a9ac4b91d4c673da864670a1e6930e6ceb..811e84ad6f99bd6a83bd1ac5128c9670730ec2ff 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.64 2009/01/01 17:23:39 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.64.2.1 2010/07/03 13:53:26 rhaas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1993,6 +1993,27 @@ AlterOpClassOwner(List *name, const char *access_method, Oid newOwnerId)
        heap_close(rel, NoLock);
 }
 
+/*
+ * Change operator class owner, specified by OID
+ */
+void
+AlterOpClassOwner_oid(Oid opclassOid, Oid newOwnerId)
+{
+       HeapTuple       tup;
+       Relation        rel;
+
+       rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
+
+       tup = SearchSysCacheCopy(CLAOID, ObjectIdGetDatum(opclassOid), 0, 0, 0);
+       if (!HeapTupleIsValid(tup))
+               elog(ERROR, "cache lookup failed for opclass %u", opclassOid);
+
+       AlterOpClassOwner_internal(rel, tup, newOwnerId);
+
+       heap_freetuple(tup);
+       heap_close(rel, NoLock);
+}
+
 /*
  * The first parameter is pg_opclass, opened and suitably locked.  The second
  * parameter is a copy of the tuple from pg_opclass we want to modify.
@@ -2120,6 +2141,28 @@ AlterOpFamilyOwner(List *name, const char *access_method, Oid newOwnerId)
        heap_close(rel, NoLock);
 }
 
+/*
+ * Change operator family owner, specified by OID
+ */
+void
+AlterOpFamilyOwner_oid(Oid opfamilyOid, Oid newOwnerId)
+{
+       HeapTuple       tup;
+       Relation        rel;
+
+       rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock);
+
+       tup = SearchSysCacheCopy(OPFAMILYOID, ObjectIdGetDatum(opfamilyOid),
+                                                        0, 0, 0);
+       if (!HeapTupleIsValid(tup))
+               elog(ERROR, "cache lookup failed for opfamily %u", opfamilyOid);
+
+       AlterOpFamilyOwner_internal(rel, tup, newOwnerId);
+
+       heap_freetuple(tup);
+       heap_close(rel, NoLock);
+}
+
 /*
  * The first parameter is pg_opfamily, opened and suitably locked.     The second
  * parameter is a copy of the tuple from pg_opfamily we want to modify.
index 4658a314f7d104bc533c3bff22f7692821371c1a..b326dc2a4070da7d1b660bee93c169f3e1854466 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.94 2009/04/04 21:12:31 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.94.2.1 2010/07/03 13:53:26 rhaas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -88,7 +88,9 @@ extern void RemoveAmProcEntryById(Oid entryOid);
 extern void RenameOpClass(List *name, const char *access_method, const char *newname);
 extern void RenameOpFamily(List *name, const char *access_method, const char *newname);
 extern void AlterOpClassOwner(List *name, const char *access_method, Oid newOwnerId);
+extern void AlterOpClassOwner_oid(Oid opclassOid, Oid newOwnerId);
 extern void AlterOpFamilyOwner(List *name, const char *access_method, Oid newOwnerId);
+extern void AlterOpFamilyOwner_oid(Oid opfamilyOid, Oid newOwnerId);
 
 /* commands/tsearchcmds.c */
 extern void DefineTSParser(List *names, List *parameters);