summaryrefslogtreecommitdiff
path: root/src/backend/commands/alter.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2015-03-03 14:10:50 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2015-03-03 14:10:50 -0300
commita2e35b53c39b2a27d3e332dc7c506539c306fd44 (patch)
tree1f4cd33208d33f4a8b3159b0d3757109c67d4b14 /src/backend/commands/alter.c
parent6f9d79904748c26a58991942dc6719db558f77b0 (diff)
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
Diffstat (limited to 'src/backend/commands/alter.c')
-rw-r--r--src/backend/commands/alter.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c
index 78b54b4a418..59aacef7ea9 100644
--- a/src/backend/commands/alter.c
+++ b/src/backend/commands/alter.c
@@ -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 */
}
}