]> granicus.if.org Git - postgresql/commitdiff
Change many routines to return ObjectAddress rather than OID
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 3 Mar 2015 17:10:50 +0000 (14:10 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 3 Mar 2015 17:10:50 +0000 (14:10 -0300)
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.

Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command.  To wit:

* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
  the new constraint

* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
  schema that originally contained the object.

* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
  of the object added to or dropped from the extension.

There's no user-visible change in this commit, and no functional change
either.

Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
68 files changed:
src/backend/bootstrap/bootparse.y
src/backend/catalog/heap.c
src/backend/catalog/objectaddress.c
src/backend/catalog/pg_aggregate.c
src/backend/catalog/pg_conversion.c
src/backend/catalog/pg_operator.c
src/backend/catalog/pg_proc.c
src/backend/catalog/pg_type.c
src/backend/catalog/toasting.c
src/backend/commands/aggregatecmds.c
src/backend/commands/alter.c
src/backend/commands/cluster.c
src/backend/commands/collationcmds.c
src/backend/commands/comment.c
src/backend/commands/conversioncmds.c
src/backend/commands/createas.c
src/backend/commands/dbcommands.c
src/backend/commands/event_trigger.c
src/backend/commands/extension.c
src/backend/commands/foreigncmds.c
src/backend/commands/functioncmds.c
src/backend/commands/indexcmds.c
src/backend/commands/matview.c
src/backend/commands/opclasscmds.c
src/backend/commands/operatorcmds.c
src/backend/commands/policy.c
src/backend/commands/proclang.c
src/backend/commands/schemacmds.c
src/backend/commands/seclabel.c
src/backend/commands/sequence.c
src/backend/commands/tablecmds.c
src/backend/commands/tablespace.c
src/backend/commands/trigger.c
src/backend/commands/tsearchcmds.c
src/backend/commands/typecmds.c
src/backend/commands/user.c
src/backend/commands/view.c
src/backend/rewrite/rewriteDefine.c
src/backend/tcop/utility.c
src/include/catalog/heap.h
src/include/catalog/objectaddress.h
src/include/catalog/pg_aggregate.h
src/include/catalog/pg_conversion_fn.h
src/include/catalog/pg_operator.h
src/include/catalog/pg_proc_fn.h
src/include/catalog/pg_type_fn.h
src/include/commands/alter.h
src/include/commands/collationcmds.h
src/include/commands/comment.h
src/include/commands/conversioncmds.h
src/include/commands/createas.h
src/include/commands/dbcommands.h
src/include/commands/defrem.h
src/include/commands/event_trigger.h
src/include/commands/extension.h
src/include/commands/matview.h
src/include/commands/policy.h
src/include/commands/proclang.h
src/include/commands/schemacmds.h
src/include/commands/seclabel.h
src/include/commands/sequence.h
src/include/commands/tablecmds.h
src/include/commands/tablespace.h
src/include/commands/trigger.h
src/include/commands/typecmds.h
src/include/commands/user.h
src/include/commands/view.h
src/include/rewrite/rewriteDefine.h

index fdb1f7faacec9bcd4aaa7b7235281c370f8246ee..6e563b67e617b4c026faa0c367b0f00382cf10d3 100644 (file)
@@ -251,7 +251,8 @@ Boot_CreateStmt:
                                                                                                          (Datum) 0,
                                                                                                          false,
                                                                                                          true,
-                                                                                                         false);
+                                                                                                         false,
+                                                                                                         NULL);
                                                elog(DEBUG4, "relation created with OID %u", id);
                                        }
                                        do_end();
index 1a64436d90d11192787e3f996c28245a41b139a3..5ce43957d9fef19def0bbffb5ac6aeecebedc34b 100644 (file)
@@ -89,7 +89,7 @@ static void AddNewRelationTuple(Relation pg_class_desc,
                                        char relkind,
                                        Datum relacl,
                                        Datum reloptions);
-static Oid AddNewRelationType(const char *typeName,
+static ObjectAddress AddNewRelationType(const char *typeName,
                                   Oid typeNamespace,
                                   Oid new_rel_oid,
                                   char new_rel_kind,
@@ -935,7 +935,7 @@ AddNewRelationTuple(Relation pg_class_desc,
  *             define a composite type corresponding to the new relation
  * --------------------------------
  */
-static Oid
+static ObjectAddress
 AddNewRelationType(const char *typeName,
                                   Oid typeNamespace,
                                   Oid new_rel_oid,
@@ -1006,6 +1006,9 @@ AddNewRelationType(const char *typeName,
  *     allow_system_table_mods: TRUE to allow creation in system namespaces
  *     is_internal: is this a system-generated catalog?
  *
+ * Output parameters:
+ *     typaddress: if not null, gets the object address of the new pg_type entry
+ *
  * Returns the OID of the new relation
  * --------------------------------
  */
@@ -1029,7 +1032,8 @@ heap_create_with_catalog(const char *relname,
                                                 Datum reloptions,
                                                 bool use_user_acl,
                                                 bool allow_system_table_mods,
-                                                bool is_internal)
+                                                bool is_internal,
+                                                ObjectAddress *typaddress)
 {
        Relation        pg_class_desc;
        Relation        new_rel_desc;
@@ -1037,6 +1041,7 @@ heap_create_with_catalog(const char *relname,
        Oid                     existing_relid;
        Oid                     old_type_oid;
        Oid                     new_type_oid;
+       ObjectAddress new_type_addr;
        Oid                     new_array_oid = InvalidOid;
 
        pg_class_desc = heap_open(RelationRelationId, RowExclusiveLock);
@@ -1187,13 +1192,16 @@ heap_create_with_catalog(const char *relname,
         * creating the same type name in parallel but hadn't committed yet when
         * we checked for a duplicate name above.
         */
-       new_type_oid = AddNewRelationType(relname,
-                                                                         relnamespace,
-                                                                         relid,
-                                                                         relkind,
-                                                                         ownerid,
-                                                                         reltypeid,
-                                                                         new_array_oid);
+       new_type_addr = AddNewRelationType(relname,
+                                                                          relnamespace,
+                                                                          relid,
+                                                                          relkind,
+                                                                          ownerid,
+                                                                          reltypeid,
+                                                                          new_array_oid);
+       new_type_oid = new_type_addr.objectId;
+       if (typaddress)
+               *typaddress = new_type_addr;
 
        /*
         * Now make the array type if wanted.
index d899dd73fefc724fb8ace42eabb9a9d50ecfb1f5..70043fca4f9de9ae2ccc94ccf32fed6d1f38b7fc 100644 (file)
@@ -531,6 +531,12 @@ ObjectTypeMap[] =
        { "policy", OBJECT_POLICY }
 };
 
+const ObjectAddress InvalidObjectAddress =
+{
+       InvalidOid,
+       InvalidOid,
+       0
+};
 
 static ObjectAddress get_object_address_unqualified(ObjectType objtype,
                                                           List *qualname, bool missing_ok);
index b56cf287fc17790c08b9c06066314f156905871f..df7bdfb03ca80a2d7b01d7a30e09041c475d1baa 100644 (file)
@@ -43,7 +43,7 @@ static Oid lookup_agg_function(List *fnName, int nargs, Oid *input_types,
 /*
  * AggregateCreate
  */
-Oid
+ObjectAddress
 AggregateCreate(const char *aggName,
                                Oid aggNamespace,
                                char aggKind,
@@ -522,32 +522,33 @@ AggregateCreate(const char *aggName,
         * aggregate.  (This could fail if there's already a conflicting entry.)
         */
 
-       procOid = ProcedureCreate(aggName,
-                                                         aggNamespace,
-                                                         false,        /* no replacement */
-                                                         false,        /* doesn't return a set */
-                                                         finaltype,            /* returnType */
-                                                         GetUserId(),          /* proowner */
-                                                         INTERNALlanguageId,           /* languageObjectId */
-                                                         InvalidOid,           /* no validator */
-                                                         "aggregate_dummy",            /* placeholder proc */
-                                                         NULL,         /* probin */
-                                                         true,         /* isAgg */
-                                                         false,        /* isWindowFunc */
-                                                         false,        /* security invoker (currently not
+       myself = ProcedureCreate(aggName,
+                                                        aggNamespace,
+                                                        false,         /* no replacement */
+                                                        false,         /* doesn't return a set */
+                                                        finaltype, /* returnType */
+                                                        GetUserId(),           /* proowner */
+                                                        INTERNALlanguageId,            /* languageObjectId */
+                                                        InvalidOid,            /* no validator */
+                                                        "aggregate_dummy", /* placeholder proc */
+                                                        NULL,          /* probin */
+                                                        true,          /* isAgg */
+                                                        false,         /* isWindowFunc */
+                                                        false,         /* security invoker (currently not
                                                                                 * definable for agg) */
-                                                         false,        /* isLeakProof */
-                                                         false,        /* isStrict (not needed for agg) */
-                                                         PROVOLATILE_IMMUTABLE,        /* volatility (not
+                                                        false,         /* isLeakProof */
+                                                        false,         /* isStrict (not needed for agg) */
+                                                        PROVOLATILE_IMMUTABLE,         /* volatility (not
                                                                                                                 * needed for agg) */
-                                                         parameterTypes,       /* paramTypes */
-                                                         allParameterTypes,            /* allParamTypes */
-                                                         parameterModes,       /* parameterModes */
-                                                         parameterNames,       /* parameterNames */
-                                                         parameterDefaults,            /* parameterDefaults */
-                                                         PointerGetDatum(NULL),        /* proconfig */
-                                                         1,    /* procost */
-                                                         0);           /* prorows */
+                                                        parameterTypes,        /* paramTypes */
+                                                        allParameterTypes, /* allParamTypes */
+                                                        parameterModes,        /* parameterModes */
+                                                        parameterNames,        /* parameterNames */
+                                                        parameterDefaults, /* parameterDefaults */
+                                                        PointerGetDatum(NULL),         /* proconfig */
+                                                        1, /* procost */
+                                                        0);    /* prorows */
+       procOid = myself.objectId;
 
        /*
         * Okay to create the pg_aggregate entry.
@@ -599,9 +600,6 @@ AggregateCreate(const char *aggName,
         * on aggTransType since we depend on it indirectly through transfn.
         * Likewise for aggmTransType if any.
         */
-       myself.classId = ProcedureRelationId;
-       myself.objectId = procOid;
-       myself.objectSubId = 0;
 
        /* Depends on transition function */
        referenced.classId = ProcedureRelationId;
@@ -654,7 +652,7 @@ AggregateCreate(const char *aggName,
                recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
        }
 
-       return procOid;
+       return myself;
 }
 
 /*
index c3a403968d0995965a07751b376b404b491ae007..7de738722bc82741623f89822e6e1a846ed4a131 100644 (file)
@@ -37,7 +37,7 @@
  *
  * Add a new tuple to pg_conversion.
  */
-Oid
+ObjectAddress
 ConversionCreate(const char *conname, Oid connamespace,
                                 Oid conowner,
                                 int32 conforencoding, int32 contoencoding,
@@ -141,7 +141,7 @@ ConversionCreate(const char *conname, Oid connamespace,
        heap_freetuple(tup);
        heap_close(rel, RowExclusiveLock);
 
-       return oid;
+       return myself;
 }
 
 /*
index fbc173be304ab15cb124716166e9e1ea109262e2..072f530d988e945e26e7395814a5e44a50168f82 100644 (file)
@@ -61,7 +61,7 @@ static Oid get_other_operator(List *otherOp,
                                   Oid leftTypeId, Oid rightTypeId,
                                   bool isCommutator);
 
-static void makeOperatorDependencies(HeapTuple tuple);
+static ObjectAddress makeOperatorDependencies(HeapTuple tuple);
 
 
 /*
@@ -325,7 +325,7 @@ OperatorShellMake(const char *operatorName,
  * Forward declaration is used only for this purpose, it is
  * not available to the user as it is for type definition.
  */
-Oid
+ObjectAddress
 OperatorCreate(const char *operatorName,
                           Oid operatorNamespace,
                           Oid leftTypeId,
@@ -352,6 +352,7 @@ OperatorCreate(const char *operatorName,
        NameData        oname;
        TupleDesc       tupDesc;
        int                     i;
+       ObjectAddress address;
 
        /*
         * Sanity checks
@@ -540,7 +541,7 @@ OperatorCreate(const char *operatorName,
        CatalogUpdateIndexes(pg_operator_desc, tup);
 
        /* Add dependencies for the entry */
-       makeOperatorDependencies(tup);
+       address = makeOperatorDependencies(tup);
 
        /* Post creation hook for new operator */
        InvokeObjectPostCreateHook(OperatorRelationId, operatorObjectId, 0);
@@ -564,7 +565,7 @@ OperatorCreate(const char *operatorName,
        if (OidIsValid(commutatorId) || OidIsValid(negatorId))
                OperatorUpd(operatorObjectId, commutatorId, negatorId);
 
-       return operatorObjectId;
+       return address;
 }
 
 /*
@@ -764,7 +765,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
  * NB: the OidIsValid tests in this routine are necessary, in case
  * the given operator is a shell.
  */
-static void
+static ObjectAddress
 makeOperatorDependencies(HeapTuple tuple)
 {
        Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tuple);
@@ -860,4 +861,6 @@ makeOperatorDependencies(HeapTuple tuple)
 
        /* Dependency on extension */
        recordDependencyOnCurrentExtension(&myself, true);
+
+       return myself;
 }
index 542539fbc31bb0a1369b7b2a47f8d53095f99268..fd5060aa7c176b9222be50bcad3e880235a15042 100644 (file)
@@ -64,7 +64,7 @@ static bool match_prosrc_to_literal(const char *prosrc, const char *literal,
  * not "ArrayType *", to avoid importing array.h into pg_proc_fn.h.
  * ----------------------------------------------------------------
  */
-Oid
+ObjectAddress
 ProcedureCreate(const char *procedureName,
                                Oid procNamespace,
                                bool replace,
@@ -703,7 +703,7 @@ ProcedureCreate(const char *procedureName,
                        AtEOXact_GUC(true, save_nestlevel);
        }
 
-       return retval;
+       return myself;
 }
 
 
index ed8259da5585cb3dae30e8a049ae96880a4669e5..d1ed53f5b4d1899019afe332af04ddb4977d97bb 100644 (file)
@@ -52,7 +52,7 @@ Oid                   binary_upgrade_next_pg_type_oid = InvalidOid;
  *             with correct ones, and "typisdefined" will be set to true.
  * ----------------------------------------------------------------
  */
-Oid
+ObjectAddress
 TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
 {
        Relation        pg_type_desc;
@@ -63,6 +63,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
        bool            nulls[Natts_pg_type];
        Oid                     typoid;
        NameData        name;
+       ObjectAddress address;
 
        Assert(PointerIsValid(typeName));
 
@@ -171,13 +172,15 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
        /* Post creation hook for new shell type */
        InvokeObjectPostCreateHook(TypeRelationId, typoid, 0);
 
+       ObjectAddressSet(address, TypeRelationId, typoid);
+
        /*
         * clean up and return the type-oid
         */
        heap_freetuple(tup);
        heap_close(pg_type_desc, RowExclusiveLock);
 
-       return typoid;
+       return address;
 }
 
 /* ----------------------------------------------------------------
@@ -185,12 +188,12 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
  *
  *             This does all the necessary work needed to define a new type.
  *
- *             Returns the OID assigned to the new type.  If newTypeOid is
- *             zero (the normal case), a new OID is created; otherwise we
- *             use exactly that OID.
+ *             Returns the ObjectAddress assigned to the new type.
+ *             If newTypeOid is zero (the normal case), a new OID is created;
+ *             otherwise we use exactly that OID.
  * ----------------------------------------------------------------
  */
-Oid
+ObjectAddress
 TypeCreate(Oid newTypeOid,
                   const char *typeName,
                   Oid typeNamespace,
@@ -233,6 +236,7 @@ TypeCreate(Oid newTypeOid,
        NameData        name;
        int                     i;
        Acl                *typacl = NULL;
+       ObjectAddress address;
 
        /*
         * We assume that the caller validated the arguments individually, but did
@@ -488,12 +492,14 @@ TypeCreate(Oid newTypeOid,
        /* Post creation hook for new type */
        InvokeObjectPostCreateHook(TypeRelationId, typeObjectId, 0);
 
+       ObjectAddressSet(address, TypeRelationId, typeObjectId);
+
        /*
         * finish up
         */
        heap_close(pg_type_desc, RowExclusiveLock);
 
-       return typeObjectId;
+       return address;
 }
 
 /*
index a1efddb98f33969dd95e1c98bb78b224c3a93be9..d14c33ce0218fbc572915cf606ab31c14e2512c4 100644 (file)
@@ -289,7 +289,8 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
                                                                                   reloptions,
                                                                                   false,
                                                                                   true,
-                                                                                  true);
+                                                                                  true,
+                                                                                  NULL);
        Assert(toast_relid != InvalidOid);
 
        /* make the toast relation visible, else heap_open will fail */
index 70a5b8ad1bb8b329fdbfc4c04ece24414345017f..894c89df947d33de129520cb9f681dd23f2e084e 100644 (file)
@@ -51,7 +51,7 @@
  * isn't an ordered-set aggregate.
  * "parameters" is a list of DefElem representing the agg's definition clauses.
  */
-Oid
+ObjectAddress
 DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
                                const char *queryString)
 {
index 78b54b4a4181373779b3f84e23055b7e0375c773..59aacef7ea947efeb7f78a0368463d777195f0ac 100644 (file)
@@ -299,8 +299,10 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
 /*
  * Executes an ALTER OBJECT / RENAME TO statement.  Based on the object
  * type, the function appropriate to that type is executed.
+ *
+ * Return value is the address of the renamed object.
  */
-Oid
+ObjectAddress
 ExecRenameStmt(RenameStmt *stmt)
 {
        switch (stmt->renameType)
@@ -378,39 +380,54 @@ ExecRenameStmt(RenameStmt *stmt)
                                                                                   stmt->newname);
                                heap_close(catalog, RowExclusiveLock);
 
-                               return address.objectId;
+                               return address;
                        }
 
                default:
                        elog(ERROR, "unrecognized rename stmt type: %d",
                                 (int) stmt->renameType);
-                       return InvalidOid;      /* keep compiler happy */
+                       return InvalidObjectAddress;            /* keep compiler happy */
        }
 }
 
 /*
  * Executes an ALTER OBJECT / SET SCHEMA statement.  Based on the object
  * type, the function appropriate to that type is executed.
+ *
+ * Return value is that of the altered object.
+ *
+ * oldSchemaAddr is an output argument which, if not NULL, is set to the object
+ * address of the original schema.
  */
-Oid
-ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
+ObjectAddress
+ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt,
+                                                 ObjectAddress *oldSchemaAddr)
 {
+       ObjectAddress address;
+       Oid                     oldNspOid;
+
        switch (stmt->objectType)
        {
                case OBJECT_EXTENSION:
-                       return AlterExtensionNamespace(stmt->object, stmt->newschema);
+                       address = AlterExtensionNamespace(stmt->object, stmt->newschema,
+                                                                                 oldSchemaAddr ? &oldNspOid : NULL);
+                       break;
 
                case OBJECT_FOREIGN_TABLE:
                case OBJECT_SEQUENCE:
                case OBJECT_TABLE:
                case OBJECT_VIEW:
                case OBJECT_MATVIEW:
-                       return AlterTableNamespace(stmt);
+                       address = AlterTableNamespace(stmt,
+                                                                                 oldSchemaAddr ? &oldNspOid : NULL);
+                       break;
 
                case OBJECT_DOMAIN:
                case OBJECT_TYPE:
-                       return AlterTypeNamespace(stmt->object, stmt->newschema,
-                                                                         stmt->objectType);
+                       address = AlterTypeNamespace(stmt->object, stmt->newschema,
+                                                                                stmt->objectType,
+                                                                                oldSchemaAddr ? &oldNspOid : NULL);
+                       break;
 
                        /* generic code path */
                case OBJECT_AGGREGATE:
@@ -442,19 +459,22 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
                                catalog = heap_open(classId, RowExclusiveLock);
                                nspOid = LookupCreationNamespace(stmt->newschema);
 
-                               AlterObjectNamespace_internal(catalog, address.objectId,
-                                                                                         nspOid);
+                               oldNspOid = AlterObjectNamespace_internal(catalog, address.objectId,
+                                                                                                                 nspOid);
                                heap_close(catalog, RowExclusiveLock);
-
-                               return address.objectId;
                        }
                        break;
 
                default:
                        elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d",
                                 (int) stmt->objectType);
-                       return InvalidOid;      /* keep compiler happy */
+                       return InvalidObjectAddress;            /* keep compiler happy */
        }
+
+       if (oldSchemaAddr)
+               ObjectAddressSet(*oldSchemaAddr, NamespaceRelationId, oldNspOid);
+
+       return address;
 }
 
 /*
@@ -676,7 +696,7 @@ AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
  * Executes an ALTER OBJECT / OWNER TO statement.  Based on the object
  * type, the function appropriate to that type is executed.
  */
-Oid
+ObjectAddress
 ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
 {
        Oid                     newowner = get_role_oid(stmt->newowner, false);
@@ -747,15 +767,14 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
                                AlterObjectOwner_internal(catalog, address.objectId, newowner);
                                heap_close(catalog, RowExclusiveLock);
 
-                               return address.objectId;
+                               return address;
                        }
                        break;
 
                default:
                        elog(ERROR, "unrecognized AlterOwnerStmt type: %d",
                                 (int) stmt->objectType);
-
-                       return InvalidOid;      /* keep compiler happy */
+                       return InvalidObjectAddress;            /* keep compiler happy */
        }
 }
 
index dc1b37cb69315212ac15e9a63b10c37dd4494c16..3febdd5cf44a88e0b8f077cf9e86243756cba504 100644 (file)
@@ -677,7 +677,8 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, char relpersistence,
                                                                                  reloptions,
                                                                                  false,
                                                                                  true,
-                                                                                 true);
+                                                                                 true,
+                                                                                 NULL);
        Assert(OIDNewHeap != InvalidOid);
 
        ReleaseSysCache(tuple);
index 4334eb96832c1b2b15db6855d5b2ab8c2a57a361..df67e50942032933b993af33dc60e7a60be79d54 100644 (file)
@@ -37,7 +37,7 @@
 /*
  * CREATE COLLATION
  */
-Oid
+ObjectAddress
 DefineCollation(List *names, List *parameters)
 {
        char       *collName;
@@ -51,6 +51,7 @@ DefineCollation(List *names, List *parameters)
        char       *collcollate = NULL;
        char       *collctype = NULL;
        Oid                     newoid;
+       ObjectAddress address;
 
        collNamespace = QualifiedNameGetCreationNamespace(names, &collName);
 
@@ -137,11 +138,13 @@ DefineCollation(List *names, List *parameters)
                                                         collcollate,
                                                         collctype);
 
+       ObjectAddressSet(address, CollationRelationId, newoid);
+
        /* check that the locales can be loaded */
        CommandCounterIncrement();
        (void) pg_newlocale_from_collation(newoid);
 
-       return newoid;
+       return address;
 }
 
 /*
index ed1e46e73c133a1aca70f17dbc282d814c89c696..6d8c0061bdc97245db58789e57c87cf28cbd3073 100644 (file)
  * This routine is used to add the associated comment into
  * pg_description for the object specified by the given SQL command.
  */
-Oid
+ObjectAddress
 CommentObject(CommentStmt *stmt)
 {
-       ObjectAddress address;
        Relation        relation;
+       ObjectAddress address = InvalidObjectAddress;
 
        /*
         * When loading a dump, we may see a COMMENT ON DATABASE for the old name
@@ -60,7 +60,7 @@ CommentObject(CommentStmt *stmt)
                        ereport(WARNING,
                                        (errcode(ERRCODE_UNDEFINED_DATABASE),
                                         errmsg("database \"%s\" does not exist", database)));
-                       return InvalidOid;
+                       return address;
                }
        }
 
@@ -126,7 +126,7 @@ CommentObject(CommentStmt *stmt)
        if (relation != NULL)
                relation_close(relation, NoLock);
 
-       return address.objectId;
+       return address;
 }
 
 /*
index f58b0a9e9d2ec7f80d55ee493e9080d78111ab1a..9cd5ced5c7a4773ad861f1ddc9ed48e00c878505 100644 (file)
@@ -34,7 +34,7 @@
 /*
  * CREATE CONVERSION
  */
-Oid
+ObjectAddress
 CreateConversionCommand(CreateConversionStmt *stmt)
 {
        Oid                     namespaceId;
index c961429a0f5a014cd61e7cd94e217d1d33676e46..54b2f382ea0e03f5c872711643ee4cbb8e1ccca9 100644 (file)
@@ -58,8 +58,8 @@ typedef struct
        BulkInsertState bistate;        /* bulk insert state */
 } DR_intorel;
 
-/* the OID of the created table, for ExecCreateTableAs consumption */
-static Oid     CreateAsRelid = InvalidOid;
+/* the address of the created table, for ExecCreateTableAs consumption */
+static ObjectAddress CreateAsReladdr = {InvalidOid, InvalidOid, 0};
 
 static void intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo);
 static void intorel_receive(TupleTableSlot *slot, DestReceiver *self);
@@ -70,7 +70,7 @@ static void intorel_destroy(DestReceiver *self);
 /*
  * ExecCreateTableAs -- execute a CREATE TABLE AS command
  */
-Oid
+ObjectAddress
 ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
                                  ParamListInfo params, char *completionTag)
 {
@@ -81,7 +81,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
        Oid                     save_userid = InvalidOid;
        int                     save_sec_context = 0;
        int                     save_nestlevel = 0;
-       Oid                     relOid;
+       ObjectAddress address;
        List       *rewritten;
        PlannedStmt *plan;
        QueryDesc  *queryDesc;
@@ -99,7 +99,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
                                        (errcode(ERRCODE_DUPLICATE_TABLE),
                                         errmsg("relation \"%s\" already exists, skipping",
                                                        stmt->into->rel->relname)));
-                       return InvalidOid;
+                       return InvalidObjectAddress;
                }
        }
 
@@ -121,9 +121,9 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
                Assert(!is_matview);    /* excluded by syntax */
                ExecuteQuery(estmt, into, queryString, params, dest, completionTag);
 
-               relOid = CreateAsRelid;
-               CreateAsRelid = InvalidOid;
-               return relOid;
+               address = CreateAsReladdr;
+               CreateAsReladdr = InvalidObjectAddress;
+               return address;
        }
        Assert(query->commandType == CMD_SELECT);
 
@@ -216,10 +216,10 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
                SetUserIdAndSecContext(save_userid, save_sec_context);
        }
 
-       relOid = CreateAsRelid;
-       CreateAsRelid = InvalidOid;
+       address = CreateAsReladdr;
+       CreateAsReladdr = InvalidObjectAddress;
 
-       return relOid;
+       return address;
 }
 
 /*
@@ -288,7 +288,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
        bool            is_matview;
        char            relkind;
        CreateStmt *create;
-       Oid                     intoRelationId;
+       ObjectAddress intoRelationAddr;
        Relation        intoRelationDesc;
        RangeTblEntry *rte;
        Datum           toast_options;
@@ -385,7 +385,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
        /*
         * Actually create the target table
         */
-       intoRelationId = DefineRelation(create, relkind, InvalidOid);
+       intoRelationAddr = DefineRelation(create, relkind, InvalidOid, NULL);
 
        /*
         * If necessary, create a TOAST table for the target table.  Note that
@@ -403,7 +403,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
 
        (void) heap_reloptions(RELKIND_TOASTVALUE, toast_options, true);
 
-       NewRelationCreateToastTable(intoRelationId, toast_options);
+       NewRelationCreateToastTable(intoRelationAddr.objectId, toast_options);
 
        /* Create the "view" part of a materialized view. */
        if (is_matview)
@@ -411,14 +411,14 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
                /* StoreViewQuery scribbles on tree, so make a copy */
                Query      *query = (Query *) copyObject(into->viewQuery);
 
-               StoreViewQuery(intoRelationId, query, false);
+               StoreViewQuery(intoRelationAddr.objectId, query, false);
                CommandCounterIncrement();
        }
 
        /*
         * Finally we can open the target table
         */
-       intoRelationDesc = heap_open(intoRelationId, AccessExclusiveLock);
+       intoRelationDesc = heap_open(intoRelationAddr.objectId, AccessExclusiveLock);
 
        /*
         * Check INSERT permission on the constructed table.
@@ -428,7 +428,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
         */
        rte = makeNode(RangeTblEntry);
        rte->rtekind = RTE_RELATION;
-       rte->relid = intoRelationId;
+       rte->relid = intoRelationAddr.objectId;
        rte->relkind = relkind;
        rte->requiredPerms = ACL_INSERT;
 
@@ -446,7 +446,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
         * be enabled here.  We don't actually support that currently, so throw
         * our own ereport(ERROR) if that happens.
         */
-       if (check_enable_rls(intoRelationId, InvalidOid, false) == RLS_ENABLED)
+       if (check_enable_rls(intoRelationAddr.objectId, InvalidOid, false) == RLS_ENABLED)
                ereport(ERROR,
                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                                 (errmsg("policies not yet implemented for this command"))));
@@ -464,8 +464,8 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
        myState->rel = intoRelationDesc;
        myState->output_cid = GetCurrentCommandId(true);
 
-       /* and remember the new relation's OID for ExecCreateTableAs */
-       CreateAsRelid = RelationGetRelid(myState->rel);
+       /* and remember the new relation's address for ExecCreateTableAs */
+       CreateAsReladdr = intoRelationAddr;
 
        /*
         * We can skip WAL-logging the insertions, unless PITR or streaming
index 5e669619bab591547c162b8fa5add12d279773ea..85791364205a9672965e9145874f6701bc1c3466 100644 (file)
@@ -938,7 +938,7 @@ dropdb(const char *dbname, bool missing_ok)
 /*
  * Rename database
  */
-Oid
+ObjectAddress
 RenameDatabase(const char *oldname, const char *newname)
 {
        Oid                     db_id;
@@ -946,6 +946,7 @@ RenameDatabase(const char *oldname, const char *newname)
        Relation        rel;
        int                     notherbackends;
        int                     npreparedxacts;
+       ObjectAddress address;
 
        /*
         * Look up the target database's OID, and get exclusive lock on it. We
@@ -1013,12 +1014,14 @@ RenameDatabase(const char *oldname, const char *newname)
 
        InvokeObjectPostAlterHook(DatabaseRelationId, db_id, 0);
 
+       ObjectAddressSet(address, DatabaseRelationId, db_id);
+
        /*
         * Close pg_database, but keep lock till commit.
         */
        heap_close(rel, NoLock);
 
-       return db_id;
+       return address;
 }
 
 
@@ -1560,7 +1563,7 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
 /*
  * ALTER DATABASE name OWNER TO newowner
  */
-Oid
+ObjectAddress
 AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
 {
        Oid                     db_id;
@@ -1569,6 +1572,7 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
        ScanKeyData scankey;
        SysScanDesc scan;
        Form_pg_database datForm;
+       ObjectAddress address;
 
        /*
         * Get the old tuple.  We don't need a lock on the database per se,
@@ -1663,12 +1667,14 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
 
        InvokeObjectPostAlterHook(DatabaseRelationId, HeapTupleGetOid(tuple), 0);
 
+       ObjectAddressSet(address, DatabaseRelationId, db_id);
+
        systable_endscan(scan);
 
        /* Close pg_database, but keep lock till commit */
        heap_close(rel, NoLock);
 
-       return db_id;
+       return address;
 }
 
 
index deeb8dcfaf164821eb40a6af77b4a3054f85a457..f573c9ce706e4e47be150ef5b3a1e9707697091c 100644 (file)
@@ -518,12 +518,13 @@ AlterEventTrigger(AlterEventTrigStmt *stmt)
 /*
  * Change event trigger's owner -- by name
  */
-Oid
+ObjectAddress
 AlterEventTriggerOwner(const char *name, Oid newOwnerId)
 {
        Oid                     evtOid;
        HeapTuple       tup;
        Relation        rel;
+       ObjectAddress address;
 
        rel = heap_open(EventTriggerRelationId, RowExclusiveLock);
 
@@ -538,11 +539,13 @@ AlterEventTriggerOwner(const char *name, Oid newOwnerId)
 
        AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
 
+       ObjectAddressSet(address, EventTriggerRelationId, evtOid);
+
        heap_freetuple(tup);
 
        heap_close(rel, RowExclusiveLock);
 
-       return evtOid;
+       return address;
 }
 
 /*
index 3b95552a60f08aa22bfda4538ce20dd935246f9f..aa733575e46796bd60f1df2342a37f21d8bd4681 100644 (file)
@@ -1170,7 +1170,7 @@ find_update_path(List *evi_list,
 /*
  * CREATE EXTENSION
  */
-Oid
+ObjectAddress
 CreateExtension(CreateExtensionStmt *stmt)
 {
        DefElem    *d_schema = NULL;
@@ -1188,6 +1188,7 @@ CreateExtension(CreateExtensionStmt *stmt)
        List       *requiredSchemas;
        Oid                     extensionOid;
        ListCell   *lc;
+       ObjectAddress address;
 
        /* Check extension name validity before any filesystem access */
        check_valid_extension_name(stmt->extname);
@@ -1206,7 +1207,7 @@ CreateExtension(CreateExtensionStmt *stmt)
                                        (errcode(ERRCODE_DUPLICATE_OBJECT),
                                         errmsg("extension \"%s\" already exists, skipping",
                                                        stmt->extname)));
-                       return InvalidOid;
+                       return InvalidObjectAddress;
                }
                else
                        ereport(ERROR,
@@ -1443,12 +1444,13 @@ CreateExtension(CreateExtensionStmt *stmt)
        /*
         * Insert new tuple into pg_extension, and create dependency entries.
         */
-       extensionOid = InsertExtensionTuple(control->name, extowner,
-                                                                               schemaOid, control->relocatable,
-                                                                               versionName,
-                                                                               PointerGetDatum(NULL),
-                                                                               PointerGetDatum(NULL),
-                                                                               requiredExtensions);
+       address = InsertExtensionTuple(control->name, extowner,
+                                                                  schemaOid, control->relocatable,
+                                                                  versionName,
+                                                                  PointerGetDatum(NULL),
+                                                                  PointerGetDatum(NULL),
+                                                                  requiredExtensions);
+       extensionOid = address.objectId;
 
        /*
         * Apply any control-file comment on extension
@@ -1471,7 +1473,7 @@ CreateExtension(CreateExtensionStmt *stmt)
        ApplyExtensionUpdates(extensionOid, pcontrol,
                                                  versionName, updateVersions);
 
-       return extensionOid;
+       return address;
 }
 
 /*
@@ -1487,7 +1489,7 @@ CreateExtension(CreateExtensionStmt *stmt)
  * extConfig and extCondition should be arrays or PointerGetDatum(NULL).
  * We declare them as plain Datum to avoid needing array.h in extension.h.
  */
-Oid
+ObjectAddress
 InsertExtensionTuple(const char *extName, Oid extOwner,
                                         Oid schemaOid, bool relocatable, const char *extVersion,
                                         Datum extConfig, Datum extCondition,
@@ -1564,7 +1566,7 @@ InsertExtensionTuple(const char *extName, Oid extOwner,
        /* Post creation hook for new extension */
        InvokeObjectPostCreateHook(ExtensionRelationId, extensionOid, 0);
 
-       return extensionOid;
+       return myself;
 }
 
 /*
@@ -2399,8 +2401,8 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
 /*
  * Execute ALTER EXTENSION SET SCHEMA
  */
-Oid
-AlterExtensionNamespace(List *names, const char *newschema)
+ObjectAddress
+AlterExtensionNamespace(List *names, const char *newschema, Oid *oldschema)
 {
        char       *extensionName;
        Oid                     extensionOid;
@@ -2416,6 +2418,7 @@ AlterExtensionNamespace(List *names, const char *newschema)
        SysScanDesc depScan;
        HeapTuple       depTup;
        ObjectAddresses *objsMoved;
+       ObjectAddress extAddr;
 
        if (list_length(names) != 1)
                ereport(ERROR,
@@ -2480,7 +2483,7 @@ AlterExtensionNamespace(List *names, const char *newschema)
        if (extForm->extnamespace == nspOid)
        {
                heap_close(extRel, RowExclusiveLock);
-               return InvalidOid;
+               return InvalidObjectAddress;
        }
 
        /* Check extension is supposed to be relocatable */
@@ -2557,6 +2560,10 @@ AlterExtensionNamespace(List *names, const char *newschema)
                                                           get_namespace_name(oldNspOid))));
        }
 
+       /* report old schema, if caller wants it */
+       if (oldschema)
+               *oldschema = oldNspOid;
+
        systable_endscan(depScan);
 
        relation_close(depRel, AccessShareLock);
@@ -2575,13 +2582,15 @@ AlterExtensionNamespace(List *names, const char *newschema)
 
        InvokeObjectPostAlterHook(ExtensionRelationId, extensionOid, 0);
 
-       return extensionOid;
+       ObjectAddressSet(extAddr, ExtensionRelationId, extensionOid);
+
+       return extAddr;
 }
 
 /*
  * Execute ALTER EXTENSION UPDATE
  */
-Oid
+ObjectAddress
 ExecAlterExtensionStmt(AlterExtensionStmt *stmt)
 {
        DefElem    *d_new_version = NULL;
@@ -2597,6 +2606,7 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt)
        Datum           datum;
        bool            isnull;
        ListCell   *lc;
+       ObjectAddress address;
 
        /*
         * We use global variables to track the extension being created, so we can
@@ -2698,7 +2708,7 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt)
                ereport(NOTICE,
                   (errmsg("version \"%s\" of extension \"%s\" is already installed",
                                   versionName, stmt->extname)));
-               return InvalidOid;
+               return InvalidObjectAddress;
        }
 
        /*
@@ -2715,7 +2725,9 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt)
        ApplyExtensionUpdates(extensionOid, control,
                                                  oldVersionName, updateVersions);
 
-       return extensionOid;
+       ObjectAddressSet(address, ExtensionRelationId, extensionOid);
+
+       return address;
 }
 
 /*
@@ -2879,9 +2891,15 @@ ApplyExtensionUpdates(Oid extensionOid,
 
 /*
  * Execute ALTER EXTENSION ADD/DROP
+ *
+ * Return value is the address of the altered extension.
+ *
+ * objAddr is an output argument which, if not NULL, is set to the address of
+ * the added/dropped object.
  */
-Oid
-ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt)
+ObjectAddress
+ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt,
+                                                          ObjectAddress *objAddr)
 {
        ObjectAddress extension;
        ObjectAddress object;
@@ -2906,6 +2924,10 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt)
        object = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,
                                                                &relation, ShareUpdateExclusiveLock, false);
 
+       Assert(object.objectSubId == 0);
+       if (objAddr)
+               *objAddr = object;
+
        /* Permission check: must own target object, too */
        check_object_ownership(GetUserId(), stmt->objtype, object,
                                                   stmt->objname, stmt->objargs, relation);
@@ -2984,5 +3006,5 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt)
        if (relation != NULL)
                relation_close(relation, NoLock);
 
-       return extension.objectId;
+       return extension;
 }
index 537e31c34ee30c831aa2058b27f7b27fee6111fb..bd4839189e6efb2a16ddee0b38c7b7633ae0406e 100644 (file)
@@ -292,12 +292,13 @@ AlterForeignDataWrapperOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerI
  *
  * Note restrictions in the "_internal" function, above.
  */
-Oid
+ObjectAddress
 AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
 {
        Oid                     fdwId;
        HeapTuple       tup;
        Relation        rel;
+       ObjectAddress address;
 
        rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock);
 
@@ -312,11 +313,13 @@ AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
 
        AlterForeignDataWrapperOwner_internal(rel, tup, newOwnerId);
 
+       ObjectAddressSet(address, ForeignDataWrapperRelationId, fdwId);
+
        heap_freetuple(tup);
 
        heap_close(rel, RowExclusiveLock);
 
-       return fdwId;
+       return address;
 }
 
 /*
@@ -427,12 +430,13 @@ AlterForeignServerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
 /*
  * Change foreign server owner -- by name
  */
-Oid
+ObjectAddress
 AlterForeignServerOwner(const char *name, Oid newOwnerId)
 {
        Oid                     servOid;
        HeapTuple       tup;
        Relation        rel;
+       ObjectAddress address;
 
        rel = heap_open(ForeignServerRelationId, RowExclusiveLock);
 
@@ -447,11 +451,13 @@ AlterForeignServerOwner(const char *name, Oid newOwnerId)
 
        AlterForeignServerOwner_internal(rel, tup, newOwnerId);
 
+       ObjectAddressSet(address, ForeignServerRelationId, servOid);
+
        heap_freetuple(tup);
 
        heap_close(rel, RowExclusiveLock);
 
-       return servOid;
+       return address;
 }
 
 /*
@@ -569,7 +575,7 @@ parse_func_options(List *func_options,
 /*
  * Create a foreign-data wrapper
  */
-Oid
+ObjectAddress
 CreateForeignDataWrapper(CreateFdwStmt *stmt)
 {
        Relation        rel;
@@ -676,14 +682,14 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
 
        heap_close(rel, RowExclusiveLock);
 
-       return fdwId;
+       return myself;
 }
 
 
 /*
  * Alter foreign-data wrapper
  */
-Oid
+ObjectAddress
 AlterForeignDataWrapper(AlterFdwStmt *stmt)
 {
        Relation        rel;
@@ -699,6 +705,7 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
        bool            validator_given;
        Oid                     fdwhandler;
        Oid                     fdwvalidator;
+       ObjectAddress myself;
 
        rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock);
 
@@ -801,10 +808,11 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
 
        heap_freetuple(tp);
 
+       ObjectAddressSet(myself, ForeignDataWrapperRelationId, fdwId);
+
        /* Update function dependencies if we changed them */
        if (handler_given || validator_given)
        {
-               ObjectAddress myself;
                ObjectAddress referenced;
 
                /*
@@ -817,9 +825,6 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
                                                                                DEPENDENCY_NORMAL);
 
                /* And build new ones. */
-               myself.classId = ForeignDataWrapperRelationId;
-               myself.objectId = fdwId;
-               myself.objectSubId = 0;
 
                if (OidIsValid(fdwhandler))
                {
@@ -842,7 +847,7 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
 
        heap_close(rel, RowExclusiveLock);
 
-       return fdwId;
+       return myself;
 }
 
 
@@ -873,7 +878,7 @@ RemoveForeignDataWrapperById(Oid fdwId)
 /*
  * Create a foreign server
  */
-Oid
+ObjectAddress
 CreateForeignServer(CreateForeignServerStmt *stmt)
 {
        Relation        rel;
@@ -979,14 +984,14 @@ CreateForeignServer(CreateForeignServerStmt *stmt)
 
        heap_close(rel, RowExclusiveLock);
 
-       return srvId;
+       return myself;
 }
 
 
 /*
  * Alter foreign server
  */
-Oid
+ObjectAddress
 AlterForeignServer(AlterForeignServerStmt *stmt)
 {
        Relation        rel;
@@ -996,6 +1001,7 @@ AlterForeignServer(AlterForeignServerStmt *stmt)
        bool            repl_repl[Natts_pg_foreign_server];
        Oid                     srvId;
        Form_pg_foreign_server srvForm;
+       ObjectAddress address;
 
        rel = heap_open(ForeignServerRelationId, RowExclusiveLock);
 
@@ -1072,11 +1078,13 @@ AlterForeignServer(AlterForeignServerStmt *stmt)
 
        InvokeObjectPostAlterHook(ForeignServerRelationId, srvId, 0);
 
+       ObjectAddressSet(address, ForeignServerRelationId, srvId);
+
        heap_freetuple(tp);
 
        heap_close(rel, RowExclusiveLock);
 
-       return srvId;
+       return address;
 }
 
 
@@ -1134,7 +1142,7 @@ user_mapping_ddl_aclcheck(Oid umuserid, Oid serverid, const char *servername)
 /*
  * Create user mapping
  */
-Oid
+ObjectAddress
 CreateUserMapping(CreateUserMappingStmt *stmt)
 {
        Relation        rel;
@@ -1225,14 +1233,14 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
 
        heap_close(rel, RowExclusiveLock);
 
-       return umId;
+       return myself;
 }
 
 
 /*
  * Alter user mapping
  */
-Oid
+ObjectAddress
 AlterUserMapping(AlterUserMappingStmt *stmt)
 {
        Relation        rel;
@@ -1243,6 +1251,7 @@ AlterUserMapping(AlterUserMappingStmt *stmt)
        Oid                     useId;
        Oid                     umId;
        ForeignServer *srv;
+       ObjectAddress address;
 
        rel = heap_open(UserMappingRelationId, RowExclusiveLock);
 
@@ -1309,11 +1318,13 @@ AlterUserMapping(AlterUserMappingStmt *stmt)
        simple_heap_update(rel, &tp->t_self, tp);
        CatalogUpdateIndexes(rel, tp);
 
+       ObjectAddressSet(address, UserMappingRelationId, umId);
+
        heap_freetuple(tp);
 
        heap_close(rel, RowExclusiveLock);
 
-       return umId;
+       return address;
 }
 
 
index b3a91fc681f37746f15ddb13f9aa6ccb1f5e7bf6..f4725056da0d365307df5644eca8d8797dec5c3d 100644 (file)
@@ -112,6 +112,7 @@ compute_return_type(TypeName *returnType, Oid languageOid,
                Oid                     namespaceId;
                AclResult       aclresult;
                char       *typname;
+               ObjectAddress address;
 
                /*
                 * Only C-coded functions can be I/O functions.  We enforce this
@@ -144,7 +145,8 @@ compute_return_type(TypeName *returnType, Oid languageOid,
                if (aclresult != ACLCHECK_OK)
                        aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
                                                   get_namespace_name(namespaceId));
-               rettype = TypeShellMake(typname, namespaceId, GetUserId());
+               address = TypeShellMake(typname, namespaceId, GetUserId());
+               rettype = address.objectId;
                Assert(OidIsValid(rettype));
        }
 
@@ -810,7 +812,7 @@ interpret_AS_clause(Oid languageOid, const char *languageName,
  * CreateFunction
  *      Execute a CREATE FUNCTION utility statement.
  */
-Oid
+ObjectAddress
 CreateFunction(CreateFunctionStmt *stmt, const char *queryString)
 {
        char       *probin_str;
@@ -1071,7 +1073,7 @@ RemoveFunctionById(Oid funcOid)
  * RENAME and OWNER clauses, which are handled as part of the generic
  * ALTER framework).
  */
-Oid
+ObjectAddress
 AlterFunction(AlterFunctionStmt *stmt)
 {
        HeapTuple       tup;
@@ -1086,6 +1088,7 @@ AlterFunction(AlterFunctionStmt *stmt)
        List       *set_items = NIL;
        DefElem    *cost_item = NULL;
        DefElem    *rows_item = NULL;
+       ObjectAddress address;
 
        rel = heap_open(ProcedureRelationId, RowExclusiveLock);
 
@@ -1201,10 +1204,12 @@ AlterFunction(AlterFunctionStmt *stmt)
 
        InvokeObjectPostAlterHook(ProcedureRelationId, funcOid, 0);
 
+       ObjectAddressSet(address, ProcedureRelationId, funcOid);
+
        heap_close(rel, NoLock);
        heap_freetuple(tup);
 
-       return funcOid;
+       return address;
 }
 
 /*
@@ -1282,7 +1287,7 @@ SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType)
 /*
  * CREATE CAST
  */
-Oid
+ObjectAddress
 CreateCast(CreateCastStmt *stmt)
 {
        Oid                     sourcetypeid;
@@ -1596,7 +1601,7 @@ CreateCast(CreateCastStmt *stmt)
 
        heap_close(relation, RowExclusiveLock);
 
-       return castid;
+       return myself;
 }
 
 /*
index e8596698970003aa5c3edbc1bb2c02426b262719..6563f2bb5bf3aa751d982b9815eb6bc2ebffbdb4 100644 (file)
@@ -291,9 +291,9 @@ CheckIndexCompatible(Oid oldId,
  *             it will be filled later.
  * 'quiet': suppress the NOTICE chatter ordinarily provided for constraints.
  *
- * Returns the OID of the created index.
+ * Returns the object address of the created index.
  */
-Oid
+ObjectAddress
 DefineIndex(Oid relationId,
                        IndexStmt *stmt,
                        Oid indexRelationId,
@@ -323,6 +323,7 @@ DefineIndex(Oid relationId,
        int                     numberOfAttributes;
        TransactionId limitXmin;
        VirtualTransactionId *old_snapshots;
+       ObjectAddress address;
        int                     n_old_snapshots;
        LockRelId       heaprelid;
        LOCKTAG         heaplocktag;
@@ -613,10 +614,12 @@ DefineIndex(Oid relationId,
                                         stmt->concurrent, !check_rights,
                                         stmt->if_not_exists);
 
+       ObjectAddressSet(address, RelationRelationId, indexRelationId);
+
        if (!OidIsValid(indexRelationId))
        {
                heap_close(rel, NoLock);
-               return indexRelationId;
+               return address;
        }
 
        /* Add any requested comment */
@@ -628,7 +631,7 @@ DefineIndex(Oid relationId,
        {
                /* Close the heap and we're done, in the non-concurrent case */
                heap_close(rel, NoLock);
-               return indexRelationId;
+               return address;
        }
 
        /* save lockrelid and locktag for below, then close rel */
@@ -873,7 +876,7 @@ DefineIndex(Oid relationId,
         */
        UnlockRelationIdForSession(&heaprelid, ShareUpdateExclusiveLock);
 
-       return indexRelationId;
+       return address;
 }
 
 
index 92d903232844b6f678a0e7e5a18855e85359360b..eb16bb31ffc04995e8a913a50eac0ed29cadb494 100644 (file)
@@ -134,7 +134,7 @@ SetMatViewPopulatedState(Relation relation, bool newstate)
  * The matview's "populated" state is changed based on whether the contents
  * reflect the result set of the materialized view's query.
  */
-Oid
+ObjectAddress
 ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
                                   ParamListInfo params, char *completionTag)
 {
@@ -153,6 +153,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
        Oid                     save_userid;
        int                     save_sec_context;
        int                     save_nestlevel;
+       ObjectAddress address;
 
        /* Determine strength of lock needed. */
        concurrent = stmt->concurrent;
@@ -311,7 +312,9 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
        /* Restore userid and security context */
        SetUserIdAndSecContext(save_userid, save_sec_context);
 
-       return matviewOid;
+       ObjectAddressSet(address, RelationRelationId, matviewOid);
+
+       return address;
 }
 
 /*
index 16f6f0503c92e10383496eb5b904991922948135..c327cc0473e0dcf453410af54759b245cf6af592 100644 (file)
@@ -246,7 +246,7 @@ get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
  *
  * Caller must have done permissions checks etc. already.
  */
-static Oid
+static ObjectAddress
 CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
 {
        Oid                     opfamilyoid;
@@ -319,14 +319,14 @@ CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
 
        heap_close(rel, RowExclusiveLock);
 
-       return opfamilyoid;
+       return myself;
 }
 
 /*
  * DefineOpClass
  *             Define a new index operator class.
  */
-Oid
+ObjectAddress
 DefineOpClass(CreateOpClassStmt *stmt)
 {
        char       *opcname;            /* name of opclass we're creating */
@@ -445,11 +445,14 @@ DefineOpClass(CreateOpClassStmt *stmt)
                }
                else
                {
+                       ObjectAddress tmpAddr;
+
                        /*
                         * Create it ... again no need for more permissions ...
                         */
-                       opfamilyoid = CreateOpFamily(stmt->amname, opcname,
-                                                                                namespaceoid, amoid);
+                       tmpAddr = CreateOpFamily(stmt->amname, opcname,
+                                                                        namespaceoid, amoid);
+                       opfamilyoid = tmpAddr.objectId;
                }
        }
 
@@ -719,7 +722,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
 
        heap_close(rel, RowExclusiveLock);
 
-       return opclassoid;
+       return myself;
 }
 
 
@@ -727,7 +730,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
  * DefineOpFamily
  *             Define a new index operator family.
  */
-Oid
+ObjectAddress
 DefineOpFamily(CreateOpFamilyStmt *stmt)
 {
        char       *opfname;            /* name of opfamily we're creating */
index 29960191c046809d39a9501e35bafb4aa293ab52..1efaacfd5e2cf2e51e34e6b5f56ec7b697e72049 100644 (file)
@@ -59,7 +59,7 @@
  *
  * 'parameters' is a list of DefElem
  */
-Oid
+ObjectAddress
 DefineOperator(List *names, List *parameters)
 {
        char       *oprName;
index d98da0dd506495708967510fd28237db4ab0b9e3..e86299781f960b93c0ee27e6e4fec2047aa873e6 100644 (file)
@@ -460,7 +460,7 @@ RemovePolicyById(Oid policy_id)
  *
  * stmt - the CreatePolicyStmt that describes the policy to create.
  */
-Oid
+ObjectAddress
 CreatePolicy(CreatePolicyStmt *stmt)
 {
        Relation                pg_policy_rel;
@@ -626,7 +626,7 @@ CreatePolicy(CreatePolicyStmt *stmt)
        relation_close(target_table, NoLock);
        heap_close(pg_policy_rel, RowExclusiveLock);
 
-       return policy_id;
+       return myself;
 }
 
 /*
@@ -635,7 +635,7 @@ CreatePolicy(CreatePolicyStmt *stmt)
  *
  * stmt - the AlterPolicyStmt that describes the policy and how to alter it.
  */
-Oid
+ObjectAddress
 AlterPolicy(AlterPolicyStmt *stmt)
 {
        Relation                pg_policy_rel;
@@ -830,14 +830,14 @@ AlterPolicy(AlterPolicyStmt *stmt)
        relation_close(target_table, NoLock);
        heap_close(pg_policy_rel, RowExclusiveLock);
 
-       return policy_id;
+       return myself;
 }
 
 /*
  * rename_policy -
  *   change the name of a policy on a relation
  */
-Oid
+ObjectAddress
 rename_policy(RenameStmt *stmt)
 {
        Relation                pg_policy_rel;
@@ -847,6 +847,7 @@ rename_policy(RenameStmt *stmt)
        ScanKeyData             skey[2];
        SysScanDesc             sscan;
        HeapTuple               policy_tuple;
+       ObjectAddress   address;
 
        /* Get id of table.  Also handles permissions checks. */
        table_id = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
@@ -925,6 +926,8 @@ rename_policy(RenameStmt *stmt)
        InvokeObjectPostAlterHook(PolicyRelationId,
                                                          HeapTupleGetOid(policy_tuple), 0);
 
+       ObjectAddressSet(address, PolicyRelationId, opoloid);
+
        /*
         * Invalidate relation's relcache entry so that other backends (and
         * this one too!) are sent SI message to make them rebuild relcache
@@ -937,7 +940,7 @@ rename_policy(RenameStmt *stmt)
        heap_close(pg_policy_rel, RowExclusiveLock);
        relation_close(target_table, NoLock);
 
-       return opoloid;
+       return address;
 }
 
 /*
index 07224616145947df7597b16524759cd589d09de8..11e6213e80f4d9a98e5d8a52a17c7de57d0f4ac2 100644 (file)
@@ -51,7 +51,7 @@ typedef struct
        char       *tmpllibrary;        /* path of shared library */
 } PLTemplate;
 
-static Oid create_proc_lang(const char *languageName, bool replace,
+static ObjectAddress create_proc_lang(const char *languageName, bool replace,
                                 Oid languageOwner, Oid handlerOid, Oid inlineOid,
                                 Oid valOid, bool trusted);
 static PLTemplate *find_language_template(const char *languageName);
@@ -60,10 +60,11 @@ static PLTemplate *find_language_template(const char *languageName);
  * CREATE PROCEDURAL LANGUAGE
  * ---------------------------------------------------------------------
  */
-Oid
+ObjectAddress
 CreateProceduralLanguage(CreatePLangStmt *stmt)
 {
        PLTemplate *pltemplate;
+       ObjectAddress tmpAddr;
        Oid                     handlerOid,
                                inlineOid,
                                valOid;
@@ -118,30 +119,31 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
                }
                else
                {
-                       handlerOid = ProcedureCreate(pltemplate->tmplhandler,
-                                                                                PG_CATALOG_NAMESPACE,
-                                                                                false, /* replace */
-                                                                                false, /* returnsSet */
-                                                                                LANGUAGE_HANDLEROID,
-                                                                                BOOTSTRAP_SUPERUSERID,
-                                                                                ClanguageId,
-                                                                                F_FMGR_C_VALIDATOR,
-                                                                                pltemplate->tmplhandler,
-                                                                                pltemplate->tmpllibrary,
-                                                                                false, /* isAgg */
-                                                                                false, /* isWindowFunc */
-                                                                                false, /* security_definer */
-                                                                                false, /* isLeakProof */
-                                                                                false, /* isStrict */
-                                                                                PROVOLATILE_VOLATILE,
-                                                                                buildoidvector(funcargtypes, 0),
-                                                                                PointerGetDatum(NULL),
-                                                                                PointerGetDatum(NULL),
-                                                                                PointerGetDatum(NULL),
-                                                                                NIL,
-                                                                                PointerGetDatum(NULL),
-                                                                                1,
-                                                                                0);
+                       tmpAddr = ProcedureCreate(pltemplate->tmplhandler,
+                                                                         PG_CATALOG_NAMESPACE,
+                                                                         false,        /* replace */
+                                                                         false,        /* returnsSet */
+                                                                         LANGUAGE_HANDLEROID,
+                                                                         BOOTSTRAP_SUPERUSERID,
+                                                                         ClanguageId,
+                                                                         F_FMGR_C_VALIDATOR,
+                                                                         pltemplate->tmplhandler,
+                                                                         pltemplate->tmpllibrary,
+                                                                         false,        /* isAgg */
+                                                                         false,        /* isWindowFunc */
+                                                                         false,        /* security_definer */
+                                                                         false,        /* isLeakProof */
+                                                                         false,        /* isStrict */
+                                                                         PROVOLATILE_VOLATILE,
+                                                                         buildoidvector(funcargtypes, 0),
+                                                                         PointerGetDatum(NULL),
+                                                                         PointerGetDatum(NULL),
+                                                                         PointerGetDatum(NULL),
+                                                                         NIL,
+                                                                         PointerGetDatum(NULL),
+                                                                         1,
+                                                                         0);
+                       handlerOid = tmpAddr.objectId;
                }
 
                /*
@@ -155,30 +157,31 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
                        inlineOid = LookupFuncName(funcname, 1, funcargtypes, true);
                        if (!OidIsValid(inlineOid))
                        {
-                               inlineOid = ProcedureCreate(pltemplate->tmplinline,
-                                                                                       PG_CATALOG_NAMESPACE,
-                                                                                       false,          /* replace */
-                                                                                       false,          /* returnsSet */
-                                                                                       VOIDOID,
-                                                                                       BOOTSTRAP_SUPERUSERID,
-                                                                                       ClanguageId,
-                                                                                       F_FMGR_C_VALIDATOR,
-                                                                                       pltemplate->tmplinline,
-                                                                                       pltemplate->tmpllibrary,
-                                                                                       false,          /* isAgg */
-                                                                                       false,          /* isWindowFunc */
-                                                                                       false,          /* security_definer */
-                                                                                       false,          /* isLeakProof */
-                                                                                       true,           /* isStrict */
-                                                                                       PROVOLATILE_VOLATILE,
-                                                                                       buildoidvector(funcargtypes, 1),
-                                                                                       PointerGetDatum(NULL),
-                                                                                       PointerGetDatum(NULL),
-                                                                                       PointerGetDatum(NULL),
-                                                                                       NIL,
-                                                                                       PointerGetDatum(NULL),
-                                                                                       1,
-                                                                                       0);
+                               tmpAddr = ProcedureCreate(pltemplate->tmplinline,
+                                                                                 PG_CATALOG_NAMESPACE,
+                                                                                 false,                /* replace */
+                                                                                 false,                /* returnsSet */
+                                                                                 VOIDOID,
+                                                                                 BOOTSTRAP_SUPERUSERID,
+                                                                                 ClanguageId,
+                                                                                 F_FMGR_C_VALIDATOR,
+                                                                                 pltemplate->tmplinline,
+                                                                                 pltemplate->tmpllibrary,
+                                                                                 false,                /* isAgg */
+                                                                                 false,                /* isWindowFunc */
+                                                                                 false,                /* security_definer */
+                                                                                 false,                /* isLeakProof */
+                                                                                 true, /* isStrict */
+                                                                                 PROVOLATILE_VOLATILE,
+                                                                                 buildoidvector(funcargtypes, 1),
+                                                                                 PointerGetDatum(NULL),
+                                                                                 PointerGetDatum(NULL),
+                                                                                 PointerGetDatum(NULL),
+                                                                                 NIL,
+                                                                                 PointerGetDatum(NULL),
+                                                                                 1,
+                                                                                 0);
+                               inlineOid = tmpAddr.objectId;
                        }
                }
                else
@@ -195,30 +198,31 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
                        valOid = LookupFuncName(funcname, 1, funcargtypes, true);
                        if (!OidIsValid(valOid))
                        {
-                               valOid = ProcedureCreate(pltemplate->tmplvalidator,
-                                                                                PG_CATALOG_NAMESPACE,
-                                                                                false, /* replace */
-                                                                                false, /* returnsSet */
-                                                                                VOIDOID,
-                                                                                BOOTSTRAP_SUPERUSERID,
-                                                                                ClanguageId,
-                                                                                F_FMGR_C_VALIDATOR,
-                                                                                pltemplate->tmplvalidator,
-                                                                                pltemplate->tmpllibrary,
-                                                                                false, /* isAgg */
-                                                                                false, /* isWindowFunc */
-                                                                                false, /* security_definer */
-                                                                                false, /* isLeakProof */
-                                                                                true,  /* isStrict */
-                                                                                PROVOLATILE_VOLATILE,
-                                                                                buildoidvector(funcargtypes, 1),
-                                                                                PointerGetDatum(NULL),
-                                                                                PointerGetDatum(NULL),
-                                                                                PointerGetDatum(NULL),
-                                                                                NIL,
-                                                                                PointerGetDatum(NULL),
-                                                                                1,
-                                                                                0);
+                               tmpAddr = ProcedureCreate(pltemplate->tmplvalidator,
+                                                                                 PG_CATALOG_NAMESPACE,
+                                                                                 false,                /* replace */
+                                                                                 false,                /* returnsSet */
+                                                                                 VOIDOID,
+                                                                                 BOOTSTRAP_SUPERUSERID,
+                                                                                 ClanguageId,
+                                                                                 F_FMGR_C_VALIDATOR,
+                                                                                 pltemplate->tmplvalidator,
+                                                                                 pltemplate->tmpllibrary,
+                                                                                 false,                /* isAgg */
+                                                                                 false,                /* isWindowFunc */
+                                                                                 false,                /* security_definer */
+                                                                                 false,                /* isLeakProof */
+                                                                                 true, /* isStrict */
+                                                                                 PROVOLATILE_VOLATILE,
+                                                                                 buildoidvector(funcargtypes, 1),
+                                                                                 PointerGetDatum(NULL),
+                                                                                 PointerGetDatum(NULL),
+                                                                                 PointerGetDatum(NULL),
+                                                                                 NIL,
+                                                                                 PointerGetDatum(NULL),
+                                                                                 1,
+                                                                                 0);
+                               valOid = tmpAddr.objectId;
                        }
                }
                else
@@ -309,7 +313,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
 /*
  * Guts of language creation.
  */
-static Oid
+static ObjectAddress
 create_proc_lang(const char *languageName, bool replace,
                                 Oid languageOwner, Oid handlerOid, Oid inlineOid,
                                 Oid valOid, bool trusted)
@@ -433,7 +437,7 @@ create_proc_lang(const char *languageName, bool replace,
 
        heap_close(rel, RowExclusiveLock);
 
-       return myself.objectId;
+       return myself;
 }
 
 /*
index a44dbf453e4c1527366ab5f9163a7c3b833cae71..722142e16eaae72b13fb410ff1b63046b75b5911 100644 (file)
@@ -195,13 +195,14 @@ RemoveSchemaById(Oid schemaOid)
 /*
  * Rename schema
  */
-Oid
+ObjectAddress
 RenameSchema(const char *oldname, const char *newname)
 {
        Oid                     nspOid;
        HeapTuple       tup;
        Relation        rel;
        AclResult       aclresult;
+       ObjectAddress address;
 
        rel = heap_open(NamespaceRelationId, RowExclusiveLock);
 
@@ -243,10 +244,12 @@ RenameSchema(const char *oldname, const char *newname)
 
        InvokeObjectPostAlterHook(NamespaceRelationId, HeapTupleGetOid(tup), 0);
 
+       ObjectAddressSet(address, NamespaceRelationId, nspOid);
+
        heap_close(rel, NoLock);
        heap_freetuple(tup);
 
-       return nspOid;
+       return address;
 }
 
 void
@@ -272,12 +275,13 @@ AlterSchemaOwner_oid(Oid oid, Oid newOwnerId)
 /*
  * Change schema owner
  */
-Oid
+ObjectAddress
 AlterSchemaOwner(const char *name, Oid newOwnerId)
 {
        Oid                     nspOid;
        HeapTuple       tup;
        Relation        rel;
+       ObjectAddress address;
 
        rel = heap_open(NamespaceRelationId, RowExclusiveLock);
 
@@ -291,11 +295,13 @@ AlterSchemaOwner(const char *name, Oid newOwnerId)
 
        AlterSchemaOwner_internal(tup, rel, newOwnerId);
 
+       ObjectAddressSet(address, NamespaceRelationId, nspOid);
+
        ReleaseSysCache(tup);
 
        heap_close(rel, RowExclusiveLock);
 
-       return nspOid;
+       return address;
 }
 
 static void
index 6e15bc8de7ba89bb25917b0492dd431f254c49f1..1ef98ce3532281ed232c48804fee010087e4cf91 100644 (file)
@@ -37,8 +37,10 @@ static List *label_provider_list = NIL;
  * ExecSecLabelStmt --
  *
  * Apply a security label to a database object.
+ *
+ * Returns the ObjectAddress of the object to which the policy was applied.
  */
-Oid
+ObjectAddress
 ExecSecLabelStmt(SecLabelStmt *stmt)
 {
        LabelProvider *provider = NULL;
@@ -133,7 +135,7 @@ ExecSecLabelStmt(SecLabelStmt *stmt)
        if (relation != NULL)
                relation_close(relation, NoLock);
 
-       return address.objectId;
+       return address;
 }
 
 /*
index 0070c4f34ef3207ec7df2aab53619185972ce2cc..6d316d62b6c58ca0c49ad3b6b925e9db23f5432b 100644 (file)
@@ -104,13 +104,14 @@ static void process_owned_by(Relation seqrel, List *owned_by);
  * DefineSequence
  *                             Creates a new sequence relation
  */
-Oid
+ObjectAddress
 DefineSequence(CreateSeqStmt *seq)
 {
        FormData_pg_sequence new;
        List       *owned_by;
        CreateStmt *stmt = makeNode(CreateStmt);
        Oid                     seqoid;
+       ObjectAddress address;
        Relation        rel;
        HeapTuple       tuple;
        TupleDesc       tupDesc;
@@ -139,7 +140,7 @@ DefineSequence(CreateSeqStmt *seq)
                                        (errcode(ERRCODE_DUPLICATE_TABLE),
                                         errmsg("relation \"%s\" already exists, skipping",
                                                        seq->sequence->relname)));
-                       return InvalidOid;
+                       return InvalidObjectAddress;
                }
        }
 
@@ -233,7 +234,8 @@ DefineSequence(CreateSeqStmt *seq)
        stmt->tablespacename = NULL;
        stmt->if_not_exists = seq->if_not_exists;
 
-       seqoid = DefineRelation(stmt, RELKIND_SEQUENCE, seq->ownerId);
+       address = DefineRelation(stmt, RELKIND_SEQUENCE, seq->ownerId, NULL);
+       seqoid = address.objectId;
        Assert(seqoid != InvalidOid);
 
        rel = heap_open(seqoid, AccessExclusiveLock);
@@ -249,7 +251,7 @@ DefineSequence(CreateSeqStmt *seq)
 
        heap_close(rel, NoLock);
 
-       return seqoid;
+       return address;
 }
 
 /*
@@ -401,7 +403,7 @@ fill_seq_with_data(Relation rel, HeapTuple tuple)
  *
  * Modify the definition of a sequence relation
  */
-Oid
+ObjectAddress
 AlterSequence(AlterSeqStmt *stmt)
 {
        Oid                     relid;
@@ -412,6 +414,7 @@ AlterSequence(AlterSeqStmt *stmt)
        Form_pg_sequence seq;
        FormData_pg_sequence new;
        List       *owned_by;
+       ObjectAddress address;
 
        /* Open and lock sequence. */
        relid = RangeVarGetRelid(stmt->sequence, AccessShareLock, stmt->missing_ok);
@@ -420,7 +423,7 @@ AlterSequence(AlterSeqStmt *stmt)
                ereport(NOTICE,
                                (errmsg("relation \"%s\" does not exist, skipping",
                                                stmt->sequence->relname)));
-               return InvalidOid;
+               return InvalidObjectAddress;
        }
 
        init_sequence(relid, &elm, &seqrel);
@@ -484,9 +487,11 @@ AlterSequence(AlterSeqStmt *stmt)
 
        InvokeObjectPostAlterHook(RelationRelationId, relid, 0);
 
+       ObjectAddressSet(address, RelationRelationId, relid);
+
        relation_close(seqrel, NoLock);
 
-       return relid;
+       return address;
 }
 
 
index 745502072e69c036c8ab596f85b0e9d949dc2573..653677892dee133e60cc1ced15cfc6d0be8a5721 100644 (file)
@@ -435,17 +435,19 @@ static void RangeVarCallbackForAlterRelation(const RangeVar *rv, Oid relid,
  * The other arguments are used to extend the behavior for other cases:
  * relkind: relkind to assign to the new relation
  * ownerId: if not InvalidOid, use this as the new relation's owner.
+ * typaddress: if not null, it's set to the pg_type entry's address.
  *
  * Note that permissions checks are done against current user regardless of
  * ownerId.  A nonzero ownerId is used when someone is creating a relation
  * "on behalf of" someone else, so we still want to see that the current user
  * has permissions to do it.
  *
- * If successful, returns the OID of the new relation.
+ * If successful, returns the address of the new relation.
  * ----------------------------------------------------------------
  */
-Oid
-DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
+ObjectAddress
+DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
+                          ObjectAddress *typaddress)
 {
        char            relname[NAMEDATALEN];
        Oid                     namespaceId;
@@ -465,6 +467,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
        AttrNumber      attnum;
        static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
        Oid                     ofTypeId;
+       ObjectAddress address;
 
        /*
         * Truncate relname to appropriate length (probably a waste of time, as
@@ -657,7 +660,8 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
                                                                                  reloptions,
                                                                                  true,
                                                                                  allowSystemTableMods,
-                                                                                 false);
+                                                                                 false,
+                                                                                 typaddress);
 
        /* Store inheritance information for new rel. */
        StoreCatalogInheritance(relationId, inheritOids);
@@ -689,13 +693,15 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
                AddRelationNewConstraints(rel, rawDefaults, stmt->constraints,
                                                                  true, true, false);
 
+       ObjectAddressSet(address, RelationRelationId, relationId);
+
        /*
         * Clean up.  We keep lock on new relation (although it shouldn't be
         * visible to anyone else anyway, until commit).
         */
        relation_close(rel, NoLock);
 
-       return relationId;
+       return address;
 }
 
 /*
@@ -2158,8 +2164,10 @@ renameatt_check(Oid myrelid, Form_pg_class classform, bool recursing)
 
 /*
  *             renameatt_internal              - workhorse for renameatt
+ *
+ * Return value is the attribute number in the 'myrelid' relation.
  */
-static void
+static AttrNumber
 renameatt_internal(Oid myrelid,
                                   const char *oldattname,
                                   const char *newattname,
@@ -2172,7 +2180,7 @@ renameatt_internal(Oid myrelid,
        Relation        attrelation;
        HeapTuple       atttup;
        Form_pg_attribute attform;
-       int                     attnum;
+       AttrNumber      attnum;
 
        /*
         * Grab an exclusive lock on the target table, which we will NOT release
@@ -2300,6 +2308,8 @@ renameatt_internal(Oid myrelid,
        heap_close(attrelation, RowExclusiveLock);
 
        relation_close(targetrelation, NoLock);         /* close rel but keep lock */
+
+       return attnum;
 }
 
 /*
@@ -2322,11 +2332,15 @@ RangeVarCallbackForRenameAttribute(const RangeVar *rv, Oid relid, Oid oldrelid,
 
 /*
  *             renameatt               - changes the name of a attribute in a relation
+ *
+ * The returned ObjectAddress is that of the renamed column.
  */
-Oid
+ObjectAddress
 renameatt(RenameStmt *stmt)
 {
        Oid                     relid;
+       AttrNumber      attnum;
+       ObjectAddress address;
 
        /* lock level taken here should match renameatt_internal */
        relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
@@ -2339,26 +2353,27 @@ renameatt(RenameStmt *stmt)
                ereport(NOTICE,
                                (errmsg("relation \"%s\" does not exist, skipping",
                                                stmt->relation->relname)));
-               return InvalidOid;
+               return InvalidObjectAddress;
        }
 
-       renameatt_internal(relid,
-                                          stmt->subname,       /* old att name */
-                                          stmt->newname,       /* new att name */
-                                          interpretInhOption(stmt->relation->inhOpt),          /* recursive? */
-                                          false,       /* recursing? */
-                                          0,           /* expected inhcount */
-                                          stmt->behavior);
+       attnum =
+               renameatt_internal(relid,
+                                                  stmt->subname,               /* old att name */
+                                                  stmt->newname,               /* new att name */
+                                                  interpretInhOption(stmt->relation->inhOpt),  /* recursive? */
+                                                  false,               /* recursing? */
+                                                  0,   /* expected inhcount */
+                                                  stmt->behavior);
 
-       /* This is an ALTER TABLE command so it's about the relid */
-       return relid;
-}
+       ObjectAddressSubSet(address, RelationRelationId, relid, attnum);
 
+       return address;
+}
 
 /*
  * same logic as renameatt_internal
  */
-static Oid
+static ObjectAddress
 rename_constraint_internal(Oid myrelid,
                                                   Oid mytypid,
                                                   const char *oldconname,
@@ -2371,6 +2386,7 @@ rename_constraint_internal(Oid myrelid,
        Oid                     constraintOid;
        HeapTuple       tuple;
        Form_pg_constraint con;
+       ObjectAddress address;
 
        AssertArg(!myrelid || !mytypid);
 
@@ -2446,15 +2462,17 @@ rename_constraint_internal(Oid myrelid,
        else
                RenameConstraintById(constraintOid, newconname);
 
+       ObjectAddressSet(address, ConstraintRelationId, constraintOid);
+
        ReleaseSysCache(tuple);
 
        if (targetrelation)
                relation_close(targetrelation, NoLock); /* close rel but keep lock */
 
-       return constraintOid;
+       return address;
 }
 
-Oid
+ObjectAddress
 RenameConstraint(RenameStmt *stmt)
 {
        Oid                     relid = InvalidOid;
@@ -2497,10 +2515,11 @@ RenameConstraint(RenameStmt *stmt)
  * Execute ALTER TABLE/INDEX/SEQUENCE/VIEW/MATERIALIZED VIEW/FOREIGN TABLE
  * RENAME
  */
-Oid
+ObjectAddress
 RenameRelation(RenameStmt *stmt)
 {
        Oid                     relid;
+       ObjectAddress address;
 
        /*
         * Grab an exclusive lock on the target table, index, sequence, view,
@@ -2520,13 +2539,15 @@ RenameRelation(RenameStmt *stmt)
                ereport(NOTICE,
                                (errmsg("relation \"%s\" does not exist, skipping",
                                                stmt->relation->relname)));
-               return InvalidOid;
+               return InvalidObjectAddress;
        }
 
        /* Do the work */
        RenameRelationInternal(relid, stmt->newname, false);
 
-       return relid;
+       ObjectAddressSet(address, RelationRelationId, relid);
+
+       return address;
 }
 
 /*
@@ -5702,7 +5723,7 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel,
        bool            check_rights;
        bool            skip_build;
        bool            quiet;
-       Oid                     new_index;
+       ObjectAddress address;
 
        Assert(IsA(stmt, IndexStmt));
        Assert(!stmt->concurrent);
@@ -5717,13 +5738,13 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel,
        /* suppress notices when rebuilding existing index */
        quiet = is_rebuild;
 
-       new_index = DefineIndex(RelationGetRelid(rel),
-                                                       stmt,
-                                                       InvalidOid, /* no predefined OID */
-                                                       true,           /* is_alter_table */
-                                                       check_rights,
-                                                       skip_build,
-                                                       quiet);
+       address = DefineIndex(RelationGetRelid(rel),
+                                                 stmt,
+                                                 InvalidOid,   /* no predefined OID */
+                                                 true, /* is_alter_table */
+                                                 check_rights,
+                                                 skip_build,
+                                                 quiet);
 
        /*
         * If TryReuseIndex() stashed a relfilenode for us, we used it for the new
@@ -5733,7 +5754,7 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel,
         */
        if (OidIsValid(stmt->oldNode))
        {
-               Relation        irel = index_open(new_index, NoLock);
+               Relation        irel = index_open(address.objectId, NoLock);
 
                RelationPreserveStorage(irel->rd_node, true);
                index_close(irel, NoLock);
@@ -10919,8 +10940,8 @@ ATPrepChangePersistence(Relation rel, bool toLogged)
 /*
  * Execute ALTER TABLE SET SCHEMA
  */
-Oid
-AlterTableNamespace(AlterObjectSchemaStmt *stmt)
+ObjectAddress
+AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
 {
        Relation        rel;
        Oid                     relid;
@@ -10928,6 +10949,7 @@ AlterTableNamespace(AlterObjectSchemaStmt *stmt)
        Oid                     nspOid;
        RangeVar   *newrv;
        ObjectAddresses *objsMoved;
+       ObjectAddress myself;
 
        relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
                                                                         stmt->missing_ok, false,
@@ -10939,7 +10961,7 @@ AlterTableNamespace(AlterObjectSchemaStmt *stmt)
                ereport(NOTICE,
                                (errmsg("relation \"%s\" does not exist, skipping",
                                                stmt->relation->relname)));
-               return InvalidOid;
+               return InvalidObjectAddress;
        }
 
        rel = relation_open(relid, NoLock);
@@ -10972,10 +10994,15 @@ AlterTableNamespace(AlterObjectSchemaStmt *stmt)
        AlterTableNamespaceInternal(rel, oldNspOid, nspOid, objsMoved);
        free_object_addresses(objsMoved);
 
+       ObjectAddressSet(myself, RelationRelationId, relid);
+
+       if (oldschema)
+               *oldschema = oldNspOid;
+
        /* close rel, but keep lock until commit */
        relation_close(rel, NoLock);
 
-       return relid;
+       return myself;
 }
 
 /*
index 03cc8fe8d800faff9c2c21365aa3cdcf4f7e1a62..68b6917df5dc513b567535d029e79db6a86bbf97 100644 (file)
@@ -846,7 +846,7 @@ directory_is_empty(const char *path)
 /*
  * Rename a tablespace
  */
-Oid
+ObjectAddress
 RenameTableSpace(const char *oldname, const char *newname)
 {
        Oid                     tspId;
@@ -856,6 +856,7 @@ RenameTableSpace(const char *oldname, const char *newname)
        HeapTuple       tup;
        HeapTuple       newtuple;
        Form_pg_tablespace newform;
+       ObjectAddress address;
 
        /* Search pg_tablespace */
        rel = heap_open(TableSpaceRelationId, RowExclusiveLock);
@@ -912,9 +913,11 @@ RenameTableSpace(const char *oldname, const char *newname)
 
        InvokeObjectPostAlterHook(TableSpaceRelationId, tspId, 0);
 
+       ObjectAddressSet(address, TableSpaceRelationId, tspId);
+
        heap_close(rel, NoLock);
 
-       return tspId;
+       return address;
 }
 
 /*
index a84e86ef805b4af0889609db1b905a13901847fb..e491c5ba772d19c179da0bc8aeb54b13cb0f1ee7 100644 (file)
@@ -100,7 +100,7 @@ static void AfterTriggerEnlargeQueryState(void);
 
 
 /*
- * Create a trigger.  Returns the OID of the created trigger.
+ * Create a trigger.  Returns the address of the created trigger.
  *
  * queryString is the source text of the CREATE TRIGGER command.
  * This must be supplied if a whenClause is specified, else it can be NULL.
@@ -129,10 +129,11 @@ static void AfterTriggerEnlargeQueryState(void);
  * relation, as well as ACL_EXECUTE on the trigger function.  For internal
  * triggers the caller must apply any required permission checks.
  *
- * Note: can return InvalidOid if we decided to not create a trigger at all,
- * but a foreign-key constraint.  This is a kluge for backwards compatibility.
+ * Note: can return InvalidObjectAddress if we decided to not create a trigger
+ * at all, but a foreign-key constraint.  This is a kluge for backwards
+ * compatibility.
  */
-Oid
+ObjectAddress
 CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
                          Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid,
                          bool isInternal)
@@ -459,7 +460,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
 
                ConvertTriggerToFK(stmt, funcoid);
 
-               return InvalidOid;
+               return InvalidObjectAddress;
        }
 
        /*
@@ -799,7 +800,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
        /* Keep lock on target rel until end of xact */
        heap_close(rel, NoLock);
 
-       return trigoid;
+       return myself;
 }
 
 
@@ -1249,7 +1250,7 @@ RangeVarCallbackForRenameTrigger(const RangeVar *rv, Oid relid, Oid oldrelid,
  *             modify tgname in trigger tuple
  *             update row in catalog
  */
-Oid
+ObjectAddress
 renametrig(RenameStmt *stmt)
 {
        Oid                     tgoid;
@@ -1259,6 +1260,7 @@ renametrig(RenameStmt *stmt)
        SysScanDesc tgscan;
        ScanKeyData key[2];
        Oid                     relid;
+       ObjectAddress address;
 
        /*
         * Look up name, check permissions, and acquire lock (which we will NOT
@@ -1351,6 +1353,8 @@ renametrig(RenameStmt *stmt)
                                                stmt->subname, RelationGetRelationName(targetrel))));
        }
 
+       ObjectAddressSet(address, TriggerRelationId, tgoid);
+
        systable_endscan(tgscan);
 
        heap_close(tgrel, RowExclusiveLock);
@@ -1360,7 +1364,7 @@ renametrig(RenameStmt *stmt)
         */
        relation_close(targetrel, NoLock);
 
-       return tgoid;
+       return address;
 }
 
 
index c6f89941e82e81a5bc68129807bfd98dd740d23f..45bafd317079c7bb63fa062f1e18f52dbddb6c53 100644 (file)
@@ -120,8 +120,10 @@ get_ts_parser_func(DefElem *defel, int attnum)
 
 /*
  * make pg_depend entries for a new pg_ts_parser entry
+ *
+ * Return value is the address of said new entry.
  */
-static void
+static ObjectAddress
 makeParserDependencies(HeapTuple tuple)
 {
        Form_pg_ts_parser prs = (Form_pg_ts_parser) GETSTRUCT(tuple);
@@ -162,12 +164,14 @@ makeParserDependencies(HeapTuple tuple)
                referenced.objectId = prs->prsheadline;
                recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
        }
+
+       return myself;
 }
 
 /*
  * CREATE TEXT SEARCH PARSER
  */
-Oid
+ObjectAddress
 DefineTSParser(List *names, List *parameters)
 {
        char       *prsname;
@@ -179,6 +183,7 @@ DefineTSParser(List *names, List *parameters)
        NameData        pname;
        Oid                     prsOid;
        Oid                     namespaceoid;
+       ObjectAddress address;
 
        if (!superuser())
                ereport(ERROR,
@@ -269,7 +274,7 @@ DefineTSParser(List *names, List *parameters)
 
        CatalogUpdateIndexes(prsRel, tup);
 
-       makeParserDependencies(tup);
+       address = makeParserDependencies(tup);
 
        /* Post creation hook for new text search parser */
        InvokeObjectPostCreateHook(TSParserRelationId, prsOid, 0);
@@ -278,7 +283,7 @@ DefineTSParser(List *names, List *parameters)
 
        heap_close(prsRel, RowExclusiveLock);
 
-       return prsOid;
+       return address;
 }
 
 /*
@@ -308,8 +313,10 @@ RemoveTSParserById(Oid prsId)
 
 /*
  * make pg_depend entries for a new pg_ts_dict entry
+ *
+ * Return value is address of the new entry
  */
-static void
+static ObjectAddress
 makeDictionaryDependencies(HeapTuple tuple)
 {
        Form_pg_ts_dict dict = (Form_pg_ts_dict) GETSTRUCT(tuple);
@@ -337,6 +344,8 @@ makeDictionaryDependencies(HeapTuple tuple)
        referenced.objectId = dict->dicttemplate;
        referenced.objectSubId = 0;
        recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
+
+       return myself;
 }
 
 /*
@@ -397,7 +406,7 @@ verify_dictoptions(Oid tmplId, List *dictoptions)
 /*
  * CREATE TEXT SEARCH DICTIONARY
  */
-Oid
+ObjectAddress
 DefineTSDictionary(List *names, List *parameters)
 {
        ListCell   *pl;
@@ -412,6 +421,7 @@ DefineTSDictionary(List *names, List *parameters)
        Oid                     namespaceoid;
        AclResult       aclresult;
        char       *dictname;
+       ObjectAddress address;
 
        /* Convert list of names to a name and namespace */
        namespaceoid = QualifiedNameGetCreationNamespace(names, &dictname);
@@ -475,7 +485,7 @@ DefineTSDictionary(List *names, List *parameters)
 
        CatalogUpdateIndexes(dictRel, tup);
 
-       makeDictionaryDependencies(tup);
+       address = makeDictionaryDependencies(tup);
 
        /* Post creation hook for new text search dictionary */
        InvokeObjectPostCreateHook(TSDictionaryRelationId, dictOid, 0);
@@ -484,7 +494,7 @@ DefineTSDictionary(List *names, List *parameters)
 
        heap_close(dictRel, RowExclusiveLock);
 
-       return dictOid;
+       return address;
 }
 
 /*
@@ -514,7 +524,7 @@ RemoveTSDictionaryById(Oid dictId)
 /*
  * ALTER TEXT SEARCH DICTIONARY
  */
-Oid
+ObjectAddress
 AlterTSDictionary(AlterTSDictionaryStmt *stmt)
 {
        HeapTuple       tup,
@@ -528,6 +538,7 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
        Datum           repl_val[Natts_pg_ts_dict];
        bool            repl_null[Natts_pg_ts_dict];
        bool            repl_repl[Natts_pg_ts_dict];
+       ObjectAddress address;
 
        dictId = get_ts_dict_oid(stmt->dictname, false);
 
@@ -614,6 +625,8 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
 
        InvokeObjectPostAlterHook(TSDictionaryRelationId, dictId, 0);
 
+       ObjectAddressSet(address, TSDictionaryRelationId, dictId);
+
        /*
         * NOTE: because we only support altering the options, not the template,
         * there is no need to update dependencies.  This might have to change if
@@ -625,7 +638,7 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
 
        heap_close(rel, RowExclusiveLock);
 
-       return dictId;
+       return address;
 }
 
 /* ---------------------- TS Template commands -----------------------*/
@@ -678,7 +691,7 @@ get_ts_template_func(DefElem *defel, int attnum)
 /*
  * make pg_depend entries for a new pg_ts_template entry
  */
-static void
+static ObjectAddress
 makeTSTemplateDependencies(HeapTuple tuple)
 {
        Form_pg_ts_template tmpl = (Form_pg_ts_template) GETSTRUCT(tuple);
@@ -710,12 +723,14 @@ makeTSTemplateDependencies(HeapTuple tuple)
                referenced.objectId = tmpl->tmplinit;
                recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
        }
+
+       return myself;
 }
 
 /*
  * CREATE TEXT SEARCH TEMPLATE
  */
-Oid
+ObjectAddress
 DefineTSTemplate(List *names, List *parameters)
 {
        ListCell   *pl;
@@ -728,6 +743,7 @@ DefineTSTemplate(List *names, List *parameters)
        Oid                     tmplOid;
        Oid                     namespaceoid;
        char       *tmplname;
+       ObjectAddress address;
 
        if (!superuser())
                ereport(ERROR,
@@ -793,7 +809,7 @@ DefineTSTemplate(List *names, List *parameters)
 
        CatalogUpdateIndexes(tmplRel, tup);
 
-       makeTSTemplateDependencies(tup);
+       address = makeTSTemplateDependencies(tup);
 
        /* Post creation hook for new text search template */
        InvokeObjectPostCreateHook(TSTemplateRelationId, tmplOid, 0);
@@ -802,7 +818,7 @@ DefineTSTemplate(List *names, List *parameters)
 
        heap_close(tmplRel, RowExclusiveLock);
 
-       return tmplOid;
+       return address;
 }
 
 /*
@@ -860,7 +876,7 @@ GetTSConfigTuple(List *names)
  * Pass opened pg_ts_config_map relation if there might be any config map
  * entries for the config.
  */
-static void
+static ObjectAddress
 makeConfigurationDependencies(HeapTuple tuple, bool removeOld,
                                                          Relation mapRel)
 {
@@ -940,12 +956,14 @@ makeConfigurationDependencies(HeapTuple tuple, bool removeOld,
        record_object_address_dependencies(&myself, addrs, DEPENDENCY_NORMAL);
 
        free_object_addresses(addrs);
+
+       return myself;
 }
 
 /*
  * CREATE TEXT SEARCH CONFIGURATION
  */
-Oid
+ObjectAddress
 DefineTSConfiguration(List *names, List *parameters)
 {
        Relation        cfgRel;
@@ -961,6 +979,7 @@ DefineTSConfiguration(List *names, List *parameters)
        Oid                     prsOid = InvalidOid;
        Oid                     cfgOid;
        ListCell   *pl;
+       ObjectAddress address;
 
        /* Convert list of names to a name and namespace */
        namespaceoid = QualifiedNameGetCreationNamespace(names, &cfgname);
@@ -1088,7 +1107,7 @@ DefineTSConfiguration(List *names, List *parameters)
                systable_endscan(scan);
        }
 
-       makeConfigurationDependencies(tup, false, mapRel);
+       address = makeConfigurationDependencies(tup, false, mapRel);
 
        /* Post creation hook for new text search configuration */
        InvokeObjectPostCreateHook(TSConfigRelationId, cfgOid, 0);
@@ -1099,7 +1118,7 @@ DefineTSConfiguration(List *names, List *parameters)
                heap_close(mapRel, RowExclusiveLock);
        heap_close(cfgRel, RowExclusiveLock);
 
-       return cfgOid;
+       return address;
 }
 
 /*
@@ -1153,12 +1172,13 @@ RemoveTSConfigurationById(Oid cfgId)
 /*
  * ALTER TEXT SEARCH CONFIGURATION - main entry point
  */
-Oid
+ObjectAddress
 AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
 {
        HeapTuple       tup;
        Oid                     cfgId;
        Relation        relMap;
+       ObjectAddress address;
 
        /* Find the configuration */
        tup = GetTSConfigTuple(stmt->cfgname);
@@ -1189,11 +1209,13 @@ AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
        InvokeObjectPostAlterHook(TSConfigMapRelationId,
                                                          HeapTupleGetOid(tup), 0);
 
+       ObjectAddressSet(address, TSConfigMapRelationId, cfgId);
+
        heap_close(relMap, RowExclusiveLock);
 
        ReleaseSysCache(tup);
 
-       return cfgId;
+       return address;
 }
 
 /*
index 60ab3aaf12f43dfefb150f09f6081bd4dd049bd8..67e2ae22c680e3ac85c305a6524dd94e1aa64396 100644 (file)
@@ -101,14 +101,14 @@ static void checkEnumOwner(HeapTuple tup);
 static char *domainAddConstraint(Oid domainOid, Oid domainNamespace,
                                        Oid baseTypeOid,
                                        int typMod, Constraint *constr,
-                                       char *domainName);
+                                       char *domainName, ObjectAddress *constrAddr);
 
 
 /*
  * DefineType
  *             Registers a new base type.
  */
-Oid
+ObjectAddress
 DefineType(List *names, List *parameters)
 {
        char       *typeName;
@@ -160,6 +160,7 @@ DefineType(List *names, List *parameters)
        Oid                     typoid;
        Oid                     resulttype;
        ListCell   *pl;
+       ObjectAddress address;
 
        /*
         * As of Postgres 8.4, we require superuser privilege to create a base
@@ -213,7 +214,7 @@ DefineType(List *names, List *parameters)
         */
        if (!OidIsValid(typoid))
        {
-               typoid = TypeShellMake(typeName, typeNamespace, GetUserId());
+               address = TypeShellMake(typeName, typeNamespace, GetUserId());
                /* Make new shell type visible for modification below */
                CommandCounterIncrement();
 
@@ -222,7 +223,7 @@ DefineType(List *names, List *parameters)
                 * creating the shell type was all we're supposed to do.
                 */
                if (parameters == NIL)
-                       return InvalidOid;
+                       return address;
        }
        else
        {
@@ -595,7 +596,7 @@ DefineType(List *names, List *parameters)
         * types) in ArrayType and in composite types in DatumTupleFields.  This
         * oid must be preserved by binary upgrades.
         */
-       typoid =
+       address =
                TypeCreate(InvalidOid,  /* no predetermined type OID */
                                   typeName,    /* type name */
                                   typeNamespace,               /* namespace */
@@ -670,7 +671,7 @@ DefineType(List *names, List *parameters)
 
        pfree(array_type);
 
-       return typoid;
+       return address;
 }
 
 /*
@@ -716,7 +717,7 @@ RemoveTypeById(Oid typeOid)
  * DefineDomain
  *             Registers a new domain.
  */
-Oid
+ObjectAddress
 DefineDomain(CreateDomainStmt *stmt)
 {
        char       *domainName;
@@ -746,12 +747,12 @@ DefineDomain(CreateDomainStmt *stmt)
        List       *schema = stmt->constraints;
        ListCell   *listptr;
        Oid                     basetypeoid;
-       Oid                     domainoid;
        Oid                     old_type_oid;
        Oid                     domaincoll;
        Form_pg_type baseType;
        int32           basetypeMod;
        Oid                     baseColl;
+       ObjectAddress address;
 
        /* Convert list of names to a name and namespace */
        domainNamespace = QualifiedNameGetCreationNamespace(stmt->domainname,
@@ -1021,7 +1022,7 @@ DefineDomain(CreateDomainStmt *stmt)
        /*
         * Have TypeCreate do all the real work.
         */
-       domainoid =
+       address =
                TypeCreate(InvalidOid,  /* no predetermined type OID */
                                   domainName,  /* type name */
                                   domainNamespace,             /* namespace */
@@ -1066,9 +1067,9 @@ DefineDomain(CreateDomainStmt *stmt)
                switch (constr->contype)
                {
                        case CONSTR_CHECK:
-                               domainAddConstraint(domainoid, domainNamespace,
+                               domainAddConstraint(address.objectId, domainNamespace,
                                                                        basetypeoid, basetypeMod,
-                                                                       constr, domainName);
+                                                                       constr, domainName, NULL);
                                break;
 
                                /* Other constraint types were fully processed above */
@@ -1086,7 +1087,7 @@ DefineDomain(CreateDomainStmt *stmt)
         */
        ReleaseSysCache(typeTup);
 
-       return domainoid;
+       return address;
 }
 
 
@@ -1094,16 +1095,16 @@ DefineDomain(CreateDomainStmt *stmt)
  * DefineEnum
  *             Registers a new enum.
  */
-Oid
+ObjectAddress
 DefineEnum(CreateEnumStmt *stmt)
 {
        char       *enumName;
        char       *enumArrayName;
        Oid                     enumNamespace;
-       Oid                     enumTypeOid;
        AclResult       aclresult;
        Oid                     old_type_oid;
        Oid                     enumArrayOid;
+       ObjectAddress enumTypeAddr;
 
        /* Convert list of names to a name and namespace */
        enumNamespace = QualifiedNameGetCreationNamespace(stmt->typeName,
@@ -1133,7 +1134,7 @@ DefineEnum(CreateEnumStmt *stmt)
        enumArrayOid = AssignTypeArrayOid();
 
        /* Create the pg_type entry */
-       enumTypeOid =
+       enumTypeAddr =
                TypeCreate(InvalidOid,  /* no predetermined type OID */
                                   enumName,    /* type name */
                                   enumNamespace,               /* namespace */
@@ -1167,7 +1168,7 @@ DefineEnum(CreateEnumStmt *stmt)
                                   InvalidOid); /* type's collation */
 
        /* Enter the enum's values into pg_enum */
-       EnumValuesCreate(enumTypeOid, stmt->vals);
+       EnumValuesCreate(enumTypeAddr.objectId, stmt->vals);
 
        /*
         * Create the array type that goes with it.
@@ -1192,7 +1193,7 @@ DefineEnum(CreateEnumStmt *stmt)
                           InvalidOid,          /* typmodin procedure - none */
                           InvalidOid,          /* typmodout procedure - none */
                           F_ARRAY_TYPANALYZE,          /* analyze procedure */
-                          enumTypeOid,         /* element type ID */
+                          enumTypeAddr.objectId,       /* element type ID */
                           true,                        /* yes this is an array type */
                           InvalidOid,          /* no further array type */
                           InvalidOid,          /* base type ID */
@@ -1208,19 +1209,20 @@ DefineEnum(CreateEnumStmt *stmt)
 
        pfree(enumArrayName);
 
-       return enumTypeOid;
+       return enumTypeAddr;
 }
 
 /*
  * AlterEnum
  *             Adds a new label to an existing enum.
  */
-Oid
+ObjectAddress
 AlterEnum(AlterEnumStmt *stmt, bool isTopLevel)
 {
        Oid                     enum_type_oid;
        TypeName   *typename;
        HeapTuple       tup;
+       ObjectAddress address;
 
        /* Make a TypeName so we can use standard type lookup machinery */
        typename = makeTypeNameFromNameList(stmt->typeName);
@@ -1259,9 +1261,11 @@ AlterEnum(AlterEnumStmt *stmt, bool isTopLevel)
 
        InvokeObjectPostAlterHook(TypeRelationId, enum_type_oid, 0);
 
+       ObjectAddressSet(address, TypeRelationId, enum_type_oid);
+
        ReleaseSysCache(tup);
 
-       return enum_type_oid;
+       return address;
 }
 
 
@@ -1293,7 +1297,7 @@ checkEnumOwner(HeapTuple tup)
  * DefineRange
  *             Registers a new range type.
  */
-Oid
+ObjectAddress
 DefineRange(CreateRangeStmt *stmt)
 {
        char       *typeName;
@@ -1316,6 +1320,7 @@ DefineRange(CreateRangeStmt *stmt)
        char            alignment;
        AclResult       aclresult;
        ListCell   *lc;
+       ObjectAddress address;
 
        /* Convert list of names to a name and namespace */
        typeNamespace = QualifiedNameGetCreationNamespace(stmt->typeName,
@@ -1354,7 +1359,8 @@ DefineRange(CreateRangeStmt *stmt)
         */
        if (!OidIsValid(typoid))
        {
-               typoid = TypeShellMake(typeName, typeNamespace, GetUserId());
+               address = TypeShellMake(typeName, typeNamespace, GetUserId());
+               typoid = address.objectId;
                /* Make new shell type visible for modification below */
                CommandCounterIncrement();
        }
@@ -1467,7 +1473,7 @@ DefineRange(CreateRangeStmt *stmt)
        rangeArrayOid = AssignTypeArrayOid();
 
        /* Create the pg_type entry */
-       typoid =
+       address =
                TypeCreate(InvalidOid,  /* no predetermined type OID */
                                   typeName,    /* type name */
                                   typeNamespace,               /* namespace */
@@ -1499,6 +1505,7 @@ DefineRange(CreateRangeStmt *stmt)
                                   0,                   /* Array dimensions of typbasetype */
                                   false,               /* Type NOT NULL */
                                   InvalidOid); /* type's collation (ranges never have one) */
+       typoid = address.objectId;
 
        /* Create the entry in pg_range */
        RangeCreate(typoid, rangeSubtype, rangeCollation, rangeSubOpclass,
@@ -1546,7 +1553,7 @@ DefineRange(CreateRangeStmt *stmt)
        /* And create the constructor functions for this range type */
        makeRangeConstructors(typeName, typeNamespace, typoid, rangeSubtype);
 
-       return typoid;
+       return address;
 }
 
 /*
@@ -1582,45 +1589,40 @@ makeRangeConstructors(const char *name, Oid namespace,
        for (i = 0; i < lengthof(prosrc); i++)
        {
                oidvector  *constructorArgTypesVector;
-               Oid                     procOid;
 
                constructorArgTypesVector = buildoidvector(constructorArgTypes,
                                                                                                   pronargs[i]);
 
-               procOid = ProcedureCreate(name, /* name: same as range type */
-                                                                 namespace,    /* namespace */
-                                                                 false,                /* replace */
-                                                                 false,                /* returns set */
-                                                                 rangeOid,             /* return type */
-                                                                 BOOTSTRAP_SUPERUSERID,                /* proowner */
-                                                                 INTERNALlanguageId,   /* language */
-                                                                 F_FMGR_INTERNAL_VALIDATOR,    /* language validator */
-                                                                 prosrc[i],    /* prosrc */
-                                                                 NULL, /* probin */
-                                                                 false,                /* isAgg */
-                                                                 false,                /* isWindowFunc */
-                                                                 false,                /* security_definer */
-                                                                 false,                /* leakproof */
-                                                                 false,                /* isStrict */
-                                                                 PROVOLATILE_IMMUTABLE,                /* volatility */
-                                                                 constructorArgTypesVector,    /* parameterTypes */
-                                                                 PointerGetDatum(NULL),                /* allParameterTypes */
-                                                                 PointerGetDatum(NULL),                /* parameterModes */
-                                                                 PointerGetDatum(NULL),                /* parameterNames */
-                                                                 NIL,  /* parameterDefaults */
-                                                                 PointerGetDatum(NULL),                /* proconfig */
-                                                                 1.0,  /* procost */
-                                                                 0.0); /* prorows */
+               myself = ProcedureCreate(name,  /* name: same as range type */
+                                                                namespace,             /* namespace */
+                                                                false, /* replace */
+                                                                false, /* returns set */
+                                                                rangeOid,              /* return type */
+                                                                BOOTSTRAP_SUPERUSERID, /* proowner */
+                                                                INTERNALlanguageId,    /* language */
+                                                                F_FMGR_INTERNAL_VALIDATOR,             /* language validator */
+                                                                prosrc[i],             /* prosrc */
+                                                                NULL,  /* probin */
+                                                                false, /* isAgg */
+                                                                false, /* isWindowFunc */
+                                                                false, /* security_definer */
+                                                                false, /* leakproof */
+                                                                false, /* isStrict */
+                                                                PROVOLATILE_IMMUTABLE, /* volatility */
+                                                                constructorArgTypesVector,             /* parameterTypes */
+                                                                PointerGetDatum(NULL), /* allParameterTypes */
+                                                                PointerGetDatum(NULL), /* parameterModes */
+                                                                PointerGetDatum(NULL), /* parameterNames */
+                                                                NIL,   /* parameterDefaults */
+                                                                PointerGetDatum(NULL), /* proconfig */
+                                                                1.0,   /* procost */
+                                                                0.0);  /* prorows */
 
                /*
                 * Make the constructors internally-dependent on the range type so
                 * that they go away silently when the type is dropped.  Note that
                 * pg_dump depends on this choice to avoid dumping the constructors.
                 */
-               myself.classId = ProcedureRelationId;
-               myself.objectId = procOid;
-               myself.objectSubId = 0;
-
                recordDependencyOn(&myself, &referenced, DEPENDENCY_INTERNAL);
        }
 }
@@ -2059,17 +2061,16 @@ AssignTypeArrayOid(void)
  * If the relation already exists, then 'DefineRelation' will abort
  * the xact...
  *
- * DefineCompositeType returns relid for use when creating
- * an implicit composite type during function creation
+ * Return type is the new type's object address.
  *-------------------------------------------------------------------
  */
-Oid
+ObjectAddress
 DefineCompositeType(RangeVar *typevar, List *coldeflist)
 {
        CreateStmt *createStmt = makeNode(CreateStmt);
        Oid                     old_type_oid;
        Oid                     typeNamespace;
-       Oid                     relid;
+       ObjectAddress address;
 
        /*
         * now set the parameters for keys/inheritance etc. All of these are
@@ -2108,17 +2109,19 @@ DefineCompositeType(RangeVar *typevar, List *coldeflist)
        /*
         * Finally create the relation.  This also creates the type.
         */
-       relid = DefineRelation(createStmt, RELKIND_COMPOSITE_TYPE, InvalidOid);
-       Assert(relid != InvalidOid);
-       return relid;
+       DefineRelation(createStmt, RELKIND_COMPOSITE_TYPE, InvalidOid, &address);
+
+       return address;
 }
 
 /*
  * AlterDomainDefault
  *
  * Routine implementing ALTER DOMAIN SET/DROP DEFAULT statements.
+ *
+ * Returns ObjectAddress of the modified domain.
  */
-Oid
+ObjectAddress
 AlterDomainDefault(List *names, Node *defaultRaw)
 {
        TypeName   *typename;
@@ -2133,6 +2136,7 @@ AlterDomainDefault(List *names, Node *defaultRaw)
        bool            new_record_repl[Natts_pg_type];
        HeapTuple       newtuple;
        Form_pg_type typTup;
+       ObjectAddress address;
 
        /* Make a TypeName so we can use standard type lookup machinery */
        typename = makeTypeNameFromNameList(names);
@@ -2242,19 +2246,23 @@ AlterDomainDefault(List *names, Node *defaultRaw)
 
        InvokeObjectPostAlterHook(TypeRelationId, domainoid, 0);
 
+       ObjectAddressSet(address, TypeRelationId, domainoid);
+
        /* Clean up */
        heap_close(rel, NoLock);
        heap_freetuple(newtuple);
 
-       return domainoid;
+       return address;
 }
 
 /*
  * AlterDomainNotNull
  *
  * Routine implementing ALTER DOMAIN SET/DROP NOT NULL statements.
+ *
+ * Returns ObjectAddress of the modified domain.
  */
-Oid
+ObjectAddress
 AlterDomainNotNull(List *names, bool notNull)
 {
        TypeName   *typename;
@@ -2262,6 +2270,7 @@ AlterDomainNotNull(List *names, bool notNull)
        Relation        typrel;
        HeapTuple       tup;
        Form_pg_type typTup;
+       ObjectAddress address = InvalidObjectAddress;
 
        /* Make a TypeName so we can use standard type lookup machinery */
        typename = makeTypeNameFromNameList(names);
@@ -2282,7 +2291,7 @@ AlterDomainNotNull(List *names, bool notNull)
        if (typTup->typnotnull == notNull)
        {
                heap_close(typrel, RowExclusiveLock);
-               return InvalidOid;
+               return address;
        }
 
        /* Adding a NOT NULL constraint requires checking existing columns */
@@ -2356,11 +2365,13 @@ AlterDomainNotNull(List *names, bool notNull)
 
        InvokeObjectPostAlterHook(TypeRelationId, domainoid, 0);
 
+       ObjectAddressSet(address, TypeRelationId, domainoid);
+
        /* Clean up */
        heap_freetuple(tup);
        heap_close(typrel, RowExclusiveLock);
 
-       return domainoid;
+       return address;
 }
 
 /*
@@ -2368,7 +2379,7 @@ AlterDomainNotNull(List *names, bool notNull)
  *
  * Implements the ALTER DOMAIN DROP CONSTRAINT statement
  */
-Oid
+ObjectAddress
 AlterDomainDropConstraint(List *names, const char *constrName,
                                                  DropBehavior behavior, bool missing_ok)
 {
@@ -2381,6 +2392,7 @@ AlterDomainDropConstraint(List *names, const char *constrName,
        ScanKeyData key[1];
        HeapTuple       contup;
        bool            found = false;
+       ObjectAddress address = InvalidObjectAddress;
 
        /* Make a TypeName so we can use standard type lookup machinery */
        typename = makeTypeNameFromNameList(names);
@@ -2427,6 +2439,9 @@ AlterDomainDropConstraint(List *names, const char *constrName,
                        found = true;
                }
        }
+
+       ObjectAddressSet(address, TypeRelationId, domainoid);
+
        /* Clean up after the scan */
        systable_endscan(conscan);
        heap_close(conrel, RowExclusiveLock);
@@ -2446,7 +2461,7 @@ AlterDomainDropConstraint(List *names, const char *constrName,
                                                        constrName, TypeNameToString(typename))));
        }
 
-       return domainoid;
+       return address;
 }
 
 /*
@@ -2454,8 +2469,9 @@ AlterDomainDropConstraint(List *names, const char *constrName,
  *
  * Implements the ALTER DOMAIN .. ADD CONSTRAINT statement.
  */
-Oid
-AlterDomainAddConstraint(List *names, Node *newConstraint)
+ObjectAddress
+AlterDomainAddConstraint(List *names, Node *newConstraint,
+                                                ObjectAddress *constrAddr)
 {
        TypeName   *typename;
        Oid                     domainoid;
@@ -2464,6 +2480,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
        Form_pg_type typTup;
        Constraint *constr;
        char       *ccbin;
+       ObjectAddress address;
 
        /* Make a TypeName so we can use standard type lookup machinery */
        typename = makeTypeNameFromNameList(names);
@@ -2539,7 +2556,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
 
        ccbin = domainAddConstraint(domainoid, typTup->typnamespace,
                                                                typTup->typbasetype, typTup->typtypmod,
-                                                               constr, NameStr(typTup->typname));
+                                                               constr, NameStr(typTup->typname), constrAddr);
 
        /*
         * If requested to validate the constraint, test all values stored in the
@@ -2548,10 +2565,12 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
        if (!constr->skip_validation)
                validateDomainConstraint(domainoid, ccbin);
 
+       ObjectAddressSet(address, TypeRelationId, domainoid);
+
        /* Clean up */
        heap_close(typrel, RowExclusiveLock);
 
-       return domainoid;
+       return address;
 }
 
 /*
@@ -2559,7 +2578,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
  *
  * Implements the ALTER DOMAIN .. VALIDATE CONSTRAINT statement.
  */
-Oid
+ObjectAddress
 AlterDomainValidateConstraint(List *names, char *constrName)
 {
        TypeName   *typename;
@@ -2577,6 +2596,7 @@ AlterDomainValidateConstraint(List *names, char *constrName)
        HeapTuple       tuple;
        HeapTuple       copyTuple;
        ScanKeyData key;
+       ObjectAddress address;
 
        /* Make a TypeName so we can use standard type lookup machinery */
        typename = makeTypeNameFromNameList(names);
@@ -2647,6 +2667,8 @@ AlterDomainValidateConstraint(List *names, char *constrName)
        InvokeObjectPostAlterHook(ConstraintRelationId,
                                                          HeapTupleGetOid(copyTuple), 0);
 
+       ObjectAddressSet(address, TypeRelationId, domainoid);
+
        heap_freetuple(copyTuple);
 
        systable_endscan(scan);
@@ -2656,7 +2678,7 @@ AlterDomainValidateConstraint(List *names, char *constrName)
 
        ReleaseSysCache(tup);
 
-       return domainoid;
+       return address;
 }
 
 static void
@@ -2953,13 +2975,14 @@ checkDomainOwner(HeapTuple tup)
 static char *
 domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
                                        int typMod, Constraint *constr,
-                                       char *domainName)
+                                       char *domainName, ObjectAddress *constrAddr)
 {
        Node       *expr;
        char       *ccsrc;
        char       *ccbin;
        ParseState *pstate;
        CoerceToDomainValue *domVal;
+       Oid                     ccoid;
 
        /*
         * Assign or validate constraint name
@@ -3038,34 +3061,37 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
        /*
         * Store the constraint in pg_constraint
         */
-       CreateConstraintEntry(constr->conname,          /* Constraint Name */
-                                                 domainNamespace,              /* namespace */
-                                                 CONSTRAINT_CHECK,             /* Constraint Type */
-                                                 false,        /* Is Deferrable */
-                                                 false,        /* Is Deferred */
-                                                 !constr->skip_validation,             /* Is Validated */
-                                                 InvalidOid,   /* not a relation constraint */
-                                                 NULL,
-                                                 0,
-                                                 domainOid,    /* domain constraint */
-                                                 InvalidOid,   /* no associated index */
-                                                 InvalidOid,   /* Foreign key fields */
-                                                 NULL,
-                                                 NULL,
-                                                 NULL,
-                                                 NULL,
-                                                 0,
-                                                 ' ',
-                                                 ' ',
-                                                 ' ',
-                                                 NULL, /* not an exclusion constraint */
-                                                 expr, /* Tree form of check constraint */
-                                                 ccbin,        /* Binary form of check constraint */
-                                                 ccsrc,        /* Source form of check constraint */
-                                                 true, /* is local */
-                                                 0,    /* inhcount */
-                                                 false,        /* connoinherit */
-                                                 false);               /* is_internal */
+       ccoid =
+               CreateConstraintEntry(constr->conname,  /* Constraint Name */
+                                                         domainNamespace,      /* namespace */
+                                                         CONSTRAINT_CHECK, /* Constraint Type */
+                                                         false,        /* Is Deferrable */
+                                                         false,        /* Is Deferred */
+                                                         !constr->skip_validation, /* Is Validated */
+                                                         InvalidOid,           /* not a relation constraint */
+                                                         NULL,
+                                                         0,
+                                                         domainOid,            /* domain constraint */
+                                                         InvalidOid,           /* no associated index */
+                                                         InvalidOid,           /* Foreign key fields */
+                                                         NULL,
+                                                         NULL,
+                                                         NULL,
+                                                         NULL,
+                                                         0,
+                                                         ' ',
+                                                         ' ',
+                                                         ' ',
+                                                         NULL,         /* not an exclusion constraint */
+                                                         expr,         /* Tree form of check constraint */
+                                                         ccbin,        /* Binary form of check constraint */
+                                                         ccsrc,        /* Source form of check constraint */
+                                                         true,         /* is local */
+                                                         0,    /* inhcount */
+                                                         false,        /* connoinherit */
+                                                         false);       /* is_internal */
+       if (constrAddr)
+               ObjectAddressSet(*constrAddr, ConstraintRelationId, ccoid);
 
        /*
         * Return the compiled constraint expression so the calling routine can
@@ -3078,7 +3104,7 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
 /*
  * Execute ALTER TYPE RENAME
  */
-Oid
+ObjectAddress
 RenameType(RenameStmt *stmt)
 {
        List       *names = stmt->object;
@@ -3088,6 +3114,7 @@ RenameType(RenameStmt *stmt)
        Relation        rel;
        HeapTuple       tup;
        Form_pg_type typTup;
+       ObjectAddress address;
 
        /* Make a TypeName so we can use standard type lookup machinery */
        typename = makeTypeNameFromNameList(names);
@@ -3145,16 +3172,17 @@ RenameType(RenameStmt *stmt)
                RenameTypeInternal(typeOid, newTypeName,
                                                   typTup->typnamespace);
 
+       ObjectAddressSet(address, TypeRelationId, typeOid);
        /* Clean up */
        heap_close(rel, RowExclusiveLock);
 
-       return typeOid;
+       return address;
 }
 
 /*
  * Change the owner of a type.
  */
-Oid
+ObjectAddress
 AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
 {
        TypeName   *typename;
@@ -3164,6 +3192,7 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
        HeapTuple       newtup;
        Form_pg_type typTup;
        AclResult       aclresult;
+       ObjectAddress address;
 
        rel = heap_open(TypeRelationId, RowExclusiveLock);
 
@@ -3293,10 +3322,12 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
                }
        }
 
+       ObjectAddressSet(address, TypeRelationId, typeOid);
+
        /* Clean up */
        heap_close(rel, RowExclusiveLock);
 
-       return typeOid;
+       return address;
 }
 
 /*
@@ -3376,13 +3407,16 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
 /*
  * Execute ALTER TYPE SET SCHEMA
  */
-Oid
-AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype)
+ObjectAddress
+AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype,
+                                  Oid *oldschema)
 {
        TypeName   *typename;
        Oid                     typeOid;
        Oid                     nspOid;
+       Oid                     oldNspOid;
        ObjectAddresses *objsMoved;
+       ObjectAddress myself;
 
        /* Make a TypeName so we can use standard type lookup machinery */
        typename = makeTypeNameFromNameList(names);
@@ -3399,10 +3433,15 @@ AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype)
        nspOid = LookupCreationNamespace(newschema);
 
        objsMoved = new_object_addresses();
-       AlterTypeNamespace_oid(typeOid, nspOid, objsMoved);
+       oldNspOid = AlterTypeNamespace_oid(typeOid, nspOid, objsMoved);
        free_object_addresses(objsMoved);
 
-       return typeOid;
+       if (oldschema)
+               *oldschema = oldNspOid;
+
+       ObjectAddressSet(myself, TypeRelationId, typeOid);
+
+       return myself;
 }
 
 Oid
index 2210eedb99a44751269ef3761f0abbcc48d98a9a..0d30838aeedde4985fedc737e44243461af219ee 100644 (file)
@@ -1114,7 +1114,7 @@ DropRole(DropRoleStmt *stmt)
 /*
  * Rename role
  */
-Oid
+ObjectAddress
 RenameRole(const char *oldname, const char *newname)
 {
        HeapTuple       oldtuple,
@@ -1128,6 +1128,7 @@ RenameRole(const char *oldname, const char *newname)
        bool            repl_repl[Natts_pg_authid];
        int                     i;
        Oid                     roleid;
+       ObjectAddress address;
 
        rel = heap_open(AuthIdRelationId, RowExclusiveLock);
        dsc = RelationGetDescr(rel);
@@ -1216,6 +1217,8 @@ RenameRole(const char *oldname, const char *newname)
 
        InvokeObjectPostAlterHook(AuthIdRelationId, roleid, 0);
 
+       ObjectAddressSet(address, AuthIdRelationId, roleid);
+
        ReleaseSysCache(oldtuple);
 
        /*
@@ -1223,7 +1226,7 @@ RenameRole(const char *oldname, const char *newname)
         */
        heap_close(rel, NoLock);
 
-       return roleid;
+       return address;
 }
 
 /*
index 7358723bded2a381baa090e12cfe611250a1969d..6f2a749756c72836884c36af95332483fe0dc998 100644 (file)
@@ -65,7 +65,7 @@ validateWithCheckOption(char *value)
  * work harder.
  *---------------------------------------------------------------------
  */
-static Oid
+static ObjectAddress
 DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
                                          List *options)
 {
@@ -143,6 +143,7 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
                TupleDesc       descriptor;
                List       *atcmds = NIL;
                AlterTableCmd *atcmd;
+               ObjectAddress address;
 
                /* Relation is already locked, but we must build a relcache entry. */
                rel = relation_open(viewOid, NoLock);
@@ -208,16 +209,18 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
                /* OK, let's do it. */
                AlterTableInternal(viewOid, atcmds, true);
 
+               ObjectAddressSet(address, RelationRelationId, viewOid);
+
                /*
                 * Seems okay, so return the OID of the pre-existing view.
                 */
                relation_close(rel, NoLock);    /* keep the lock! */
 
-               return viewOid;
+               return address;
        }
        else
        {
-               Oid                     relid;
+               ObjectAddress address;
 
                /*
                 * now set the parameters for keys/inheritance etc. All of these are
@@ -237,9 +240,9 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
                 * existing view, so we don't need more code to complain if "replace"
                 * is false).
                 */
-               relid = DefineRelation(createStmt, RELKIND_VIEW, InvalidOid);
-               Assert(relid != InvalidOid);
-               return relid;
+               address = DefineRelation(createStmt, RELKIND_VIEW, InvalidOid, NULL);
+               Assert(address.objectId != InvalidOid);
+               return address;
        }
 }
 
@@ -388,14 +391,14 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
  * DefineView
  *             Execute a CREATE VIEW command.
  */
-Oid
+ObjectAddress
 DefineView(ViewStmt *stmt, const char *queryString)
 {
        Query      *viewParse;
-       Oid                     viewOid;
        RangeVar   *view;
        ListCell   *cell;
        bool            check_option;
+       ObjectAddress address;
 
        /*
         * Run parse analysis to convert the raw parse tree to a Query.  Note this
@@ -533,7 +536,7 @@ DefineView(ViewStmt *stmt, const char *queryString)
         * NOTE: if it already exists and replace is false, the xact will be
         * aborted.
         */
-       viewOid = DefineVirtualRelation(view, viewParse->targetList,
+       address = DefineVirtualRelation(view, viewParse->targetList,
                                                                        stmt->replace, stmt->options);
 
        /*
@@ -543,9 +546,9 @@ DefineView(ViewStmt *stmt, const char *queryString)
         */
        CommandCounterIncrement();
 
-       StoreViewQuery(viewOid, viewParse, stmt->replace);
+       StoreViewQuery(address.objectId, viewParse, stmt->replace);
 
-       return viewOid;
+       return address;
 }
 
 /*
index eab4d7367c2cafdea54fa85028ddeadeb2d61fc0..f540432ccbc9fc329953360900002cb7bc40b51e 100644 (file)
@@ -191,7 +191,7 @@ InsertRule(char *rulname,
  * DefineRule
  *             Execute a CREATE RULE command.
  */
-Oid
+ObjectAddress
 DefineRule(RuleStmt *stmt, const char *queryString)
 {
        List       *actions;
@@ -225,7 +225,7 @@ DefineRule(RuleStmt *stmt, const char *queryString)
  * This is essentially the same as DefineRule() except that the rule's
  * action and qual have already been passed through parse analysis.
  */
-Oid
+ObjectAddress
 DefineQueryRewrite(char *rulename,
                                   Oid event_relid,
                                   Node *event_qual,
@@ -239,6 +239,7 @@ DefineQueryRewrite(char *rulename,
        Query      *query;
        bool            RelisBecomingView = false;
        Oid                     ruleId = InvalidOid;
+       ObjectAddress address;
 
        /*
         * If we are installing an ON SELECT rule, we had better grab
@@ -604,10 +605,12 @@ DefineQueryRewrite(char *rulename,
                heap_close(relationRelation, RowExclusiveLock);
        }
 
+       ObjectAddressSet(address, RewriteRelationId, ruleId);
+
        /* Close rel, but keep lock till commit... */
        heap_close(event_relation, NoLock);
 
-       return ruleId;
+       return address;
 }
 
 /*
@@ -897,7 +900,7 @@ RangeVarCallbackForRenameRule(const RangeVar *rv, Oid relid, Oid oldrelid,
 /*
  * Rename an existing rewrite rule.
  */
-Oid
+ObjectAddress
 RenameRewriteRule(RangeVar *relation, const char *oldName,
                                  const char *newName)
 {
@@ -907,6 +910,7 @@ RenameRewriteRule(RangeVar *relation, const char *oldName,
        HeapTuple       ruletup;
        Form_pg_rewrite ruleform;
        Oid                     ruleOid;
+       ObjectAddress address;
 
        /*
         * Look up name, check permissions, and acquire lock (which we will NOT
@@ -969,10 +973,12 @@ RenameRewriteRule(RangeVar *relation, const char *oldName,
         */
        CacheInvalidateRelcache(targetrel);
 
+       ObjectAddressSet(address, RewriteRelationId, ruleOid);
+
        /*
         * Close rel, but keep exclusive lock!
         */
        relation_close(targetrel, NoLock);
 
-       return ruleOid;
+       return address;
 }
index 6d269865e7e2b46f0598ef83f57df5e4f734ba1a..daf532693c26d6476050290e1f5d77a6791c1abd 100644 (file)
@@ -818,7 +818,7 @@ standard_ProcessUtility(Node *parsetree,
                                                                           context, params,
                                                                           dest, completionTag);
                                else
-                                       ExecAlterObjectSchemaStmt(stmt);
+                                       ExecAlterObjectSchemaStmt(stmt, NULL);
                        }
                        break;
 
@@ -886,6 +886,7 @@ ProcessUtilitySlow(Node *parsetree,
        bool            isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
        bool            isCompleteQuery = (context <= PROCESS_UTILITY_QUERY);
        bool            needCleanup;
+       ObjectAddress address;
 
        /* All event trigger calls are done only when isCompleteQuery is true */
        needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
@@ -911,7 +912,6 @@ ProcessUtilitySlow(Node *parsetree,
                                {
                                        List       *stmts;
                                        ListCell   *l;
-                                       Oid                     relOid;
 
                                        /* Run parse analysis ... */
                                        stmts = transformCreateStmt((CreateStmt *) parsetree,
@@ -928,9 +928,9 @@ ProcessUtilitySlow(Node *parsetree,
                                                        static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
 
                                                        /* Create the table itself */
-                                                       relOid = DefineRelation((CreateStmt *) stmt,
-                                                                                                       RELKIND_RELATION,
-                                                                                                       InvalidOid);
+                                                       address = DefineRelation((CreateStmt *) stmt,
+                                                                                                        RELKIND_RELATION,
+                                                                                                        InvalidOid, NULL);
 
                                                        /*
                                                         * Let NewRelationCreateToastTable decide if this
@@ -952,16 +952,17 @@ ProcessUtilitySlow(Node *parsetree,
                                                                                                   toast_options,
                                                                                                   true);
 
-                                                       NewRelationCreateToastTable(relOid, toast_options);
+                                                       NewRelationCreateToastTable(address.objectId,
+                                                                                                               toast_options);
                                                }
                                                else if (IsA(stmt, CreateForeignTableStmt))
                                                {
                                                        /* Create the table itself */
-                                                       relOid = DefineRelation((CreateStmt *) stmt,
-                                                                                                       RELKIND_FOREIGN_TABLE,
-                                                                                                       InvalidOid);
+                                                       address = DefineRelation((CreateStmt *) stmt,
+                                                                                                        RELKIND_FOREIGN_TABLE,
+                                                                                                        InvalidOid, NULL);
                                                        CreateForeignTable((CreateForeignTableStmt *) stmt,
-                                                                                          relOid);
+                                                                                          address.objectId);
                                                }
                                                else
                                                {
@@ -1067,7 +1068,8 @@ ProcessUtilitySlow(Node *parsetree,
                                                        break;
                                                case 'C':               /* ADD CONSTRAINT */
                                                        AlterDomainAddConstraint(stmt->typeName,
-                                                                                                        stmt->def);
+                                                                                                        stmt->def,
+                                                                                                        NULL);
                                                        break;
                                                case 'X':               /* DROP CONSTRAINT */
                                                        AlterDomainDropConstraint(stmt->typeName,
@@ -1190,7 +1192,8 @@ ProcessUtilitySlow(Node *parsetree,
                                break;
 
                        case T_AlterExtensionContentsStmt:
-                               ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree);
+                               ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree,
+                                                                                          NULL);
                                break;
 
                        case T_CreateFdwStmt:
@@ -1334,7 +1337,8 @@ ProcessUtilitySlow(Node *parsetree,
                                break;
 
                        case T_AlterObjectSchemaStmt:
-                               ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree);
+                               ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree,
+                                                                                 NULL);
                                break;
 
                        case T_AlterOwnerStmt:
index e5c204db653853ccdf8d6a507ebeea80c45fff4a..573b2deb2d08434f6fe4b78d26193748762a1c54 100644 (file)
@@ -14,8 +14,9 @@
 #ifndef HEAP_H
 #define HEAP_H
 
-#include "parser/parse_node.h"
 #include "catalog/indexing.h"
+#include "catalog/objectaddress.h"
+#include "parser/parse_node.h"
 
 
 typedef struct RawColumnDefault
@@ -68,7 +69,8 @@ extern Oid heap_create_with_catalog(const char *relname,
                                                 Datum reloptions,
                                                 bool use_user_acl,
                                                 bool allow_system_table_mods,
-                                                bool is_internal);
+                                                bool is_internal,
+                                                ObjectAddress *typaddress);
 
 extern void heap_create_init_fork(Relation rel);
 
index 6f4dbab3a88f618aff1958ae1f3f52297956162c..619b2f58bca8f92da213039c678a2656bbb1357c 100644 (file)
@@ -28,6 +28,18 @@ typedef struct ObjectAddress
        int32           objectSubId;    /* Subitem within object (eg column), or 0 */
 } ObjectAddress;
 
+extern const ObjectAddress InvalidObjectAddress;
+
+#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id) \
+       do { \
+               (addr).classId = (class_id); \
+               (addr).objectId = (object_id); \
+               (addr).objectSubId = (object_sub_id); \
+       } while (0)
+
+#define ObjectAddressSet(addr, class_id, object_id) \
+       ObjectAddressSubSet(addr, class_id, object_id, 0)
+
 extern ObjectAddress get_object_address(ObjectType objtype, List *objname,
                                   List *objargs, Relation *relp,
                                   LOCKMODE lockmode, bool missing_ok);
index 5e1196dc7aab8dd32e8fcb3574304a70cfb99962..3e28e2fe027d7918b8b307bb1db31e7f281e229a 100644 (file)
@@ -20,6 +20,7 @@
 #define PG_AGGREGATE_H
 
 #include "catalog/genbki.h"
+#include "catalog/objectaddress.h"
 #include "nodes/pg_list.h"
 
 /* ----------------------------------------------------------------
@@ -308,7 +309,7 @@ DATA(insert ( 3992  h 1 ordered_set_transition_multi        dense_rank_final                                                -               -
 /*
  * prototypes for functions in pg_aggregate.c
  */
-extern Oid AggregateCreate(const char *aggName,
+extern ObjectAddress AggregateCreate(const char *aggName,
                                Oid aggNamespace,
                                char aggKind,
                                int numArgs,
index 6185d218b6a399f083d979659501ae93e0408e9e..7818272e8b9ad6db19178ce74f2b3102f0c6321d 100644 (file)
 #ifndef PG_CONVERSION_FN_H
 #define PG_CONVERSION_FN_H
 
-extern Oid ConversionCreate(const char *conname, Oid connamespace,
+
+#include "catalog/objectaddress.h"
+
+extern ObjectAddress ConversionCreate(const char *conname, Oid connamespace,
                                 Oid conowner,
                                 int32 conforencoding, int32 contoencoding,
                                 Oid conproc, bool def);
index af991d34f729b92926d9dbbf2a55459fa9faba20..e22eb27bd523c89375f4686846b8fa4adda4115e 100644 (file)
@@ -23,6 +23,7 @@
 #define PG_OPERATOR_H
 
 #include "catalog/genbki.h"
+#include "catalog/objectaddress.h"
 #include "nodes/pg_list.h"
 
 /* ----------------
@@ -1812,7 +1813,7 @@ DESCR("is contained by");
 /*
  * function prototypes
  */
-extern Oid OperatorCreate(const char *operatorName,
+extern ObjectAddress OperatorCreate(const char *operatorName,
                           Oid operatorNamespace,
                           Oid leftTypeId,
                           Oid rightTypeId,
index 791d9d62a4cf59c69119e8cd15a29b2cb0340811..e217188111486c07cec0801462b5bd0848c55618 100644 (file)
 #ifndef PG_PROC_FN_H
 #define PG_PROC_FN_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/pg_list.h"
 
-extern Oid ProcedureCreate(const char *procedureName,
+extern ObjectAddress ProcedureCreate(const char *procedureName,
                                Oid procNamespace,
                                bool replace,
                                bool returnsSet,
index 28c43a142d1c6a285ed19ac5ca625aeabb04ce58..02015fcdd64ee753c2c8e07e98555b781a0b258d 100644 (file)
 #ifndef PG_TYPE_FN_H
 #define PG_TYPE_FN_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/nodes.h"
 
 
-extern Oid TypeShellMake(const char *typeName,
+extern ObjectAddress TypeShellMake(const char *typeName,
                          Oid typeNamespace,
                          Oid ownerId);
 
-extern Oid TypeCreate(Oid newTypeOid,
+extern ObjectAddress TypeCreate(Oid newTypeOid,
                   const char *typeName,
                   Oid typeNamespace,
                   Oid relationOid,
index 14d24f124d7b8a6ebe8923cbe80350e80d5e6216..be688909430a62db87c1363a9b4e8946c8891939 100644 (file)
 #define ALTER_H
 
 #include "catalog/dependency.h"
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 #include "utils/relcache.h"
 
-extern Oid     ExecRenameStmt(RenameStmt *stmt);
+extern ObjectAddress ExecRenameStmt(RenameStmt *stmt);
 
-extern Oid     ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt);
+extern ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt,
+                                                 ObjectAddress *oldSchemaAddr);
 extern Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid,
                                                 ObjectAddresses *objsMoved);
 
-extern Oid     ExecAlterOwnerStmt(AlterOwnerStmt *stmt);
+extern ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt);
 extern void AlterObjectOwner_internal(Relation catalog, Oid objectId,
                                                  Oid new_ownerId);
 
index dfc741bec1d76f9c57cdcd65ddab09846f81a720..fa99ed693a5e562acb1fde888b3cc5a35f0badd0 100644 (file)
 #ifndef COLLATIONCMDS_H
 #define COLLATIONCMDS_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 
-extern Oid     DefineCollation(List *names, List *parameters);
+extern ObjectAddress DefineCollation(List *names, List *parameters);
 extern void IsThereCollationInNamespace(const char *collname, Oid nspOid);
 
 #endif   /* COLLATIONCMDS_H */
index 3d61b4452819ff635b12053d63d6cd74f9607cd1..990d36216a255a952ab58369a1c52b6190b6ae2e 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef COMMENT_H
 #define COMMENT_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 
 /*------------------------------------------------------------------
@@ -29,7 +30,7 @@
  *------------------------------------------------------------------
  */
 
-extern Oid     CommentObject(CommentStmt *stmt);
+extern ObjectAddress CommentObject(CommentStmt *stmt);
 
 extern void DeleteComments(Oid oid, Oid classoid, int32 subid);
 
index dd8f6dce6b6be7e7c62e4947a571cf782b15f161..1f322691a496cadedc0f3443c7a51cf524401d08 100644 (file)
@@ -15,8 +15,9 @@
 #ifndef CONVERSIONCMDS_H
 #define CONVERSIONCMDS_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 
-extern Oid     CreateConversionCommand(CreateConversionStmt *parsetree);
+extern ObjectAddress CreateConversionCommand(CreateConversionStmt *parsetree);
 
 #endif   /* CONVERSIONCMDS_H */
index 495298f575d0c1b8bab29b695f72b401caecc6d6..8325d7335955155d96ef77ee1a7d139c716dec77 100644 (file)
 #ifndef CREATEAS_H
 #define CREATEAS_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/params.h"
 #include "nodes/parsenodes.h"
 #include "tcop/dest.h"
 
 
-extern Oid     ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
+extern ObjectAddress ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
                                  ParamListInfo params, char *completionTag);
 
 extern int     GetIntoRelEFlags(IntoClause *intoClause);
index 4b60cdbedc6823507bf4f8a0a26072880148faa5..9fec3344dcac98bc2a45b09ae3ca6521790e7058 100644 (file)
@@ -15,6 +15,7 @@
 #define DBCOMMANDS_H
 
 #include "access/xlogreader.h"
+#include "catalog/objectaddress.h"
 #include "lib/stringinfo.h"
 #include "nodes/parsenodes.h"
 
@@ -40,10 +41,10 @@ typedef struct xl_dbase_drop_rec
 
 extern Oid     createdb(const CreatedbStmt *stmt);
 extern void dropdb(const char *dbname, bool missing_ok);
-extern Oid     RenameDatabase(const char *oldname, const char *newname);
+extern ObjectAddress RenameDatabase(const char *oldname, const char *newname);
 extern Oid     AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel);
 extern Oid     AlterDatabaseSet(AlterDatabaseSetStmt *stmt);
-extern Oid     AlterDatabaseOwner(const char *dbname, Oid newOwnerId);
+extern ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId);
 
 extern Oid     get_database_oid(const char *dbname, bool missingok);
 extern char *get_database_name(Oid dbid);
index cf586feac3679acc33ee6341eec353ed9e3618da..9e3e93b605554b8de179ce5d8ddcca722d71a17d 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef DEFREM_H
 #define DEFREM_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 #include "utils/array.h"
 
@@ -21,7 +22,7 @@
 extern void RemoveObjects(DropStmt *stmt);
 
 /* commands/indexcmds.c */
-extern Oid DefineIndex(Oid relationId,
+extern ObjectAddress DefineIndex(Oid relationId,
                        IndexStmt *stmt,
                        Oid indexRelationId,
                        bool is_alter_table,
@@ -42,12 +43,12 @@ extern bool CheckIndexCompatible(Oid oldId,
 extern Oid     GetDefaultOpClass(Oid type_id, Oid am_id);
 
 /* commands/functioncmds.c */
-extern Oid     CreateFunction(CreateFunctionStmt *stmt, const char *queryString);
+extern ObjectAddress CreateFunction(CreateFunctionStmt *stmt, const char *queryString);
 extern void RemoveFunctionById(Oid funcOid);
 extern void SetFunctionReturnType(Oid funcOid, Oid newRetType);
 extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
-extern Oid     AlterFunction(AlterFunctionStmt *stmt);
-extern Oid     CreateCast(CreateCastStmt *stmt);
+extern ObjectAddress AlterFunction(AlterFunctionStmt *stmt);
+extern ObjectAddress CreateCast(CreateCastStmt *stmt);
 extern void DropCastById(Oid castOid);
 extern void IsThereFunctionInNamespace(const char *proname, int pronargs,
                                                   oidvector *proargtypes, Oid nspOid);
@@ -66,16 +67,16 @@ extern void interpret_function_parameter_list(List *parameters,
                                                                  Oid *requiredResultType);
 
 /* commands/operatorcmds.c */
-extern Oid     DefineOperator(List *names, List *parameters);
+extern ObjectAddress DefineOperator(List *names, List *parameters);
 extern void RemoveOperatorById(Oid operOid);
 
 /* commands/aggregatecmds.c */
-extern Oid DefineAggregate(List *name, List *args, bool oldstyle,
+extern ObjectAddress DefineAggregate(List *name, List *args, bool oldstyle,
                                List *parameters, const char *queryString);
 
 /* commands/opclasscmds.c */
-extern Oid     DefineOpClass(CreateOpClassStmt *stmt);
-extern Oid     DefineOpFamily(CreateOpFamilyStmt *stmt);
+extern ObjectAddress DefineOpClass(CreateOpClassStmt *stmt);
+extern ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt);
 extern Oid     AlterOpFamily(AlterOpFamilyStmt *stmt);
 extern void RemoveOpClassById(Oid opclassOid);
 extern void RemoveOpFamilyById(Oid opfamilyOid);
@@ -90,36 +91,36 @@ extern Oid  get_opclass_oid(Oid amID, List *opclassname, bool missing_ok);
 extern Oid     get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok);
 
 /* commands/tsearchcmds.c */
-extern Oid     DefineTSParser(List *names, List *parameters);
+extern ObjectAddress DefineTSParser(List *names, List *parameters);
 extern void RemoveTSParserById(Oid prsId);
 
-extern Oid     DefineTSDictionary(List *names, List *parameters);
+extern ObjectAddress DefineTSDictionary(List *names, List *parameters);
 extern void RemoveTSDictionaryById(Oid dictId);
-extern Oid     AlterTSDictionary(AlterTSDictionaryStmt *stmt);
+extern ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt);
 
-extern Oid     DefineTSTemplate(List *names, List *parameters);
+extern ObjectAddress DefineTSTemplate(List *names, List *parameters);
 extern void RemoveTSTemplateById(Oid tmplId);
 
-extern Oid     DefineTSConfiguration(List *names, List *parameters);
+extern ObjectAddress DefineTSConfiguration(List *names, List *parameters);
 extern void RemoveTSConfigurationById(Oid cfgId);
-extern Oid     AlterTSConfiguration(AlterTSConfigurationStmt *stmt);
+extern ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt);
 
 extern text *serialize_deflist(List *deflist);
 extern List *deserialize_deflist(Datum txt);
 
 /* commands/foreigncmds.c */
-extern Oid     AlterForeignServerOwner(const char *name, Oid newOwnerId);
+extern ObjectAddress AlterForeignServerOwner(const char *name, Oid newOwnerId);
 extern void AlterForeignServerOwner_oid(Oid, Oid newOwnerId);
-extern Oid     AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId);
+extern ObjectAddress AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId);
 extern void AlterForeignDataWrapperOwner_oid(Oid fwdId, Oid newOwnerId);
-extern Oid     CreateForeignDataWrapper(CreateFdwStmt *stmt);
-extern Oid     AlterForeignDataWrapper(AlterFdwStmt *stmt);
+extern ObjectAddress CreateForeignDataWrapper(CreateFdwStmt *stmt);
+extern ObjectAddress AlterForeignDataWrapper(AlterFdwStmt *stmt);
 extern void RemoveForeignDataWrapperById(Oid fdwId);
-extern Oid     CreateForeignServer(CreateForeignServerStmt *stmt);
-extern Oid     AlterForeignServer(AlterForeignServerStmt *stmt);
+extern ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt);
+extern ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt);
 extern void RemoveForeignServerById(Oid srvId);
-extern Oid     CreateUserMapping(CreateUserMappingStmt *stmt);
-extern Oid     AlterUserMapping(AlterUserMappingStmt *stmt);
+extern ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt);
+extern ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt);
 extern Oid     RemoveUserMapping(DropUserMappingStmt *stmt);
 extern void RemoveUserMappingById(Oid umId);
 extern void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid);
index 9ac9fc37356d05d270821d52fb4402379703f393..7eb2156085680772bea75c0b078f218f45bf8496 100644 (file)
@@ -43,7 +43,7 @@ extern void RemoveEventTriggerById(Oid ctrigOid);
 extern Oid     get_event_trigger_oid(const char *trigname, bool missing_ok);
 
 extern Oid     AlterEventTrigger(AlterEventTrigStmt *stmt);
-extern Oid     AlterEventTriggerOwner(const char *name, Oid newOwnerId);
+extern ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId);
 extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId);
 
 extern bool EventTriggerSupportsObjectType(ObjectType obtype);
index a349d6a711bfc39ce9922fa4a754d82f5df2344c..40ecea2fee46bf944543cc95078aea6810bebaa5 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef EXTENSION_H
 #define EXTENSION_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 
 
@@ -27,23 +28,25 @@ extern bool creating_extension;
 extern Oid     CurrentExtensionObject;
 
 
-extern Oid     CreateExtension(CreateExtensionStmt *stmt);
+extern ObjectAddress CreateExtension(CreateExtensionStmt *stmt);
 
 extern void RemoveExtensionById(Oid extId);
 
-extern Oid InsertExtensionTuple(const char *extName, Oid extOwner,
+extern ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner,
                                         Oid schemaOid, bool relocatable, const char *extVersion,
                                         Datum extConfig, Datum extCondition,
                                         List *requiredExtensions);
 
-extern Oid     ExecAlterExtensionStmt(AlterExtensionStmt *stmt);
+extern ObjectAddress ExecAlterExtensionStmt(AlterExtensionStmt *stmt);
 
-extern Oid     ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt);
+extern ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt,
+                                                          ObjectAddress *objAddress);
 
 extern Oid     get_extension_oid(const char *extname, bool missing_ok);
 extern char *get_extension_name(Oid ext_oid);
 
-extern Oid     AlterExtensionNamespace(List *names, const char *newschema);
+extern ObjectAddress AlterExtensionNamespace(List *names, const char *newschema,
+                                               Oid *oldschema);
 
 extern void AlterExtensionOwner_oid(Oid extensionOid, Oid newOwnerId);
 
index 91e2eb532a611a0a8c032985298b9f82df4f5ae5..37a81aa42854e0c1b6d9f4f2c805ff7731c08daa 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef MATVIEW_H
 #define MATVIEW_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/params.h"
 #include "nodes/parsenodes.h"
 #include "tcop/dest.h"
@@ -22,7 +23,7 @@
 
 extern void SetMatViewPopulatedState(Relation relation, bool newstate);
 
-extern Oid ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
+extern ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
                                   ParamListInfo params, char *completionTag);
 
 extern DestReceiver *CreateTransientRelDestReceiver(Oid oid);
index e911fccf830438911aa3569b75adbb007cd32175..ac322e0db9263519a8e8edac64b7885460a1c31f 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef POLICY_H
 #define POLICY_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 #include "utils/relcache.h"
 
@@ -22,13 +23,13 @@ extern void RelationBuildRowSecurity(Relation relation);
 
 extern void RemovePolicyById(Oid policy_id);
 
-extern Oid CreatePolicy(CreatePolicyStmt *stmt);
-extern Oid AlterPolicy(AlterPolicyStmt *stmt);
+extern ObjectAddress CreatePolicy(CreatePolicyStmt *stmt);
+extern ObjectAddress AlterPolicy(AlterPolicyStmt *stmt);
 
 extern Oid get_relation_policy_oid(Oid relid, const char *policy_name,
                                                bool missing_ok);
 
-extern Oid rename_policy(RenameStmt *stmt);
+extern ObjectAddress rename_policy(RenameStmt *stmt);
 
 
 #endif   /* POLICY_H */
index f43c321ce235d4f6a19db0841373fd1a24418450..f056978805d4055655ffa775887238b6d4cb2eb4 100644 (file)
 #ifndef PROCLANG_H
 #define PROCLANG_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 
-extern Oid     CreateProceduralLanguage(CreatePLangStmt *stmt);
+extern ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt);
 extern void DropProceduralLanguageById(Oid langOid);
 extern bool PLTemplateExists(const char *languageName);
 extern Oid     get_language_oid(const char *langname, bool missing_ok);
index d08fdd4f6c773a9bab47f5d769df06954fba7ef5..55207a481686a14c0d8b78c66d06f7adaa3130e2 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef SCHEMACMDS_H
 #define SCHEMACMDS_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 
 extern Oid CreateSchemaCommand(CreateSchemaStmt *parsetree,
@@ -22,8 +23,8 @@ extern Oid CreateSchemaCommand(CreateSchemaStmt *parsetree,
 
 extern void RemoveSchemaById(Oid schemaOid);
 
-extern Oid     RenameSchema(const char *oldname, const char *newname);
-extern Oid     AlterSchemaOwner(const char *name, Oid newOwnerId);
+extern ObjectAddress RenameSchema(const char *oldname, const char *newname);
+extern ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId);
 extern void AlterSchemaOwner_oid(Oid schemaOid, Oid newOwnerId);
 
 #endif   /* SCHEMACMDS_H */
index 7e3dde4d3a439a123a127266f05ad5003187380b..661da2b21b0ad94a31727fed67d706b1403a005b 100644 (file)
@@ -24,7 +24,7 @@ extern void DeleteSharedSecurityLabel(Oid objectId, Oid classId);
 /*
  * Statement and ESP hook support
  */
-extern Oid     ExecSecLabelStmt(SecLabelStmt *stmt);
+extern ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt);
 
 typedef void (*check_object_relabel_type) (const ObjectAddress *object,
                                                                                                           const char *seclabel);
index 1baf43d3d32f3ba632f05399882134857097edfc..44862bba81d050844a735ed0a21f0da1b8d32431 100644 (file)
@@ -14,6 +14,7 @@
 #define SEQUENCE_H
 
 #include "access/xlogreader.h"
+#include "catalog/objectaddress.h"
 #include "fmgr.h"
 #include "lib/stringinfo.h"
 #include "nodes/parsenodes.h"
@@ -72,8 +73,8 @@ extern Datum lastval(PG_FUNCTION_ARGS);
 
 extern Datum pg_sequence_parameters(PG_FUNCTION_ARGS);
 
-extern Oid     DefineSequence(CreateSeqStmt *stmt);
-extern Oid     AlterSequence(AlterSeqStmt *stmt);
+extern ObjectAddress DefineSequence(CreateSeqStmt *stmt);
+extern ObjectAddress AlterSequence(AlterSeqStmt *stmt);
 extern void ResetSequence(Oid seq_relid);
 extern void ResetSequenceCaches(void);
 
index a55e8d42ee7ceb53eb4e4d791914051f53a84c8b..f269c63558806800cd9975dde5377d01fa7d9964 100644 (file)
 
 #include "access/htup.h"
 #include "catalog/dependency.h"
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 #include "storage/lock.h"
 #include "utils/relcache.h"
 
 
-extern Oid     DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId);
+extern ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
+                          ObjectAddress *typaddress);
 
 extern void RemoveRelations(DropStmt *drop);
 
@@ -37,7 +39,8 @@ extern void AlterTableInternal(Oid relid, List *cmds, bool recurse);
 
 extern Oid     AlterTableMoveAll(AlterTableMoveAllStmt *stmt);
 
-extern Oid     AlterTableNamespace(AlterObjectSchemaStmt *stmt);
+extern ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt,
+                                       Oid *oldschema);
 
 extern void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid,
                                                        Oid nspOid, ObjectAddresses *objsMoved);
@@ -53,11 +56,13 @@ extern void ExecuteTruncate(TruncateStmt *stmt);
 
 extern void SetRelationHasSubclass(Oid relationId, bool relhassubclass);
 
-extern Oid     renameatt(RenameStmt *stmt);
+extern ObjectAddress renameatt(RenameStmt *stmt);
 
-extern Oid     RenameConstraint(RenameStmt *stmt);
+extern ObjectAddress renameatt_type(RenameStmt *stmt);
 
-extern Oid     RenameRelation(RenameStmt *stmt);
+extern ObjectAddress RenameConstraint(RenameStmt *stmt);
+
+extern ObjectAddress RenameRelation(RenameStmt *stmt);
 
 extern void RenameRelationInternal(Oid myrelid,
                                           const char *newrelname, bool is_internal);
index 70734d60301e21ad1fb56eed81e1083d7c235c61..86b0477335b50023eaee83bc23b09cdc40504ac8 100644 (file)
@@ -15,6 +15,7 @@
 #define TABLESPACE_H
 
 #include "access/xlogreader.h"
+#include "catalog/objectaddress.h"
 #include "lib/stringinfo.h"
 #include "nodes/parsenodes.h"
 
@@ -42,7 +43,7 @@ typedef struct TableSpaceOpts
 
 extern Oid     CreateTableSpace(CreateTableSpaceStmt *stmt);
 extern void DropTableSpace(DropTableSpaceStmt *stmt);
-extern Oid     RenameTableSpace(const char *oldname, const char *newname);
+extern ObjectAddress RenameTableSpace(const char *oldname, const char *newname);
 extern Oid     AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt);
 
 extern void TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo);
index d0c0dccb1f31db4ff68f4dd4d3f44a2f60f30f83..1a53f6cde596cfa11a01b82d98d1b33c4a638c91 100644 (file)
@@ -13,6 +13,7 @@
 #ifndef TRIGGER_H
 #define TRIGGER_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/execnodes.h"
 #include "nodes/parsenodes.h"
 
@@ -108,14 +109,14 @@ extern PGDLLIMPORT int SessionReplicationRole;
 #define TRIGGER_FIRES_ON_REPLICA                       'R'
 #define TRIGGER_DISABLED                                       'D'
 
-extern Oid CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
+extern ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
                          Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid,
                          bool isInternal);
 
 extern void RemoveTriggerById(Oid trigOid);
 extern Oid     get_trigger_oid(Oid relid, const char *name, bool missing_ok);
 
-extern Oid     renametrig(RenameStmt *stmt);
+extern ObjectAddress renametrig(RenameStmt *stmt);
 
 extern void EnableDisableTrigger(Relation rel, const char *tgname,
                                         char fires_when, bool skip_system);
index 0a638002c3cab8071ef896227711a4305ab716e2..ef4b41b5a55be607f16bfc5c4eae6782c4141f7b 100644 (file)
 
 #define DEFAULT_TYPDELIM               ','
 
-extern Oid     DefineType(List *names, List *parameters);
+extern ObjectAddress DefineType(List *names, List *parameters);
 extern void RemoveTypeById(Oid typeOid);
-extern Oid     DefineDomain(CreateDomainStmt *stmt);
-extern Oid     DefineEnum(CreateEnumStmt *stmt);
-extern Oid     DefineRange(CreateRangeStmt *stmt);
-extern Oid     AlterEnum(AlterEnumStmt *stmt, bool isTopLevel);
-extern Oid     DefineCompositeType(RangeVar *typevar, List *coldeflist);
+extern ObjectAddress DefineDomain(CreateDomainStmt *stmt);
+extern ObjectAddress DefineEnum(CreateEnumStmt *stmt);
+extern ObjectAddress DefineRange(CreateRangeStmt *stmt);
+extern ObjectAddress AlterEnum(AlterEnumStmt *stmt, bool isTopLevel);
+extern ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist);
 extern Oid     AssignTypeArrayOid(void);
 
-extern Oid     AlterDomainDefault(List *names, Node *defaultRaw);
-extern Oid     AlterDomainNotNull(List *names, bool notNull);
-extern Oid     AlterDomainAddConstraint(List *names, Node *constr);
-extern Oid     AlterDomainValidateConstraint(List *names, char *constrName);
-extern Oid AlterDomainDropConstraint(List *names, const char *constrName,
+extern ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw);
+extern ObjectAddress AlterDomainNotNull(List *names, bool notNull);
+extern ObjectAddress AlterDomainAddConstraint(List *names, Node *constr,
+                                                ObjectAddress *constrAddr);
+extern ObjectAddress AlterDomainValidateConstraint(List *names, char *constrName);
+extern ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName,
                                                  DropBehavior behavior, bool missing_ok);
 
 extern void checkDomainOwner(HeapTuple tup);
 
-extern Oid     RenameType(RenameStmt *stmt);
-extern Oid     AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype);
+extern ObjectAddress RenameType(RenameStmt *stmt);
+extern ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype);
 extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
                                           bool hasDependEntry);
-extern Oid     AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype);
+extern ObjectAddress AlterTypeNamespace(List *names, const char *newschema,
+                                  ObjectType objecttype, Oid *oldschema);
 extern Oid     AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses *objsMoved);
 extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
                                                   bool isImplicitArray,
index d76685182f8b56de753dc9d4453dfc01c0a8eff4..ccadb04b8c7688f944706babf2b62991678e4cfc 100644 (file)
@@ -11,6 +11,7 @@
 #ifndef USER_H
 #define USER_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 
 
@@ -27,7 +28,7 @@ extern Oid    AlterRole(AlterRoleStmt *stmt);
 extern Oid     AlterRoleSet(AlterRoleSetStmt *stmt);
 extern void DropRole(DropRoleStmt *stmt);
 extern void GrantRole(GrantRoleStmt *stmt);
-extern Oid     RenameRole(const char *oldname, const char *newname);
+extern ObjectAddress RenameRole(const char *oldname, const char *newname);
 extern void DropOwnedObjects(DropOwnedStmt *stmt);
 extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt);
 extern List *roleNamesToIds(List *memberNames);
index 595d2663f166be1f0fee23dc84f8b3dab1eb4745..53db76e6c629ee5704df7bd5dc6da587d5608d5f 100644 (file)
 #ifndef VIEW_H
 #define VIEW_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 
 extern void validateWithCheckOption(char *value);
 
-extern Oid     DefineView(ViewStmt *stmt, const char *queryString);
+extern ObjectAddress DefineView(ViewStmt *stmt, const char *queryString);
 
 extern void StoreViewQuery(Oid viewOid, Query *viewParse, bool replace);
 
index d384552ca28cd9063e8ec9e3a77b55fcaf88ece5..5f0dc31bd3dc056e00395d2237a230698ba0bb52 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef REWRITEDEFINE_H
 #define REWRITEDEFINE_H
 
+#include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
 #include "utils/relcache.h"
 
@@ -22,9 +23,9 @@
 #define RULE_FIRES_ON_REPLICA  'R'
 #define RULE_DISABLED                  'D'
 
-extern Oid     DefineRule(RuleStmt *stmt, const char *queryString);
+extern ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString);
 
-extern Oid DefineQueryRewrite(char *rulename,
+extern ObjectAddress DefineQueryRewrite(char *rulename,
                                   Oid event_relid,
                                   Node *event_qual,
                                   CmdType event_type,
@@ -32,7 +33,7 @@ extern Oid DefineQueryRewrite(char *rulename,
                                   bool replace,
                                   List *action);
 
-extern Oid RenameRewriteRule(RangeVar *relation, const char *oldName,
+extern ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName,
                                  const char *newName);
 
 extern void setRuleCheckAsUser(Node *node, Oid userid);