From 37304b7b51fc81e4c4026990d58b1ae619799d0b Mon Sep 17 00:00:00 2001 From: Jason Chan Date: Wed, 15 Jun 2022 07:34:36 -0700 Subject: [PATCH] sql/schemachanger: implement DROP OWNED BY Previously, we did not support the DROP OWNED BY statement (#55381). This commit adds partial support for DROP OWNED BY in the declarative schema changer. Followup work is needed to support the CASCADE modifier. Release note (sql change): Support `DROP OWNED BY`. --- .../testdata/logic_test/drop_owned_by | 318 ++++++++ .../logic_test/schema_change_feature_flags | 4 +- .../schemachanger/scbuild/builder_state.go | 14 + pkg/sql/schemachanger/scbuild/dependencies.go | 3 + .../scbuild/internal/scbuildstmt/BUILD.bazel | 3 + .../internal/scbuildstmt/dependencies.go | 8 + .../internal/scbuildstmt/drop_owned_by.go | 107 +++ .../scbuild/internal/scbuildstmt/process.go | 1 + pkg/sql/schemachanger/scdeps/build_deps.go | 5 + .../scexec/scmutationexec/BUILD.bazel | 1 + .../scexec/scmutationexec/drop.go | 14 + pkg/sql/schemachanger/scop/mutation.go | 7 + .../scop/mutation_visitor_generated.go | 6 + .../internal/opgen/opgen_user_privileges.go | 5 +- .../scplan/testdata/drop_owned_by | 747 ++++++++++++++++++ pkg/sql/testdata/telemetry/drop_owned_by | 2 - 16 files changed, 1240 insertions(+), 5 deletions(-) create mode 100644 pkg/sql/logictest/testdata/logic_test/drop_owned_by create mode 100644 pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_owned_by.go create mode 100644 pkg/sql/schemachanger/scplan/testdata/drop_owned_by diff --git a/pkg/sql/logictest/testdata/logic_test/drop_owned_by b/pkg/sql/logictest/testdata/logic_test/drop_owned_by new file mode 100644 index 000000000000..5c5792c345d1 --- /dev/null +++ b/pkg/sql/logictest/testdata/logic_test/drop_owned_by @@ -0,0 +1,318 @@ +# LogicTest: !local-legacy-schema-changer + +# Test dropping nothing. +statement ok +DROP OWNED BY testuser + +statement ok +CREATE USER testuser2 + +# DROP-OBJECTS: Test that DROP OWNED BY drops objects owned by the specified +# roles. +# +# In this test, testuser creates multiple objects and drops all of them in one +# go. Additionally, testuser2 owns a table that shouldn't be dropped by +# testuser's DROP OWNED BY. +subtest drop-objects + +user testuser2 + +statement ok +CREATE TABLE u() + +user root + +statement ok +GRANT CREATE ON DATABASE test TO testuser WITH GRANT OPTION + +user testuser + +statement ok +CREATE TABLE t(a INT) + +statement ok +CREATE VIEW v AS SELECT 1 + +statement ok +CREATE SEQUENCE seq + +statement ok +CREATE TYPE enum AS ENUM('a', 'b') + +query TTTTIT +SHOW TABLES FROM public +---- +public seq sequence testuser 0 NULL +public t table testuser 0 NULL +public u table testuser2 0 NULL +public v view testuser 0 NULL + +query TTTT +SHOW ENUMS +---- +public enum {a,b} testuser + +statement ok +DROP OWNED BY testuser + +query TTTTIT +SHOW TABLES FROM public +---- +public u table testuser2 0 NULL + +query error pgcode 42P01 relation "t" does not exist +SELECT * FROM t + +query error pgcode 42P01 relation "v" does not exist +SELECT * FROM v + +query TTTT +SHOW ENUMS +---- + +user testuser2 + +statement ok +DROP OWNED BY testuser2 + +query TTTTIT +SHOW TABLES FROM public +---- + +# DROP-BEHAVIOR: Test RESTRICT/CASCADE. +# +# In this test, testuser2 creates a view dependent on a table owned by +# testuser. Under RESTRICT, testuser cannot DROP OWNED BY due to this +# dependency. Under CASCADE, testuser can DROP OWNED BY, which drops both +# testuser's table and testuser2's view. +subtest drop-behavior + +user testuser + +statement ok +CREATE TABLE t(a INT) + +statement ok +GRANT SELECT ON t TO testuser2 WITH GRANT OPTION + +user testuser2 + +statement ok +CREATE VIEW v AS SELECT a FROM t + +user testuser + +statement error pq: cannot drop desired object\(s\) because other objects depend on them +DROP OWNED BY testuser + +statement error pq: cannot drop desired object\(s\) because other objects depend on them +DROP OWNED BY testuser RESTRICT + +query TTTTIT +SHOW TABLES FROM public +---- +public t table testuser 0 NULL +public v view testuser2 0 NULL + +user testuser2 + +# TODO(jasonmchan): Replace the two following DROP OWNED BY statements with a +# single DROP OWNED BY testuser2 CASCADE statement. +statement ok +DROP OWNED BY testuser2 + +user testuser + +statement ok +DROP OWNED BY testuser + +query TTTTIT +SHOW TABLES FROM public +---- + +# DROP-SCHEMA: Test that schemas and the objects that they contain can all be +# dropped together by a single DROP OWNED BY (when they are all owned by the +# specified roles). +subtest drop-schema + +user root + +statement ok +GRANT ALL ON DATABASE test TO testuser WITH GRANT OPTION + +user testuser + +statement ok +CREATE SCHEMA s + +statement ok +CREATE TABLE s.t1() + +statement ok +CREATE TABLE s.t2() + +statement ok +DROP OWNED BY testuser + +statement error pq: target database or schema does not exist +SHOW TABLES FROM s + +user root + +# REVOKE-PRIVILEGES-DB: Test that DROP OWNED BY revokes privileges on the +# current database. +# +# The DROP OWNED BY from the previous subtest did not revoke testuser's +# privileges for the DATABASE. This is because a user should not revoke its own +# database privileges. However, the root user should be able to drop testuser's +# database privileges via DROP OWNED BY. +subtest revoke-privileges-db + +query TTTB +SHOW GRANTS ON DATABASE test +---- +test admin ALL true +test public CONNECT false +test root ALL true +test testuser ALL true + +user root + +statement ok +DROP OWNED BY testuser + +query TTTB +SHOW GRANTS ON DATABASE test +---- +test admin ALL true +test public CONNECT false +test root ALL true + +# REVOKE-PRIVILEGES-SCHEMA: Test that DROP OWNED BY revokes privileges on +# schemas in the current database. +# +# In this test, root creates a schema and grants privileges for the schema to +# testuser. When testuser issues a DROP OWNED BY, those privileges should be +# revoked. +subtest revoke-privileges-schema + +user root + +statement ok +CREATE SCHEMA s + +statement ok +GRANT CREATE ON SCHEMA s TO testuser WITH GRANT OPTION + +user testuser + +statement ok +CREATE TABLE s.t() + +statement ok +DROP OWNED BY testuser + +query TTTTB +SHOW GRANTS ON SCHEMA s +---- +test s admin ALL true +test s root ALL true + +query TTTTIT +SHOW TABLES FROM s +---- + +user root + +statement ok +DROP SCHEMA s + +# REVOKE-PRIVILEGES-TABLE: Test that DROP OWNED BY revokes privileges on +# objects in the database. +subtest revoke-privileges-table + +user root + +statement ok +CREATE TABLE t() + +statement ok +GRANT ALL ON t TO testuser WITH GRANT OPTION + +user testuser + +query TTTTTB +SHOW GRANTS ON t +---- +test public t admin ALL true +test public t root ALL true +test public t testuser ALL true + +statement ok +DROP OWNED BY testuser + +query TTTTTB +SHOW GRANTS ON t +---- +test public t admin ALL true +test public t root ALL true + +user root + +statement ok +DROP TABLE t + +# MUTIROLE: Test DROP OWNED BY with multiple roles. +subtest multirole + +statement ok +CREATE ROLE r1 + +statement ok +CREATE ROLE r2 + +statement ok +SET ROLE r1 + +statement ok +CREATE TABLE t1() + +statement ok +SET ROLE r2 + +statement ok +CREATE TABLE t2() + +statement ok +SET ROLE root + +query TTTTIT +SHOW TABLES FROM public +---- +public t1 table r1 0 NULL +public t2 table r2 0 NULL + +statement ok +DROP OWNED BY r1, r2 + +query TTTTIT +SHOW TABLES FROM public +---- + +# ROLES: Test that the current user is a member of all the specified roles. The +# admin role and the root user are off-limits. +subtest roles + +user testuser + +statement error pq: permission denied to drop objects +DROP OWNED BY testuser2 + +statement error pq: permission denied to drop objects +DROP OWNED BY testuser, testuser2 + +statement error pq: cannot drop objects owned by role "root" because they are required by the database system +DROP OWNED BY root + +statement error pq: cannot drop objects owned by role "admin" because they are required by the database system +DROP OWNED BY admin diff --git a/pkg/sql/logictest/testdata/logic_test/schema_change_feature_flags b/pkg/sql/logictest/testdata/logic_test/schema_change_feature_flags index 852921f89f13..03a470c2234d 100644 --- a/pkg/sql/logictest/testdata/logic_test/schema_change_feature_flags +++ b/pkg/sql/logictest/testdata/logic_test/schema_change_feature_flags @@ -246,8 +246,8 @@ ALTER SEQUENCE seq NO CYCLE statement error pq: feature REASSIGN OWNED BY is part of the schema change category, which was disabled by the database administrator REASSIGN OWNED BY root TO testuser -# Test DROP OWNED BY. -statement error pq: feature DROP OWNED BY is part of the schema change category, which was disabled by the database administrator +# Test DROP OWNED. +statement error pq: feature DROP OWNED is part of the schema change category, which was disabled by the database administrator DROP OWNED BY testuser # Test DROP DATABASE. diff --git a/pkg/sql/schemachanger/scbuild/builder_state.go b/pkg/sql/schemachanger/scbuild/builder_state.go index ad0d1dcbef80..e567f18fa8c7 100644 --- a/pkg/sql/schemachanger/scbuild/builder_state.go +++ b/pkg/sql/schemachanger/scbuild/builder_state.go @@ -14,6 +14,7 @@ import ( "strings" "github.com/cockroachdb/cockroach/pkg/keys" + "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" @@ -155,6 +156,19 @@ func (b *builderState) checkPrivilege(id catid.DescID, priv privilege.Kind) { } } +// IsMemberOf implements the scbuildstmt.PrivilegeChecker interface. +func (b *builderState) IsMemberOf(role username.SQLUsername) bool { + if b.hasAdmin { + return true + } + memberships, err := b.auth.MemberOfWithAdminOption(b.ctx, role) + if err != nil { + panic(err) + } + _, ok := memberships[b.evalCtx.SessionData().User()] + return ok +} + var _ scbuildstmt.TableHelpers = (*builderState)(nil) // NextTableColumnID implements the scbuildstmt.TableHelpers interface. diff --git a/pkg/sql/schemachanger/scbuild/dependencies.go b/pkg/sql/schemachanger/scbuild/dependencies.go index 9bc31e766593..3b5949af71b2 100644 --- a/pkg/sql/schemachanger/scbuild/dependencies.go +++ b/pkg/sql/schemachanger/scbuild/dependencies.go @@ -167,6 +167,9 @@ type AuthorizationAccessor interface { CheckPrivilegeForUser( ctx context.Context, descriptor catalog.Descriptor, privilege privilege.Kind, user username.SQLUsername, ) error + + // MemberOfWithAdminOption looks up the roles that 'member' is a member of. + MemberOfWithAdminOption(ctx context.Context, member username.SQLUsername) (map[username.SQLUsername]bool, error) } // AstFormatter provides interfaces for formatting AST nodes. diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel index 397dca826e5a..1c6e2e1f1cc4 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel @@ -9,6 +9,7 @@ go_library( "create_index.go", "dependencies.go", "drop_database.go", + "drop_owned_by.go", "drop_schema.go", "drop_sequence.go", "drop_table.go", @@ -20,6 +21,7 @@ go_library( importpath = "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scbuild/internal/scbuildstmt", visibility = ["//pkg/sql/schemachanger/scbuild:__subpackages__"], deps = [ + "//pkg/security/username", "//pkg/server/telemetry", "//pkg/settings/cluster", "//pkg/sql/catalog", @@ -29,6 +31,7 @@ go_library( "//pkg/sql/catalog/schemaexpr", "//pkg/sql/catalog/tabledesc", "//pkg/sql/catalog/typedesc", + "//pkg/sql/decodeusername", "//pkg/sql/parser", "//pkg/sql/pgwire/pgcode", "//pkg/sql/pgwire/pgerror", diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/dependencies.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/dependencies.go index e4f136168f8a..308724b6812b 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/dependencies.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/dependencies.go @@ -13,6 +13,7 @@ package scbuildstmt import ( "context" + "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/privilege" @@ -148,6 +149,9 @@ type Telemetry interface { // IncrementEnumCounter increments the selected enum telemetry counter. IncrementEnumCounter(counterType sqltelemetry.EnumTelemetryType) + + // IncrementDropOwnedByCounter increments the DROP OWNED BY telemetry counter. + IncrementDropOwnedByCounter() } // SchemaFeatureChecker checks if a schema change feature is allowed by the @@ -167,6 +171,10 @@ type PrivilegeChecker interface { // CheckPrivilege panics if the current user does not have the specified // privilege for the element. CheckPrivilege(e scpb.Element, privilege privilege.Kind) + + // CheckMemberOf returns true iff the current user has membership in the + // specified role. + IsMemberOf(member username.SQLUsername) bool } // TableHelpers has methods useful for creating new table elements. diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_owned_by.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_owned_by.go new file mode 100644 index 000000000000..b11f391c2edc --- /dev/null +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_owned_by.go @@ -0,0 +1,107 @@ +// Copyright 2022 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package scbuildstmt + +import ( + "github.com/cockroachdb/cockroach/pkg/security/username" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" + "github.com/cockroachdb/cockroach/pkg/sql/decodeusername" + "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" + "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" + "github.com/cockroachdb/cockroach/pkg/sql/privilege" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" + "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" +) + +// DropOwnedBy implements DROP OWNED BY. +func DropOwnedBy(b BuildCtx, n *tree.DropOwnedBy) { + normalizedRoles, err := decodeusername.FromRoleSpecList( + b.SessionData(), username.PurposeValidation, n.Roles, + ) + if err != nil { + panic(err) + } + for _, role := range normalizedRoles { + if role.IsAdminRole() || role.IsRootUser() || role.IsNodeUser() { + panic(pgerror.Newf(pgcode.DependentObjectsStillExist, + "cannot drop objects owned by role %q because they are required by the database system", role)) + } + if role != b.SessionData().User() && !b.IsMemberOf(role) { + panic(pgerror.New(pgcode.InsufficientPrivilege, "permission denied to drop objects")) + } + } + + var objects []descpb.ID + var toCheckBackrefs []descpb.ID + + // Lookup all objects in the current database. + _, _, db := scpb.FindDatabase(b.ResolveDatabase(tree.Name(b.SessionData().Database), ResolveParams{ + IsExistenceOptional: false, + RequiredPrivilege: privilege.CONNECT, + })) + dbRefs := undroppedBackrefs(b, db.DatabaseID) + scpb.ForEachSchemaParent(dbRefs, func(_ scpb.Status, _ scpb.TargetStatus, sp *scpb.SchemaParent) { + schemaRefs := undroppedBackrefs(b, sp.SchemaID) + scpb.ForEachObjectParent(schemaRefs, func(_ scpb.Status, _ scpb.TargetStatus, op *scpb.ObjectParent) { + objects = append(objects, op.ObjectID) + }) + objects = append(objects, sp.SchemaID) + }) + + // Drop owned objects and revoke user privileges for the specified roles. + for _, id := range objects { + elts := b.QueryByID(id) + _, _, owner := scpb.FindOwner(elts) + for _, role := range normalizedRoles { + if owner.Owner == role.Normalized() { + if n.DropBehavior == tree.DropCascade { + // TODO(jasonmchan): implement for #55908 + panic(scerrors.NotImplementedError(n)) + } else { + if dropRestrictDescriptor(b, id) { + toCheckBackrefs = append(toCheckBackrefs, id) + } + } + break + } + scpb.ForEachUserPrivileges(elts, func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.UserPrivileges) { + if e.UserName == role.Normalized() { + b.Drop(e) + } + }) + } + } + + // Revoke privileges for the database. The current user shouldn't revoke + // their own database privileges. + dbElts := b.QueryByID(db.DatabaseID) + scpb.ForEachUserPrivileges(dbElts, func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.UserPrivileges) { + for _, role := range normalizedRoles { + if e.UserName == role.Normalized() && e.UserName != b.SessionData().User().Normalized() { + b.Drop(e) + break + } + } + }) + + b.IncrementSubWorkID() + b.IncrementDropOwnedByCounter() + + // Enforce RESTRICT semantics by checking for backreferences. + for _, id := range toCheckBackrefs { + backrefs := undroppedBackrefs(b, id) + if !backrefs.IsEmpty() { + panic(pgerror.New(pgcode.DependentObjectsStillExist, + "cannot drop desired object(s) because other objects depend on them")) + } + } +} diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go index 196410ebd1d6..5ca420776a44 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go @@ -49,6 +49,7 @@ var supportedStatements = map[reflect.Type]supportedStatement{ reflect.TypeOf((*tree.AlterTable)(nil)): {AlterTable, true}, reflect.TypeOf((*tree.CreateIndex)(nil)): {CreateIndex, false}, reflect.TypeOf((*tree.DropDatabase)(nil)): {DropDatabase, true}, + reflect.TypeOf((*tree.DropOwnedBy)(nil)): {DropOwnedBy, true}, reflect.TypeOf((*tree.DropSchema)(nil)): {DropSchema, true}, reflect.TypeOf((*tree.DropSequence)(nil)): {DropSequence, true}, reflect.TypeOf((*tree.DropTable)(nil)): {DropTable, true}, diff --git a/pkg/sql/schemachanger/scdeps/build_deps.go b/pkg/sql/schemachanger/scdeps/build_deps.go index a885f0347b0e..aec9ebf7f62e 100644 --- a/pkg/sql/schemachanger/scdeps/build_deps.go +++ b/pkg/sql/schemachanger/scdeps/build_deps.go @@ -375,6 +375,11 @@ func (d *buildDeps) IncrementEnumCounter(counterType sqltelemetry.EnumTelemetryT sqltelemetry.IncrementEnumCounter(counterType) } +// IncrementDropOwnedByCounter implements the scbuild.Dependencies interface. +func (d *buildDeps) IncrementDropOwnedByCounter() { + telemetry.Inc(sqltelemetry.CreateDropOwnedByCounter()) +} + func (d *buildDeps) DescriptorCommentCache() scbuild.CommentCache { return descmetadata.NewCommentCache(d.txn, d.internalExecutor) } diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel b/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel index 6ab4547ef1ca..09c68b278532 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel +++ b/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel @@ -20,6 +20,7 @@ go_library( deps = [ "//pkg/jobs/jobspb", "//pkg/keys", + "//pkg/security/username", "//pkg/sql/catalog", "//pkg/sql/catalog/dbdesc", "//pkg/sql/catalog/descpb", diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/drop.go b/pkg/sql/schemachanger/scexec/scmutationexec/drop.go index 4156c24c4c59..053959a33d17 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/drop.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/drop.go @@ -14,6 +14,7 @@ import ( "context" "github.com/cockroachdb/cockroach/pkg/keys" + "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" @@ -132,6 +133,19 @@ func (m *visitor) RemoveDatabaseRoleSettings( return m.s.DeleteDatabaseRoleSettings(ctx, op.DatabaseID) } +func (m *visitor) RemoveUserPrivileges(ctx context.Context, op scop.RemoveUserPrivileges) error { + desc, err := m.s.CheckOutDescriptor(ctx, op.DescID) + if err != nil { + return err + } + user, err := username.MakeSQLUsernameFromUserInput(op.User, username.PurposeValidation) + if err != nil { + return err + } + desc.GetPrivileges().RemoveUser(user) + return nil +} + func (m *visitor) DeleteSchedule(_ context.Context, op scop.DeleteSchedule) error { if op.ScheduleID != 0 { m.s.DeleteSchedule(op.ScheduleID) diff --git a/pkg/sql/schemachanger/scop/mutation.go b/pkg/sql/schemachanger/scop/mutation.go index fb416aa30beb..e237c88727b9 100644 --- a/pkg/sql/schemachanger/scop/mutation.go +++ b/pkg/sql/schemachanger/scop/mutation.go @@ -530,6 +530,13 @@ type RemoveDatabaseRoleSettings struct { DatabaseID descpb.ID } +// RemoveUserPrivileges is used to revoke a user's privileges. +type RemoveUserPrivileges struct { + mutationOp + DescID descpb.ID + User string +} + // DeleteSchedule is used to delete a schedule ID from the database. type DeleteSchedule struct { mutationOp diff --git a/pkg/sql/schemachanger/scop/mutation_visitor_generated.go b/pkg/sql/schemachanger/scop/mutation_visitor_generated.go index 15b5f0a40f98..dfbc0a70e6b5 100644 --- a/pkg/sql/schemachanger/scop/mutation_visitor_generated.go +++ b/pkg/sql/schemachanger/scop/mutation_visitor_generated.go @@ -86,6 +86,7 @@ type MutationVisitor interface { UpsertConstraintComment(context.Context, UpsertConstraintComment) error RemoveConstraintComment(context.Context, RemoveConstraintComment) error RemoveDatabaseRoleSettings(context.Context, RemoveDatabaseRoleSettings) error + RemoveUserPrivileges(context.Context, RemoveUserPrivileges) error DeleteSchedule(context.Context, DeleteSchedule) error RefreshStats(context.Context, RefreshStats) error } @@ -410,6 +411,11 @@ func (op RemoveDatabaseRoleSettings) Visit(ctx context.Context, v MutationVisito return v.RemoveDatabaseRoleSettings(ctx, op) } +// Visit is part of the MutationOp interface. +func (op RemoveUserPrivileges) Visit(ctx context.Context, v MutationVisitor) error { + return v.RemoveUserPrivileges(ctx, op) +} + // Visit is part of the MutationOp interface. func (op DeleteSchedule) Visit(ctx context.Context, v MutationVisitor) error { return v.DeleteSchedule(ctx, op) diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_user_privileges.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_user_privileges.go index f71f7ea9429c..d4e6f16d21fb 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_user_privileges.go +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_user_privileges.go @@ -31,7 +31,10 @@ func init() { // TODO(postamar): remove revertibility constraint when possible revertible(false), emit(func(this *scpb.UserPrivileges) scop.Op { - return notImplemented(this) + return scop.RemoveUserPrivileges{ + DescID: this.DescriptorID, + User: this.UserName, + } }), ), ), diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_owned_by b/pkg/sql/schemachanger/scplan/testdata/drop_owned_by new file mode 100644 index 000000000000..0750cbb9d068 --- /dev/null +++ b/pkg/sql/schemachanger/scplan/testdata/drop_owned_by @@ -0,0 +1,747 @@ +setup +CREATE ROLE r; +CREATE TABLE tab(); +GRANT ALL ON tab TO r; +GRANT CREATE ON DATABASE defaultdb TO r WITH GRANT OPTION; +SET ROLE r; +CREATE SCHEMA s; +CREATE SEQUENCE public.sq; +CREATE SEQUENCE s.sq; +CREATE TABLE s.t (id INT PRIMARY KEY, name VARCHAR(256), val INT DEFAULT nextval('s.sq')); +CREATE TABLE public.t (id INT PRIMARY KEY, name VARCHAR(256), val INT DEFAULT nextval('public.sq')); +CREATE VIEW s.v1 AS (SELECT name FROM s.t); +CREATE TYPE s.typ AS ENUM('a'); +CREATE VIEW s.v2 AS (SELECT 'a'::s.typ::string AS k, name FROM s.v1); +---- + +ops +DROP OWNED BY r +---- +StatementPhase stage 1 of 1 with 34 MutationType ops + transitions: + [[UserPrivileges:{DescID: 100, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[Namespace:{DescID: 105, Name: s, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[Owner:{DescID: 105}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 105, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 105, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 105, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[Schema:{DescID: 105}, ABSENT], PUBLIC] -> DROPPED + [[SchemaParent:{DescID: 105, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 104, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[Namespace:{DescID: 106, Name: sq, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[Owner:{DescID: 106}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 106, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 106, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 106, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[Sequence:{DescID: 106}, ABSENT], PUBLIC] -> DROPPED + [[ObjectParent:{DescID: 106, ReferencedDescID: 101}, ABSENT], PUBLIC] -> ABSENT + [[Namespace:{DescID: 109, Name: t, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[Owner:{DescID: 109}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 109, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 109, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 109, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[Table:{DescID: 109}, ABSENT], PUBLIC] -> DROPPED + [[ObjectParent:{DescID: 109, ReferencedDescID: 101}, ABSENT], PUBLIC] -> ABSENT + [[ColumnFamily:{DescID: 109, ColumnFamilyID: 0, Name: primary}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 109, ColumnID: 1}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 109, Name: id, ColumnID: 1}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 109, ColumnFamilyID: 0, ColumnID: 1}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 109, ColumnID: 2}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 109, Name: name, ColumnID: 2}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 109, ColumnFamilyID: 0, ColumnID: 2}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 109, ColumnID: 3}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 109, Name: val, ColumnID: 3}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 109, ColumnFamilyID: 0, ColumnID: 3}, ABSENT], PUBLIC] -> ABSENT + [[ColumnDefaultExpression:{DescID: 109, ColumnID: 3}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 109, ColumnID: 4294967295}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 109, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 109, ColumnFamilyID: 0, ColumnID: 4294967295}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 109, ColumnID: 4294967294}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 109, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 109, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED + [[IndexName:{DescID: 109, Name: t_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[Namespace:{DescID: 107, Name: sq, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[Owner:{DescID: 107}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 107, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 107, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 107, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[Sequence:{DescID: 107}, ABSENT], PUBLIC] -> DROPPED + [[ObjectParent:{DescID: 107, ReferencedDescID: 105}, ABSENT], PUBLIC] -> ABSENT + [[Namespace:{DescID: 108, Name: t, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[Owner:{DescID: 108}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 108, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 108, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 108, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[Table:{DescID: 108}, ABSENT], PUBLIC] -> DROPPED + [[ObjectParent:{DescID: 108, ReferencedDescID: 105}, ABSENT], PUBLIC] -> ABSENT + [[ColumnFamily:{DescID: 108, ColumnFamilyID: 0, Name: primary}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 108, ColumnID: 1}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 108, Name: id, ColumnID: 1}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 1}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 108, ColumnID: 2}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 108, Name: name, ColumnID: 2}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 2}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 108, ColumnID: 3}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 108, Name: val, ColumnID: 3}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 3}, ABSENT], PUBLIC] -> ABSENT + [[ColumnDefaultExpression:{DescID: 108, ColumnID: 3}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 108, ColumnID: 4294967295}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 108, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967295}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 108, ColumnID: 4294967294}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 108, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED + [[IndexName:{DescID: 108, Name: t_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[Namespace:{DescID: 110, Name: v1, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[Owner:{DescID: 110}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 110, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 110, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 110, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[View:{DescID: 110}, ABSENT], PUBLIC] -> DROPPED + [[ObjectParent:{DescID: 110, ReferencedDescID: 105}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 110, ColumnID: 1}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 110, Name: name, ColumnID: 1}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 110, ColumnFamilyID: 0, ColumnID: 1}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 110, ColumnID: 4294967295}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 110, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 110, ColumnFamilyID: 0, ColumnID: 4294967295}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 110, ColumnID: 4294967294}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 110, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 110, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[Namespace:{DescID: 111, Name: typ, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[Owner:{DescID: 111}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 111, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 111, Name: public}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 111, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 111, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[EnumType:{DescID: 111}, ABSENT], PUBLIC] -> DROPPED + [[ObjectParent:{DescID: 111, ReferencedDescID: 105}, ABSENT], PUBLIC] -> ABSENT + [[Namespace:{DescID: 112, Name: _typ, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[Owner:{DescID: 112}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 112, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 112, Name: public}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 112, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 112, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[AliasType:{DescID: 112}, ABSENT], PUBLIC] -> DROPPED + [[ObjectParent:{DescID: 112, ReferencedDescID: 105}, ABSENT], PUBLIC] -> ABSENT + [[Namespace:{DescID: 113, Name: v2, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[Owner:{DescID: 113}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 113, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 113, Name: r}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 113, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[View:{DescID: 113}, ABSENT], PUBLIC] -> DROPPED + [[ObjectParent:{DescID: 113, ReferencedDescID: 105}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 113, ColumnID: 1}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 113, Name: k, ColumnID: 1}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 113, ColumnFamilyID: 0, ColumnID: 1}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 113, ColumnID: 2}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 113, Name: name, ColumnID: 2}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 113, ColumnFamilyID: 0, ColumnID: 2}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 113, ColumnID: 4294967295}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 113, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 113, ColumnFamilyID: 0, ColumnID: 4294967295}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 113, ColumnID: 4294967294}, ABSENT], PUBLIC] -> WRITE_ONLY + [[ColumnName:{DescID: 113, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 113, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + ops: + scop.RemoveUserPrivileges + DescID: 100 + User: r + scop.RemoveUserPrivileges + DescID: 104 + User: r + *scop.MarkDescriptorAsDropped + DescID: 105 + *scop.RemoveSchemaParent + Parent: + ParentDatabaseID: 100 + SchemaID: 105 + *scop.MarkDescriptorAsDropped + DescID: 106 + *scop.RemoveAllTableComments + TableID: 106 + *scop.MarkDescriptorAsDropped + DescID: 109 + *scop.RemoveAllTableComments + TableID: 109 + *scop.RemoveColumnDefaultExpression + ColumnID: 3 + TableID: 109 + *scop.UpdateBackReferencesInSequences + BackReferencedColumnID: 3 + BackReferencedTableID: 109 + SequenceIDs: + - 106 + *scop.MarkDescriptorAsDropped + DescID: 107 + *scop.RemoveAllTableComments + TableID: 107 + *scop.MarkDescriptorAsDropped + DescID: 108 + *scop.RemoveAllTableComments + TableID: 108 + *scop.RemoveColumnDefaultExpression + ColumnID: 3 + TableID: 108 + *scop.UpdateBackReferencesInSequences + BackReferencedColumnID: 3 + BackReferencedTableID: 108 + SequenceIDs: + - 107 + *scop.MarkDescriptorAsDropped + DescID: 110 + *scop.RemoveViewBackReferencesInRelations + BackReferencedViewID: 110 + RelationIDs: + - 108 + *scop.RemoveAllTableComments + TableID: 110 + *scop.MarkDescriptorAsDropped + DescID: 111 + *scop.MarkDescriptorAsDropped + DescID: 112 + *scop.MarkDescriptorAsDropped + DescID: 113 + *scop.RemoveBackReferenceInTypes + BackReferencedDescID: 113 + TypeIDs: + - 111 + - 112 + *scop.RemoveViewBackReferencesInRelations + BackReferencedViewID: 113 + RelationIDs: + - 110 + *scop.RemoveAllTableComments + TableID: 113 + *scop.DrainDescriptorName + Namespace: + DatabaseID: 100 + DescriptorID: 105 + Name: s + *scop.DrainDescriptorName + Namespace: + DatabaseID: 100 + DescriptorID: 106 + Name: sq + SchemaID: 101 + *scop.DrainDescriptorName + Namespace: + DatabaseID: 100 + DescriptorID: 109 + Name: t + SchemaID: 101 + *scop.DrainDescriptorName + Namespace: + DatabaseID: 100 + DescriptorID: 107 + Name: sq + SchemaID: 105 + *scop.DrainDescriptorName + Namespace: + DatabaseID: 100 + DescriptorID: 108 + Name: t + SchemaID: 105 + *scop.DrainDescriptorName + Namespace: + DatabaseID: 100 + DescriptorID: 110 + Name: v1 + SchemaID: 105 + *scop.DrainDescriptorName + Namespace: + DatabaseID: 100 + DescriptorID: 111 + Name: typ + SchemaID: 105 + *scop.DrainDescriptorName + Namespace: + DatabaseID: 100 + DescriptorID: 112 + Name: _typ + SchemaID: 105 + *scop.DrainDescriptorName + Namespace: + DatabaseID: 100 + DescriptorID: 113 + Name: v2 + SchemaID: 105 +PreCommitPhase stage 1 of 1 with 12 MutationType ops + transitions: + ops: + *scop.SetJobStateOnDescriptor + DescriptorID: 100 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 104 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 105 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 106 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 107 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 108 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 109 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 110 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 111 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 112 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 113 + Initialize: true + *scop.CreateSchemaChangerJob + Authorization: + UserName: root + DescriptorIDs: + - 100 + - 104 + - 105 + - 106 + - 107 + - 108 + - 109 + - 110 + - 111 + - 112 + - 113 + JobID: 1 + NonCancelable: true + RunningStatus: PostCommitNonRevertiblePhase stage 1 of 1 with 35 MutationType ops + pending + Statements: + - statement: DROP OWNED BY r + redactedstatement: DROP OWNED BY r + statementtag: DROP OWNED BY +PostCommitNonRevertiblePhase stage 1 of 1 with 47 MutationType ops + transitions: + [[Schema:{DescID: 105}, ABSENT], DROPPED] -> ABSENT + [[Sequence:{DescID: 106}, ABSENT], DROPPED] -> ABSENT + [[Table:{DescID: 109}, ABSENT], DROPPED] -> ABSENT + [[Column:{DescID: 109, ColumnID: 1}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 109, ColumnID: 2}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 109, ColumnID: 3}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 109, ColumnID: 4294967295}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 109, ColumnID: 4294967294}, ABSENT], WRITE_ONLY] -> ABSENT + [[PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT], VALIDATED] -> ABSENT + [[Sequence:{DescID: 107}, ABSENT], DROPPED] -> ABSENT + [[Table:{DescID: 108}, ABSENT], DROPPED] -> ABSENT + [[Column:{DescID: 108, ColumnID: 1}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 108, ColumnID: 2}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 108, ColumnID: 3}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 108, ColumnID: 4294967295}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 108, ColumnID: 4294967294}, ABSENT], WRITE_ONLY] -> ABSENT + [[PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}, ABSENT], VALIDATED] -> ABSENT + [[View:{DescID: 110}, ABSENT], DROPPED] -> ABSENT + [[Column:{DescID: 110, ColumnID: 1}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 110, ColumnID: 4294967295}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 110, ColumnID: 4294967294}, ABSENT], WRITE_ONLY] -> ABSENT + [[EnumType:{DescID: 111}, ABSENT], DROPPED] -> ABSENT + [[AliasType:{DescID: 112}, ABSENT], DROPPED] -> ABSENT + [[View:{DescID: 113}, ABSENT], DROPPED] -> ABSENT + [[Column:{DescID: 113, ColumnID: 1}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 113, ColumnID: 2}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 113, ColumnID: 4294967295}, ABSENT], WRITE_ONLY] -> ABSENT + [[Column:{DescID: 113, ColumnID: 4294967294}, ABSENT], WRITE_ONLY] -> ABSENT + ops: + *scop.LogEvent + Element: + Schema: + schemaId: 105 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.DeleteDescriptor + DescriptorID: 105 + *scop.LogEvent + Element: + Sequence: + sequenceId: 106 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.CreateGcJobForTable + StatementForDropJob: + Statement: DROP OWNED BY r + TableID: 106 + *scop.LogEvent + Element: + Sequence: + sequenceId: 107 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.CreateGcJobForTable + StatementForDropJob: + Statement: DROP OWNED BY r + TableID: 107 + *scop.LogEvent + Element: + EnumType: + arrayTypeId: 112 + typeId: 111 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.DeleteDescriptor + DescriptorID: 111 + *scop.LogEvent + Element: + AliasType: + embeddedTypeT: + closedTypeIds: + - 111 + - 112 + type: + arrayContents: + family: EnumFamily + oid: 100111 + udtMetadata: + arrayTypeOid: 100112 + arrayElemType: EnumFamily + family: ArrayFamily + oid: 100112 + typeId: 112 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.DeleteDescriptor + DescriptorID: 112 + *scop.LogEvent + Element: + View: + usesRelationIds: + - 108 + viewId: 110 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.DeleteDescriptor + DescriptorID: 110 + *scop.MakeColumnAbsent + ColumnID: 1 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 110 + *scop.MakeColumnAbsent + ColumnID: 4294967295 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 110 + *scop.MakeColumnAbsent + ColumnID: 4294967294 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 110 + *scop.LogEvent + Element: + View: + usesRelationIds: + - 110 + usesTypeIds: + - 111 + - 112 + viewId: 113 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.DeleteDescriptor + DescriptorID: 113 + *scop.MakeColumnAbsent + ColumnID: 1 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 113 + *scop.MakeColumnAbsent + ColumnID: 2 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 113 + *scop.MakeColumnAbsent + ColumnID: 4294967295 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 113 + *scop.MakeColumnAbsent + ColumnID: 4294967294 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 113 + *scop.LogEvent + Element: + Table: + tableId: 109 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.CreateGcJobForTable + StatementForDropJob: + Statement: DROP OWNED BY r + TableID: 109 + *scop.MakeColumnAbsent + ColumnID: 1 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 109 + *scop.MakeColumnAbsent + ColumnID: 2 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 109 + *scop.MakeColumnAbsent + ColumnID: 3 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 109 + *scop.MakeColumnAbsent + ColumnID: 4294967295 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 109 + *scop.MakeColumnAbsent + ColumnID: 4294967294 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 109 + *scop.LogEvent + Element: + Table: + tableId: 108 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.CreateGcJobForTable + StatementForDropJob: + Statement: DROP OWNED BY r + TableID: 108 + *scop.MakeColumnAbsent + ColumnID: 1 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 108 + *scop.MakeColumnAbsent + ColumnID: 2 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 108 + *scop.MakeColumnAbsent + ColumnID: 3 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 108 + *scop.MakeColumnAbsent + ColumnID: 4294967295 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 108 + *scop.MakeColumnAbsent + ColumnID: 4294967294 + EventBase: + Authorization: + UserName: root + Statement: DROP OWNED BY r + StatementTag: DROP OWNED BY + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TableID: 108 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 100 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 104 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 105 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 106 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 107 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 108 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 109 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 110 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 111 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 112 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 113 + JobID: 1 + *scop.UpdateSchemaChangerJob + IsNonCancelable: true + JobID: 1 diff --git a/pkg/sql/testdata/telemetry/drop_owned_by b/pkg/sql/testdata/telemetry/drop_owned_by index 1da9d9586212..bddbb209f7f8 100644 --- a/pkg/sql/testdata/telemetry/drop_owned_by +++ b/pkg/sql/testdata/telemetry/drop_owned_by @@ -11,9 +11,7 @@ GRANT CREATE ON DATABASE defaultdb TO testuser; ALTER TABLE t OWNER TO testuser ---- -# TODO(angelaw): Remove unimplemented message after implementation. feature-usage DROP OWNED BY testuser ---- -error: pq: unimplemented: drop owned by is not yet implemented sql.drop_owned_by