Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: alter ALTER TYPE ... OWNER TO ... for multi-region enum #69722

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/multi_region
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ ALTER TYPE multi_region_test_db.public.crdb_internal_region ADD VALUE 'us-east-1
statement error "multi_region_test_db.public.crdb_internal_region" is a multi-region enum and can't be modified using the alter type command
ALTER TYPE multi_region_test_db.public.crdb_internal_region DROP VALUE 'us-east-1'

statement ok
GRANT ALL ON DATABASE multi_region_test_db TO testuser;
ALTER TYPE multi_region_test_db.public.crdb_internal_region OWNER TO testuser

query T
SELECT owner FROM [SHOW TYPES] WHERE name = 'crdb_internal_region' AND schema = 'public'
----
testuser

statement error region "region_no_exists" does not exist\nHINT:.*valid regions: ap-southeast-2, ca-central-1, us-east-1
CREATE DATABASE invalid_region_db PRIMARY REGION "region_no_exists" REGION "region_no_exists"

Expand Down
16 changes: 9 additions & 7 deletions pkg/sql/alter_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ func (p *planner) AlterType(ctx context.Context, n *tree.AlterType) (planNode, e
tree.AsStringWithFQNames(n.Type, &p.semaCtx.Annotations),
)
case descpb.TypeDescriptor_MULTIREGION_ENUM:
// Multi-region enums can't be directly modified.
return nil, errors.WithHint(
pgerror.Newf(
pgcode.WrongObjectType,
"%q is a multi-region enum and can't be modified using the alter type command",
tree.AsStringWithFQNames(n.Type, &p.semaCtx.Annotations)),
"try adding/removing the region using ALTER DATABASE")
// Multi-region enums can't be directly modified except for OWNER TO.
if _, isAlterTypeOwner := n.Cmd.(*tree.AlterTypeOwner); !isAlterTypeOwner {
return nil, errors.WithHint(
pgerror.Newf(
pgcode.WrongObjectType,
"%q is a multi-region enum and can't be modified using the alter type command",
tree.AsStringWithFQNames(n.Type, &p.semaCtx.Annotations)),
"try adding/removing the region using ALTER DATABASE")
}
case descpb.TypeDescriptor_ENUM:
sqltelemetry.IncrementEnumCounter(sqltelemetry.EnumAlter)
}
Expand Down