summaryrefslogtreecommitdiff
path: root/src/backend/commands/tablespace.c
diff options
context:
space:
mode:
authorAlvaro Herrera2012-10-03 21:02:38 +0000
committerAlvaro Herrera2012-10-03 21:07:46 +0000
commit994c36e01d19dece2b0c76fb781e1d08a6e1c814 (patch)
tree584ad1b7807646382b4d25f0188745f14953ebef /src/backend/commands/tablespace.c
parent1f91c8ca1d2edc66c688ee719eded79ecd0e8f1b (diff)
refactor ALTER some-obj SET OWNER implementation
Remove duplicate implementation of catalog munging and miscellaneous privilege and consistency checks. Instead rely on already existing data in objectaddress.c to do the work. Author: KaiGai Kohei Tweaked by me Reviewed by Robert Haas
Diffstat (limited to 'src/backend/commands/tablespace.c')
-rw-r--r--src/backend/commands/tablespace.c99
1 files changed, 0 insertions, 99 deletions
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index d1718c15138..08899aeecec 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -884,105 +884,6 @@ RenameTableSpace(const char *oldname, const char *newname)
}
/*
- * Change tablespace owner
- */
-void
-AlterTableSpaceOwner(const char *name, Oid newOwnerId)
-{
- Relation rel;
- ScanKeyData entry[1];
- HeapScanDesc scandesc;
- Form_pg_tablespace spcForm;
- HeapTuple tup;
-
- /* Search pg_tablespace */
- rel = heap_open(TableSpaceRelationId, RowExclusiveLock);
-
- ScanKeyInit(&entry[0],
- Anum_pg_tablespace_spcname,
- BTEqualStrategyNumber, F_NAMEEQ,
- CStringGetDatum(name));
- scandesc = heap_beginscan(rel, SnapshotNow, 1, entry);
- tup = heap_getnext(scandesc, ForwardScanDirection);
- if (!HeapTupleIsValid(tup))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("tablespace \"%s\" does not exist", name)));
-
- spcForm = (Form_pg_tablespace) GETSTRUCT(tup);
-
- /*
- * If the new owner is the same as the existing owner, consider the
- * command to have succeeded. This is for dump restoration purposes.
- */
- if (spcForm->spcowner != newOwnerId)
- {
- Datum repl_val[Natts_pg_tablespace];
- bool repl_null[Natts_pg_tablespace];
- bool repl_repl[Natts_pg_tablespace];
- Acl *newAcl;
- Datum aclDatum;
- bool isNull;
- HeapTuple newtuple;
-
- /* Otherwise, must be owner of the existing object */
- if (!pg_tablespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))
- aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TABLESPACE,
- name);
-
- /* Must be able to become new owner */
- check_is_member_of_role(GetUserId(), newOwnerId);
-
- /*
- * Normally we would also check for create permissions here, but there
- * are none for tablespaces so we follow what rename tablespace does
- * and omit the create permissions check.
- *
- * NOTE: Only superusers may create tablespaces to begin with and so
- * initially only a superuser would be able to change its ownership
- * anyway.
- */
-
- memset(repl_null, false, sizeof(repl_null));
- memset(repl_repl, false, sizeof(repl_repl));
-
- repl_repl[Anum_pg_tablespace_spcowner - 1] = true;
- repl_val[Anum_pg_tablespace_spcowner - 1] = ObjectIdGetDatum(newOwnerId);
-
- /*
- * Determine the modified ACL for the new owner. This is only
- * necessary when the ACL is non-null.
- */
- aclDatum = heap_getattr(tup,
- Anum_pg_tablespace_spcacl,
- RelationGetDescr(rel),
- &isNull);
- if (!isNull)
- {
- newAcl = aclnewowner(DatumGetAclP(aclDatum),
- spcForm->spcowner, newOwnerId);
- repl_repl[Anum_pg_tablespace_spcacl - 1] = true;
- repl_val[Anum_pg_tablespace_spcacl - 1] = PointerGetDatum(newAcl);
- }
-
- newtuple = heap_modify_tuple(tup, RelationGetDescr(rel), repl_val, repl_null, repl_repl);
-
- simple_heap_update(rel, &newtuple->t_self, newtuple);
- CatalogUpdateIndexes(rel, newtuple);
-
- heap_freetuple(newtuple);
-
- /* Update owner dependency reference */
- changeDependencyOnOwner(TableSpaceRelationId, HeapTupleGetOid(tup),
- newOwnerId);
- }
-
- heap_endscan(scandesc);
- heap_close(rel, NoLock);
-}
-
-
-/*
* Alter table space options
*/
void