1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +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

@ -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 */
}
}