From a2e35b53c39b2a27d3e332dc7c506539c306fd44 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 3 Mar 2015 14:10:50 -0300 Subject: 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 --- src/backend/commands/functioncmds.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/backend/commands/functioncmds.c') diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index b3a91fc681f..f4725056da0 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -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; } /* -- cgit v1.2.3