Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8b6d6cf

Browse files
committed
Remove objname/objargs split for referring to objects
In simpler times, it might have worked to refer to all kinds of objects by a list of name components and an optional argument list. But this doesn't work for all objects, which has resulted in a collection of hacks to place various other nodes types into these fields, which have to be unpacked at the other end. This makes it also weird to represent lists of such things in the grammar, because they would have to be lists of singleton lists, to make the unpacking work consistently. The other problem is that keeping separate name and args fields makes it awkward to deal with lists of functions. Change that by dropping the objargs field and have objname, renamed to object, be a generic Node, which can then be flexibly assigned and managed using the normal Node mechanisms. In many cases it will still be a List of names, in some cases it will be a string Value, for types it will be the existing Typename, for functions it will now use the existing ObjectWithArgs node type. Some of the more obscure object types still use somewhat arbitrary nested lists. Reviewed-by: Jim Nasby <Jim.Nasby@BlueTreble.com> Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
1 parent 550214a commit 8b6d6cf

File tree

18 files changed

+610
-635
lines changed

18 files changed

+610
-635
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 246 additions & 201 deletions
Large diffs are not rendered by default.

src/backend/commands/alter.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ ExecRenameStmt(RenameStmt *stmt)
385385
Relation relation;
386386

387387
address = get_object_address(stmt->renameType,
388-
stmt->object, stmt->objarg,
388+
stmt->object,
389389
&relation,
390390
AccessExclusiveLock, false);
391391
Assert(relation == NULL);
@@ -421,8 +421,8 @@ ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddre
421421
Relation rel;
422422

423423
address =
424-
get_object_address_rv(stmt->objectType, stmt->relation, stmt->objname,
425-
stmt->objargs, &rel, AccessExclusiveLock, false);
424+
get_object_address_rv(stmt->objectType, stmt->relation, (List *) stmt->object,
425+
&rel, AccessExclusiveLock, false);
426426

427427
/*
428428
* If a relation was involved, it would have been opened and locked. We
@@ -431,8 +431,8 @@ ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddre
431431
if (rel)
432432
heap_close(rel, NoLock);
433433

434-
refAddr = get_object_address(OBJECT_EXTENSION, list_make1(stmt->extname),
435-
NULL, &rel, AccessExclusiveLock, false);
434+
refAddr = get_object_address(OBJECT_EXTENSION, (Node *) stmt->extname,
435+
&rel, AccessExclusiveLock, false);
436436
Assert(rel == NULL);
437437
if (refAddress)
438438
*refAddress = refAddr;
@@ -461,7 +461,7 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt,
461461
switch (stmt->objectType)
462462
{
463463
case OBJECT_EXTENSION:
464-
address = AlterExtensionNamespace(stmt->object, stmt->newschema,
464+
address = AlterExtensionNamespace(strVal((Value *) stmt->object), stmt->newschema,
465465
oldSchemaAddr ? &oldNspOid : NULL);
466466
break;
467467

@@ -476,7 +476,7 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt,
476476

477477
case OBJECT_DOMAIN:
478478
case OBJECT_TYPE:
479-
address = AlterTypeNamespace(stmt->object, stmt->newschema,
479+
address = AlterTypeNamespace(castNode(List, stmt->object), stmt->newschema,
480480
stmt->objectType,
481481
oldSchemaAddr ? &oldNspOid : NULL);
482482
break;
@@ -501,7 +501,6 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt,
501501

502502
address = get_object_address(stmt->objectType,
503503
stmt->object,
504-
stmt->objarg,
505504
&relation,
506505
AccessExclusiveLock,
507506
false);
@@ -764,33 +763,34 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
764763
switch (stmt->objectType)
765764
{
766765
case OBJECT_DATABASE:
767-
return AlterDatabaseOwner(strVal(linitial(stmt->object)), newowner);
766+
return AlterDatabaseOwner(strVal((Value *) stmt->object), newowner);
768767

769768
case OBJECT_SCHEMA:
770-
return AlterSchemaOwner(strVal(linitial(stmt->object)), newowner);
769+
return AlterSchemaOwner(strVal((Value *) stmt->object), newowner);
771770

772771
case OBJECT_TYPE:
773772
case OBJECT_DOMAIN: /* same as TYPE */
774-
return AlterTypeOwner(stmt->object, newowner, stmt->objectType);
773+
return AlterTypeOwner(castNode(List, stmt->object), newowner, stmt->objectType);
774+
break;
775775

776776
case OBJECT_FDW:
777-
return AlterForeignDataWrapperOwner(strVal(linitial(stmt->object)),
777+
return AlterForeignDataWrapperOwner(strVal((Value *) stmt->object),
778778
newowner);
779779

780780
case OBJECT_FOREIGN_SERVER:
781-
return AlterForeignServerOwner(strVal(linitial(stmt->object)),
781+
return AlterForeignServerOwner(strVal((Value *) stmt->object),
782782
newowner);
783783

784784
case OBJECT_EVENT_TRIGGER:
785-
return AlterEventTriggerOwner(strVal(linitial(stmt->object)),
785+
return AlterEventTriggerOwner(strVal((Value *) stmt->object),
786786
newowner);
787787

788788
case OBJECT_PUBLICATION:
789-
return AlterPublicationOwner(strVal(linitial(stmt->object)),
789+
return AlterPublicationOwner(strVal((Value *) stmt->object),
790790
newowner);
791791

792792
case OBJECT_SUBSCRIPTION:
793-
return AlterSubscriptionOwner(strVal(linitial(stmt->object)),
793+
return AlterSubscriptionOwner(strVal((Value *) stmt->object),
794794
newowner);
795795

796796
/* Generic cases */
@@ -814,7 +814,6 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
814814

815815
address = get_object_address(stmt->objectType,
816816
stmt->object,
817-
stmt->objarg,
818817
&relation,
819818
AccessExclusiveLock,
820819
false);

src/backend/commands/comment.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ CommentObject(CommentStmt *stmt)
4848
* (which is really pg_restore's fault, but for now we will work around
4949
* the problem here). Consensus is that the best fix is to treat wrong
5050
* database name as a WARNING not an ERROR; hence, the following special
51-
* case. (If the length of stmt->objname is not 1, get_object_address
52-
* will throw an error below; that's OK.)
51+
* case.
5352
*/
54-
if (stmt->objtype == OBJECT_DATABASE && list_length(stmt->objname) == 1)
53+
if (stmt->objtype == OBJECT_DATABASE)
5554
{
56-
char *database = strVal(linitial(stmt->objname));
55+
char *database = strVal((Value *) stmt->object);
5756

5857
if (!OidIsValid(get_database_oid(database, true)))
5958
{
@@ -70,12 +69,12 @@ CommentObject(CommentStmt *stmt)
7069
* does not exist, and will also acquire a lock on the target to guard
7170
* against concurrent DROP operations.
7271
*/
73-
address = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,
72+
address = get_object_address(stmt->objtype, stmt->object,
7473
&relation, ShareUpdateExclusiveLock, false);
7574

7675
/* Require ownership of the target object. */
7776
check_object_ownership(GetUserId(), stmt->objtype, address,
78-
stmt->objname, stmt->objargs, relation);
77+
stmt->object, relation);
7978

8079
/* Perform other integrity checks as needed. */
8180
switch (stmt->objtype)

0 commit comments

Comments
 (0)