summaryrefslogtreecommitdiff
path: root/src/backend/commands/alter.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2011-12-15 18:51:46 -0500
committerRobert Haas <rhaas@postgresql.org>2011-12-15 19:02:38 -0500
commit74a1d4fe7cc092076806767925d6f34ea347efde (patch)
tree4aec82c1cc22d267358d7216e7ec78650ee05f9f /src/backend/commands/alter.c
parentd039fd51f79e9ddde4d692d2b396bdf5722b4c4e (diff)
Improve behavior of concurrent rename statements.
Previously, renaming a table, sequence, view, index, foreign table, column, or trigger checked permissions before locking the object, which meant that if permissions were revoked during the lock wait, we would still allow the operation. Similarly, if the original object is dropped and a new one with the same name is created, the operation will be allowed if we had permissions on the old object; the permissions on the new object don't matter. All this is now fixed. Along the way, attempting to rename a trigger on a foreign table now gives the same error message as trying to create one there in the first place (i.e. that it's not a table or view) rather than simply stating that no trigger by that name exists. Patch by me; review by Noah Misch.
Diffstat (limited to 'src/backend/commands/alter.c')
-rw-r--r--src/backend/commands/alter.c62
1 files changed, 9 insertions, 53 deletions
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c
index f9be3a9a4ec..2954bb27dd9 100644
--- a/src/backend/commands/alter.c
+++ b/src/backend/commands/alter.c
@@ -105,62 +105,18 @@ ExecRenameStmt(RenameStmt *stmt)
case OBJECT_SEQUENCE:
case OBJECT_VIEW:
case OBJECT_INDEX:
+ case OBJECT_FOREIGN_TABLE:
+ RenameRelation(stmt);
+ break;
+
case OBJECT_COLUMN:
case OBJECT_ATTRIBUTE:
+ renameatt(stmt);
+ break;
+
case OBJECT_TRIGGER:
- case OBJECT_FOREIGN_TABLE:
- {
- Oid relid;
-
- CheckRelationOwnership(stmt->relation, true);
-
- /*
- * Lock level used here should match what will be taken later,
- * in RenameRelation, renameatt, or renametrig.
- */
- relid = RangeVarGetRelid(stmt->relation, AccessExclusiveLock,
- false);
-
- switch (stmt->renameType)
- {
- case OBJECT_TABLE:
- case OBJECT_SEQUENCE:
- case OBJECT_VIEW:
- case OBJECT_INDEX:
- case OBJECT_FOREIGN_TABLE:
- {
- /*
- * RENAME TABLE requires that we (still) hold
- * CREATE rights on the containing namespace, as
- * well as ownership of the table.
- */
- Oid namespaceId = get_rel_namespace(relid);
- AclResult aclresult;
-
- aclresult = pg_namespace_aclcheck(namespaceId,
- GetUserId(),
- ACL_CREATE);
- if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
- get_namespace_name(namespaceId));
-
- RenameRelation(relid, stmt->newname, stmt->renameType);
- break;
- }
- case OBJECT_COLUMN:
- case OBJECT_ATTRIBUTE:
- renameatt(relid, stmt);
- break;
- case OBJECT_TRIGGER:
- renametrig(relid,
- stmt->subname, /* old att name */
- stmt->newname); /* new att name */
- break;
- default:
- /* can't happen */ ;
- }
- break;
- }
+ renametrig(stmt);
+ break;
case OBJECT_TSPARSER:
RenameTSParser(stmt->object, stmt->newname);