mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Add an assertion in get_object_address()
Some places declared a Relation before calling get_object_address() only to assert that the relation is NULL after the call. The new assertion allows passing NULL as the relation argument at those places making the code cleaner and easier to understand. Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://www.postgresql.org/message-id/ZzG34eNrT83W/Orz@ip-10-97-1-34.eu-west-3.compute.internal
This commit is contained in:
@ -896,7 +896,8 @@ static void getRelationIdentity(StringInfo buffer, Oid relid, List **object,
|
|||||||
*
|
*
|
||||||
* If the object is a relation or a child object of a relation (e.g. an
|
* If the object is a relation or a child object of a relation (e.g. an
|
||||||
* attribute or constraint), the relation is also opened and *relp receives
|
* attribute or constraint), the relation is also opened and *relp receives
|
||||||
* the open relcache entry pointer; otherwise, *relp is set to NULL. This
|
* the open relcache entry pointer; otherwise, *relp is set to NULL.
|
||||||
|
* (relp can be NULL if the caller never passes a relation-related object.) This
|
||||||
* is a bit grotty but it makes life simpler, since the caller will
|
* is a bit grotty but it makes life simpler, since the caller will
|
||||||
* typically need the relcache entry too. Caller must close the relcache
|
* typically need the relcache entry too. Caller must close the relcache
|
||||||
* entry when done with it. The relation is locked with the specified lockmode
|
* entry when done with it. The relation is locked with the specified lockmode
|
||||||
@ -1204,7 +1205,11 @@ get_object_address(ObjectType objtype, Node *object,
|
|||||||
old_address = address;
|
old_address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* relp must be given if it's a relation */
|
||||||
|
Assert(!relation || relp);
|
||||||
|
|
||||||
/* Return the object address and the relation. */
|
/* Return the object address and the relation. */
|
||||||
|
if (relp)
|
||||||
*relp = relation;
|
*relp = relation;
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
@ -421,13 +421,11 @@ ExecRenameStmt(RenameStmt *stmt)
|
|||||||
{
|
{
|
||||||
ObjectAddress address;
|
ObjectAddress address;
|
||||||
Relation catalog;
|
Relation catalog;
|
||||||
Relation relation;
|
|
||||||
|
|
||||||
address = get_object_address(stmt->renameType,
|
address = get_object_address(stmt->renameType,
|
||||||
stmt->object,
|
stmt->object,
|
||||||
&relation,
|
NULL,
|
||||||
AccessExclusiveLock, false);
|
AccessExclusiveLock, false);
|
||||||
Assert(relation == NULL);
|
|
||||||
|
|
||||||
catalog = table_open(address.classId, RowExclusiveLock);
|
catalog = table_open(address.classId, RowExclusiveLock);
|
||||||
AlterObjectRename_internal(catalog,
|
AlterObjectRename_internal(catalog,
|
||||||
@ -482,8 +480,7 @@ ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddre
|
|||||||
table_close(rel, NoLock);
|
table_close(rel, NoLock);
|
||||||
|
|
||||||
refAddr = get_object_address(OBJECT_EXTENSION, (Node *) stmt->extname,
|
refAddr = get_object_address(OBJECT_EXTENSION, (Node *) stmt->extname,
|
||||||
&rel, AccessExclusiveLock, false);
|
NULL, AccessExclusiveLock, false);
|
||||||
Assert(rel == NULL);
|
|
||||||
if (refAddress)
|
if (refAddress)
|
||||||
*refAddress = refAddr;
|
*refAddress = refAddr;
|
||||||
|
|
||||||
@ -563,16 +560,14 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt,
|
|||||||
case OBJECT_TSTEMPLATE:
|
case OBJECT_TSTEMPLATE:
|
||||||
{
|
{
|
||||||
Relation catalog;
|
Relation catalog;
|
||||||
Relation relation;
|
|
||||||
Oid classId;
|
Oid classId;
|
||||||
Oid nspOid;
|
Oid nspOid;
|
||||||
|
|
||||||
address = get_object_address(stmt->objectType,
|
address = get_object_address(stmt->objectType,
|
||||||
stmt->object,
|
stmt->object,
|
||||||
&relation,
|
NULL,
|
||||||
AccessExclusiveLock,
|
AccessExclusiveLock,
|
||||||
false);
|
false);
|
||||||
Assert(relation == NULL);
|
|
||||||
classId = address.classId;
|
classId = address.classId;
|
||||||
catalog = table_open(classId, RowExclusiveLock);
|
catalog = table_open(classId, RowExclusiveLock);
|
||||||
nspOid = LookupCreationNamespace(stmt->newschema);
|
nspOid = LookupCreationNamespace(stmt->newschema);
|
||||||
@ -876,15 +871,13 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
|
|||||||
case OBJECT_TSDICTIONARY:
|
case OBJECT_TSDICTIONARY:
|
||||||
case OBJECT_TSCONFIGURATION:
|
case OBJECT_TSCONFIGURATION:
|
||||||
{
|
{
|
||||||
Relation relation;
|
|
||||||
ObjectAddress address;
|
ObjectAddress address;
|
||||||
|
|
||||||
address = get_object_address(stmt->objectType,
|
address = get_object_address(stmt->objectType,
|
||||||
stmt->object,
|
stmt->object,
|
||||||
&relation,
|
NULL,
|
||||||
AccessExclusiveLock,
|
AccessExclusiveLock,
|
||||||
false);
|
false);
|
||||||
Assert(relation == NULL);
|
|
||||||
|
|
||||||
AlterObjectOwner_internal(address.classId, address.objectId,
|
AlterObjectOwner_internal(address.classId, address.objectId,
|
||||||
newowner);
|
newowner);
|
||||||
|
Reference in New Issue
Block a user