1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

Change many routines to return ObjectAddress rather than OID

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
This commit is contained in:
Alvaro Herrera
2015-03-03 14:10:50 -03:00
parent 6f9d799047
commit a2e35b53c3
68 changed files with 840 additions and 558 deletions

View 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;
}