From 7bdc32f4fcc6f05718416ba02956d65151b56efa Mon Sep 17 00:00:00 2001 From: Kuien Liu Date: Wed, 29 Nov 2017 19:08:27 +0800 Subject: [PATCH] HAWQ-1556. enable ALTER SCHEMA RENAME/OWNER --- src/backend/commands/alter.c | 8 ------ src/test/feature/catalog/ans/alter-owner.ans | 28 +++++++++++++++++--- src/test/feature/catalog/sql/alter-owner.sql | 17 +++++++++--- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index 040e82f304..b3f3b87b11 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -106,11 +106,6 @@ ExecRenameStmt(RenameStmt *stmt) break; case OBJECT_SCHEMA: - if (!gp_called_by_pgdump) - { - ereport(ERROR, - (errcode(ERRCODE_CDB_FEATURE_NOT_YET), errmsg("Cannot support rename schema statement yet") )); - } RenameSchema(stmt->subname, stmt->newname); break; @@ -304,9 +299,6 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt) break; case OBJECT_SCHEMA: - if (!gp_called_by_pgdump) - ereport(ERROR, - (errcode(ERRCODE_CDB_FEATURE_NOT_YET), errmsg("Cannot support alter schema owner statement yet") )); AlterSchemaOwner(strVal(linitial(stmt->object)), newowner); break; diff --git a/src/test/feature/catalog/ans/alter-owner.ans b/src/test/feature/catalog/ans/alter-owner.ans index 9d2eeafd8e..81d03698e7 100644 --- a/src/test/feature/catalog/ans/alter-owner.ans +++ b/src/test/feature/catalog/ans/alter-owner.ans @@ -34,14 +34,36 @@ select alter database u1 owner to u1; psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:24: ERROR: Cannot support alter database owner statement yet alter schema u1 owner to u1; -psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:25: ERROR: Cannot support alter schema owner statement yet -reset session authorization; +ALTER SCHEMA +alter schema u1 rename to u2; +ALTER SCHEMA +-- test permission +create role u2; +psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:29: NOTICE: resource queue required -- using default resource queue "pg_default" +CREATE ROLE +ALTER SCHEMA pg_toast OWNER to u2; -- system schema +psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:30: ERROR: permission denied to ALTER SCHEMA "pg_toast" +DETAIL: Schema pg_toast is reserved for system use. +GRANT ALL ON SCHEMA u2 to u2; +GRANT +RESET SESSION AUTHORIZATION; +RESET +SET SESSION AUTHORIZATION u2; +SET +CREATE TABLE u2.grant_test(a int) DISTRIBUTED BY (a); +CREATE TABLE +ALTER SCHEMA u2 RENAME to myschema; -- not the schema owner +psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:35: ERROR: must be owner of schema u2 +RESET SESSION AUTHORIZATION; RESET drop database u1; DROP DATABASE -drop schema u1; +drop schema u2 CASCADE; +psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:39: NOTICE: drop cascades to append only table u2.grant_test DROP SCHEMA drop role u1; DROP ROLE +drop role u2; +DROP ROLE drop role super; DROP ROLE diff --git a/src/test/feature/catalog/sql/alter-owner.sql b/src/test/feature/catalog/sql/alter-owner.sql index a6e7b77ae9..a908b09be6 100644 --- a/src/test/feature/catalog/sql/alter-owner.sql +++ b/src/test/feature/catalog/sql/alter-owner.sql @@ -20,9 +20,20 @@ select alter database u1 owner to u1; alter schema u1 owner to u1; +alter schema u1 rename to u2; -reset session authorization; +-- test permission +create role u2; +ALTER SCHEMA pg_toast OWNER to u2; -- system schema +GRANT ALL ON SCHEMA u2 to u2; +RESET SESSION AUTHORIZATION; +SET SESSION AUTHORIZATION u2; +CREATE TABLE u2.grant_test(a int) DISTRIBUTED BY (a); +ALTER SCHEMA u2 RENAME to myschema; -- not the schema owner + +RESET SESSION AUTHORIZATION; drop database u1; -drop schema u1; +drop schema u2 CASCADE; drop role u1; -drop role super; \ No newline at end of file +drop role u2; +drop role super;