Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite468ec0

Browse files
committed
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 atthose 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
1 parent818119a commite468ec0

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

‎src/backend/catalog/objectaddress.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,8 @@ static void getRelationIdentity(StringInfo buffer, Oid relid, List **object,
896896
*
897897
* If the object is a relation or a child object of a relation (e.g. an
898898
* attribute or constraint), the relation is also opened and *relp receives
899-
* the open relcache entry pointer; otherwise, *relp is set to NULL. This
899+
* the open relcache entry pointer; otherwise, *relp is set to NULL.
900+
* (relp can be NULL if the caller never passes a relation-related object.) This
900901
* is a bit grotty but it makes life simpler, since the caller will
901902
* typically need the relcache entry too. Caller must close the relcache
902903
* entry when done with it. The relation is locked with the specified lockmode
@@ -1204,8 +1205,12 @@ get_object_address(ObjectType objtype, Node *object,
12041205
old_address=address;
12051206
}
12061207

1208+
/* relp must be given if it's a relation */
1209+
Assert(!relation||relp);
1210+
12071211
/* Return the object address and the relation. */
1208-
*relp=relation;
1212+
if (relp)
1213+
*relp=relation;
12091214
returnaddress;
12101215
}
12111216

‎src/backend/commands/alter.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,11 @@ ExecRenameStmt(RenameStmt *stmt)
421421
{
422422
ObjectAddressaddress;
423423
Relationcatalog;
424-
Relationrelation;
425424

426425
address=get_object_address(stmt->renameType,
427426
stmt->object,
428-
&relation,
427+
NULL,
429428
AccessExclusiveLock, false);
430-
Assert(relation==NULL);
431429

432430
catalog=table_open(address.classId,RowExclusiveLock);
433431
AlterObjectRename_internal(catalog,
@@ -482,8 +480,7 @@ ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddre
482480
table_close(rel,NoLock);
483481

484482
refAddr=get_object_address(OBJECT_EXTENSION, (Node*)stmt->extname,
485-
&rel,AccessExclusiveLock, false);
486-
Assert(rel==NULL);
483+
NULL,AccessExclusiveLock, false);
487484
if (refAddress)
488485
*refAddress=refAddr;
489486

@@ -563,16 +560,14 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt,
563560
caseOBJECT_TSTEMPLATE:
564561
{
565562
Relationcatalog;
566-
Relationrelation;
567563
OidclassId;
568564
OidnspOid;
569565

570566
address=get_object_address(stmt->objectType,
571567
stmt->object,
572-
&relation,
568+
NULL,
573569
AccessExclusiveLock,
574570
false);
575-
Assert(relation==NULL);
576571
classId=address.classId;
577572
catalog=table_open(classId,RowExclusiveLock);
578573
nspOid=LookupCreationNamespace(stmt->newschema);
@@ -876,15 +871,13 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
876871
caseOBJECT_TSDICTIONARY:
877872
caseOBJECT_TSCONFIGURATION:
878873
{
879-
Relationrelation;
880874
ObjectAddressaddress;
881875

882876
address=get_object_address(stmt->objectType,
883877
stmt->object,
884-
&relation,
878+
NULL,
885879
AccessExclusiveLock,
886880
false);
887-
Assert(relation==NULL);
888881

889882
AlterObjectOwner_internal(address.classId,address.objectId,
890883
newowner);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp