diff --git a/pkg/ccl/schemachangerccl/backup_base_generated_test.go b/pkg/ccl/schemachangerccl/backup_base_generated_test.go index 231251c7d088..128b8172fd88 100644 --- a/pkg/ccl/schemachangerccl/backup_base_generated_test.go +++ b/pkg/ccl/schemachangerccl/backup_base_generated_test.go @@ -108,6 +108,11 @@ func TestBackupbase_drop_index_vanilla_index(t *testing.T) { defer log.Scope(t).Close(t) sctest.Backup(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_index_vanilla_index", newCluster) } +func TestBackupbase_drop_index_with_materialized_view_dep(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.Backup(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep", newCluster) +} func TestBackupbase_drop_multiple_columns_separate_statements(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) diff --git a/pkg/sql/logictest/testdata/logic_test/alter_table b/pkg/sql/logictest/testdata/logic_test/alter_table index 8e49ad8db426..c40eb0ce7da5 100644 --- a/pkg/sql/logictest/testdata/logic_test/alter_table +++ b/pkg/sql/logictest/testdata/logic_test/alter_table @@ -217,6 +217,7 @@ ALTER TABLE t DROP CONSTRAINT foo statement ok DROP INDEX foo CASCADE +onlyif config local-legacy-schema-changer query TTTTRT retry SELECT job_type, description, user_name, status, fraction_completed, error FROM crdb_internal.jobs @@ -227,6 +228,21 @@ LIMIT 2 SCHEMA CHANGE GC GC for DROP INDEX test.public.t@foo CASCADE root running 0 · SCHEMA CHANGE DROP INDEX test.public.t@foo CASCADE root succeeded 1 · + +skipif config local-legacy-schema-changer +skipif config local-mixed-22.2-23.1 +query TTTTRT retry +SELECT job_type, description, user_name, status, fraction_completed, error +FROM crdb_internal.jobs +WHERE job_type = 'NEW SCHEMA CHANGE' OR job_type = 'SCHEMA CHANGE GC' +ORDER BY created DESC +LIMIT 2 +---- +SCHEMA CHANGE GC GC for DROP INDEX test.public.t@foo CASCADE node running 0 · +NEW SCHEMA CHANGE DROP INDEX test.public.t@foo CASCADE root succeeded 1 · + + + query TTBITTBBB colnames SHOW INDEXES FROM t ---- @@ -302,6 +318,7 @@ INSERT INTO t (a, d, x, y, z) VALUES (33, 34, DECIMAL '2.0', DECIMAL '2.1', DECI statement ok DROP INDEX t@t_f_idx +onlyif config local-legacy-schema-changer query TTTTRT retry SELECT job_type, description, user_name, status, fraction_completed, error FROM crdb_internal.jobs @@ -312,6 +329,20 @@ LIMIT 2 SCHEMA CHANGE GC GC for DROP INDEX test.public.t@t_f_idx root running 0 · SCHEMA CHANGE DROP INDEX test.public.t@t_f_idx root succeeded 1 · +skipif config local-legacy-schema-changer +skipif config local-mixed-22.2-23.1 +query TTTTRT retry +SELECT job_type, description, user_name, status, fraction_completed, error +FROM crdb_internal.jobs +WHERE job_type = 'NEW SCHEMA CHANGE' OR job_type = 'SCHEMA CHANGE GC' +ORDER BY created DESC +LIMIT 2 +---- +SCHEMA CHANGE GC GC for DROP INDEX test.public.t@t_f_idx node running 0 · +NEW SCHEMA CHANGE DROP INDEX test.public.t@t_f_idx root succeeded 1 · + + + statement ok ALTER TABLE t DROP COLUMN f @@ -2073,6 +2104,7 @@ statement ok ALTER TABLE t ADD CONSTRAINT t_pkey PRIMARY KEY (id) skipif config local-legacy-schema-changer +skipif config local-mixed-22.2-23.1 query TT SHOW CREATE TABLE t ---- diff --git a/pkg/sql/logictest/testdata/logic_test/create_index b/pkg/sql/logictest/testdata/logic_test/create_index index fc4e1de7cd90..f9987f3c44a8 100644 --- a/pkg/sql/logictest/testdata/logic_test/create_index +++ b/pkg/sql/logictest/testdata/logic_test/create_index @@ -193,8 +193,6 @@ query T noticetrace DROP INDEX CONCURRENTLY IF EXISTS create_index_concurrently_idx ---- NOTICE: CONCURRENTLY is not required as all indexes are dropped concurrently -NOTICE: the data for dropped indexes is reclaimed asynchronously -HINT: The reclamation delay can be customized in the zone configuration for the table. query TT SHOW CREATE TABLE create_index_concurrently_tbl diff --git a/pkg/sql/logictest/testdata/logic_test/drop_index b/pkg/sql/logictest/testdata/logic_test/drop_index index 40e70377620f..13a1a2697fe8 100644 --- a/pkg/sql/logictest/testdata/logic_test/drop_index +++ b/pkg/sql/logictest/testdata/logic_test/drop_index @@ -101,6 +101,12 @@ users users_pkey false 3 title N/A true user testuser +skipif config local-legacy-schema-changer +skipif config local-mixed-22.2-23.1 +statement error must be owner of table users or have CREATE privilege on table users +DROP INDEX users@bar + +onlyif config local-legacy-schema-changer statement error user testuser does not have CREATE privilege on relation users DROP INDEX users@bar diff --git a/pkg/sql/logictest/testdata/logic_test/new_schema_changer b/pkg/sql/logictest/testdata/logic_test/new_schema_changer index ac0c6d78c72f..edb6da80ac6b 100644 --- a/pkg/sql/logictest/testdata/logic_test/new_schema_changer +++ b/pkg/sql/logictest/testdata/logic_test/new_schema_changer @@ -1393,7 +1393,7 @@ CREATE VIEW child AS SELECT count(*) FROM parent@idx statement ok SET use_declarative_schema_changer = 'unsafe' -statement error pgcode 2BP01 cannot drop index "parent@idx" because view "child" depends on it +statement error pgcode 2BP01 cannot drop index "idx" because view "child" depends on it DROP INDEX parent@idx statement ok diff --git a/pkg/sql/logictest/testdata/logic_test/privileges_comments b/pkg/sql/logictest/testdata/logic_test/privileges_comments index a180a1a685d5..14b45a1591c4 100644 --- a/pkg/sql/logictest/testdata/logic_test/privileges_comments +++ b/pkg/sql/logictest/testdata/logic_test/privileges_comments @@ -39,9 +39,14 @@ skipif config local-legacy-schema-changer statement error must be owner of table t45707 or have CREATE privilege on table t45707 COMMENT ON COLUMN d45707.t45707.x IS 'x45707' +onlyif config local-legacy-schema-changer statement error user testuser does not have CREATE privilege on relation t45707 COMMENT ON INDEX d45707.t45707@t45707_pkey IS 'p45707' +skipif config local-legacy-schema-changer +statement error must be owner of table t45707 or have CREATE privilege on table t45707 +COMMENT ON INDEX d45707.t45707@t45707_pkey IS 'p45707' + # Verify that the user can view the comments query T diff --git a/pkg/sql/opt/exec/execbuilder/testdata/show_trace b/pkg/sql/opt/exec/execbuilder/testdata/show_trace index 3038182dc800..e7a781eb76f6 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/show_trace +++ b/pkg/sql/opt/exec/execbuilder/testdata/show_trace @@ -197,10 +197,9 @@ SET tracing = off query TT $trace_query ---- -drop index Del /Table/24/1/3/108/2/0 -drop index Del /Table/24/1/3/108/2/4/1 -drop index CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 not_visible:false > state:WRITE_ONLY direction:DROP mutation_id:2 rollback:false > next_mutation_id:3 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > -sql query rows affected: 0 +schema change CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 not_visible:false > state:WRITE_ONLY direction:DROP mutation_id:2 rollback:false > next_mutation_id:2 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > +sql query rows affected: 0 +commit sql txn CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 not_visible:false > state:WRITE_ONLY direction:DROP mutation_id:2 rollback:false > next_mutation_id:2 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:PUBLIC current_statuses:PUBLIC target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 relevant_statements: > authorization: > drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > statement ok SET tracing = on,kv,results; DROP TABLE t.kv @@ -212,7 +211,7 @@ query TT $trace_query ---- sql query rows affected: 0 -commit sql txn CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:PUBLIC current_statuses:PUBLIC target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 target_ranks:24 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > +commit sql txn CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:2 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:PUBLIC current_statuses:PUBLIC target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 target_ranks:24 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > commit sql txn Del /NamespaceTable/30/1/106/107/"kv"/4/1 commit sql txn DelRange /Table/24/1/1/108 commit sql txn DelRange /Table/24/1/2/108 diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go index da677ed72dfb..b827562694ce 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go @@ -25,26 +25,13 @@ import ( "github.com/cockroachdb/errors" ) -// TODO (xiang): To enable full support for DROP INDEX, we still need to +// TODO (xiang): To remove fallbacks for DROP INDEX we still need to: // 1. Model adding and dropping FK constraints correctly // for dropping an index with dependent FK constraint; -// 2. Fix the "revertibility bug" in the planner as it currently -// seems to ignore non-revertible operations and plan -// them to happen in a much early phase (say, stmt phase); -// 2.a. Once the above two are done, add a test where -// we drop an index with a dependent FK constraint and a -// dependent view to end-to-end test, scbuild test, scplan test. -// 2.b. Answer the question "Are there any CCL required `DROP INDEX` usage?" -// If yes, add a end-to-end test in `pkg/ccl/schemachangerccl`. +// 2. Once the above two are done, add a test where +// we drop an index with a dependent FK constraint and a +// dependent view to end-to-end test, scbuild test, scplan test. // 3. Check if requires CCL binary for eventual zone config removal. -// 4. Make all existing unit tests and logic tests pass using this -// new `DROP INDEX` implementation. This will likely involve -// rewriting expected output since there are the legacy and declarative -// schema changer exhibits minor behavior difference. Ideally, we -// should modify the tests in a way such that if we turn off the -// declarative schema changer for `DROP INDEX`, the legacy schema -// changer's `DROP INDEX` will be able to pass all the tests as well. -// 5. Set `DROP INDEX` to be fully-supported in `process.go`. // DropIndex implements DROP INDEX. // It resolves the to-be-dropped index into elements and inform `BuildCtx` diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go index 4154f72effac..a99164a142a2 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go @@ -102,8 +102,7 @@ var supportedStatements = map[reflect.Type]supportedStatement{ reflect.TypeOf((*tree.CommentOnColumn)(nil)): {fn: CommentOnColumn, on: true, minSupportedClusterVersion: clusterversion.V22_2Start}, reflect.TypeOf((*tree.CommentOnIndex)(nil)): {fn: CommentOnIndex, on: true, minSupportedClusterVersion: clusterversion.V22_2Start}, reflect.TypeOf((*tree.CommentOnConstraint)(nil)): {fn: CommentOnConstraint, on: true, minSupportedClusterVersion: clusterversion.V22_2Start}, - // TODO (Xiang): turn on `DROP INDEX` as fully supported. - reflect.TypeOf((*tree.DropIndex)(nil)): {fn: DropIndex, on: false, minSupportedClusterVersion: clusterversion.V22_2Start}, + reflect.TypeOf((*tree.DropIndex)(nil)): {fn: DropIndex, on: true, minSupportedClusterVersion: clusterversion.V23_1Start}, } func init() { diff --git a/pkg/sql/schemachanger/scbuild/testdata/drop_index b/pkg/sql/schemachanger/scbuild/testdata/drop_index index 0446c5645e2d..73dfe68a200a 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/drop_index +++ b/pkg/sql/schemachanger/scbuild/testdata/drop_index @@ -8,6 +8,10 @@ CREATE TABLE t1(i INT, j STRING); CREATE INDEX idx1 ON t1(i); CREATE INDEX idx2 ON t1(lower(j)) WHERE i > 0; CREATE INDEX idx3 ON t1(i) USING HASH; +CREATE VIEW v AS SELECT count(j) FROM t1@idx3; +CREATE MATERIALIZED VIEW v2 AS SELECT i, j FROM t1; +CREATE INDEX idx ON v2(j); +CREATE MATERIALIZED VIEW v3 AS SELECT j FROM v2@idx ---- build @@ -71,3 +75,99 @@ DROP INDEX idx3 CASCADE {columnIds: [5], constraintId: 2, expr: 'crdb_internal_i_shard_16 IN (0:::INT8, 1:::INT8, 2:::INT8, 3:::INT8, 4:::INT8, 5:::INT8, 6:::INT8, 7:::INT8, 8:::INT8, 9:::INT8, 10:::INT8, 11:::INT8, 12:::INT8, 13:::INT8, 14:::INT8, 15:::INT8)', fromHashShardedColumn: true, referencedColumnIds: [5], tableId: 104} - [[ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_i_shard_16, ConstraintID: 2}, ABSENT], PUBLIC] {constraintId: 2, name: check_crdb_internal_i_shard_16, tableId: 104} +- [[Namespace:{DescID: 105, Name: v, ReferencedDescID: 100}, ABSENT], PUBLIC] + {databaseId: 100, descriptorId: 105, name: v, schemaId: 101} +- [[Owner:{DescID: 105}, ABSENT], PUBLIC] + {descriptorId: 105, owner: root} +- [[UserPrivileges:{DescID: 105, Name: admin}, ABSENT], PUBLIC] + {descriptorId: 105, privileges: 2, userName: admin} +- [[UserPrivileges:{DescID: 105, Name: root}, ABSENT], PUBLIC] + {descriptorId: 105, privileges: 2, userName: root} +- [[View:{DescID: 105}, ABSENT], PUBLIC] + {forwardReferences: [{columnIds: [2], indexId: 6, toId: 104}], usesRelationIds: [104], viewId: 105} +- [[ObjectParent:{DescID: 105, ReferencedDescID: 101}, ABSENT], PUBLIC] + {objectId: 105, parentSchemaId: 101} +- [[Column:{DescID: 105, ColumnID: 1}, ABSENT], PUBLIC] + {columnId: 1, pgAttributeNum: 1, tableId: 105} +- [[ColumnName:{DescID: 105, Name: count, ColumnID: 1}, ABSENT], PUBLIC] + {columnId: 1, name: count, tableId: 105} +- [[ColumnType:{DescID: 105, ColumnFamilyID: 0, ColumnID: 1}, ABSENT], PUBLIC] + {columnId: 1, isNullable: true, tableId: 105, type: {family: IntFamily, oid: 20, width: 64}} +- [[Column:{DescID: 105, ColumnID: 4294967295}, ABSENT], PUBLIC] + {columnId: 4.294967295e+09, isHidden: true, isSystemColumn: true, pgAttributeNum: 4.294967295e+09, tableId: 105} +- [[ColumnName:{DescID: 105, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}, ABSENT], PUBLIC] + {columnId: 4.294967295e+09, name: crdb_internal_mvcc_timestamp, tableId: 105} +- [[ColumnType:{DescID: 105, ColumnFamilyID: 0, ColumnID: 4294967295}, ABSENT], PUBLIC] + {columnId: 4.294967295e+09, isNullable: true, tableId: 105, type: {family: DecimalFamily, oid: 1700}} +- [[Column:{DescID: 105, ColumnID: 4294967294}, ABSENT], PUBLIC] + {columnId: 4.294967294e+09, isHidden: true, isSystemColumn: true, pgAttributeNum: 4.294967294e+09, tableId: 105} +- [[ColumnName:{DescID: 105, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] + {columnId: 4.294967294e+09, name: tableoid, tableId: 105} +- [[ColumnType:{DescID: 105, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] + {columnId: 4.294967294e+09, isNullable: true, tableId: 105, type: {family: OidFamily, oid: 26}} + +build +DROP INDEX v2@idx CASCADE +---- +- [[IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 2}, ABSENT], PUBLIC] + {columnId: 2, indexId: 2, tableId: 106} +- [[IndexColumn:{DescID: 106, ColumnID: 3, IndexID: 2}, ABSENT], PUBLIC] + {columnId: 3, indexId: 2, kind: KEY_SUFFIX, tableId: 106} +- [[SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0}, ABSENT], PUBLIC] + {indexId: 2, isCreatedExplicitly: true, tableId: 106} +- [[IndexName:{DescID: 106, Name: idx, IndexID: 2}, ABSENT], PUBLIC] + {indexId: 2, name: idx, tableId: 106} +- [[IndexData:{DescID: 106, IndexID: 2}, ABSENT], PUBLIC] + {indexId: 2, tableId: 106} +- [[Namespace:{DescID: 107, Name: v3, ReferencedDescID: 100}, ABSENT], PUBLIC] + {databaseId: 100, descriptorId: 107, name: v3, schemaId: 101} +- [[Owner:{DescID: 107}, ABSENT], PUBLIC] + {descriptorId: 107, owner: root} +- [[UserPrivileges:{DescID: 107, Name: admin}, ABSENT], PUBLIC] + {descriptorId: 107, privileges: 2, userName: admin} +- [[UserPrivileges:{DescID: 107, Name: root}, ABSENT], PUBLIC] + {descriptorId: 107, privileges: 2, userName: root} +- [[View:{DescID: 107}, ABSENT], PUBLIC] + {forwardReferences: [{columnIds: [2], indexId: 2, toId: 106}], isMaterialized: true, usesRelationIds: [106], viewId: 107} +- [[ObjectParent:{DescID: 107, ReferencedDescID: 101}, ABSENT], PUBLIC] + {objectId: 107, parentSchemaId: 101} +- [[ColumnFamily:{DescID: 107, Name: primary, ColumnFamilyID: 0}, ABSENT], PUBLIC] + {name: primary, tableId: 107} +- [[Column:{DescID: 107, ColumnID: 1}, ABSENT], PUBLIC] + {columnId: 1, pgAttributeNum: 1, tableId: 107} +- [[ColumnName:{DescID: 107, Name: j, ColumnID: 1}, ABSENT], PUBLIC] + {columnId: 1, name: j, tableId: 107} +- [[ColumnType:{DescID: 107, ColumnFamilyID: 0, ColumnID: 1}, ABSENT], PUBLIC] + {columnId: 1, isNullable: true, tableId: 107, type: {family: StringFamily, oid: 25}} +- [[Column:{DescID: 107, ColumnID: 2}, ABSENT], PUBLIC] + {columnId: 2, isHidden: true, pgAttributeNum: 2, tableId: 107} +- [[ColumnName:{DescID: 107, Name: rowid, ColumnID: 2}, ABSENT], PUBLIC] + {columnId: 2, name: rowid, tableId: 107} +- [[ColumnType:{DescID: 107, ColumnFamilyID: 0, ColumnID: 2}, ABSENT], PUBLIC] + {columnId: 2, tableId: 107, type: {family: IntFamily, oid: 20, width: 64}} +- [[ColumnDefaultExpression:{DescID: 107, ColumnID: 2}, ABSENT], PUBLIC] + {columnId: 2, expr: unique_rowid(), tableId: 107} +- [[Column:{DescID: 107, ColumnID: 4294967295}, ABSENT], PUBLIC] + {columnId: 4.294967295e+09, isHidden: true, isSystemColumn: true, pgAttributeNum: 4.294967295e+09, tableId: 107} +- [[ColumnName:{DescID: 107, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}, ABSENT], PUBLIC] + {columnId: 4.294967295e+09, name: crdb_internal_mvcc_timestamp, tableId: 107} +- [[ColumnType:{DescID: 107, ColumnFamilyID: 0, ColumnID: 4294967295}, ABSENT], PUBLIC] + {columnId: 4.294967295e+09, isNullable: true, tableId: 107, type: {family: DecimalFamily, oid: 1700}} +- [[Column:{DescID: 107, ColumnID: 4294967294}, ABSENT], PUBLIC] + {columnId: 4.294967294e+09, isHidden: true, isSystemColumn: true, pgAttributeNum: 4.294967294e+09, tableId: 107} +- [[ColumnName:{DescID: 107, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] + {columnId: 4.294967294e+09, name: tableoid, tableId: 107} +- [[ColumnType:{DescID: 107, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] + {columnId: 4.294967294e+09, isNullable: true, tableId: 107, type: {family: OidFamily, oid: 26}} +- [[IndexColumn:{DescID: 107, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 2, indexId: 1, tableId: 107} +- [[IndexColumn:{DescID: 107, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 1, indexId: 1, kind: STORED, tableId: 107} +- [[PrimaryIndex:{DescID: 107, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] + {constraintId: 1, indexId: 1, isUnique: true, tableId: 107} +- [[IndexName:{DescID: 107, Name: v3_pkey, IndexID: 1}, ABSENT], PUBLIC] + {indexId: 1, name: v3_pkey, tableId: 107} +- [[IndexData:{DescID: 107, IndexID: 1}, ABSENT], PUBLIC] + {indexId: 1, tableId: 107} +- [[TableData:{DescID: 107, ReferencedDescID: 100}, ABSENT], PUBLIC] + {databaseId: 100, tableId: 107} diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_index b/pkg/sql/schemachanger/scplan/testdata/drop_index index 07b9b08ca7c7..103159f6029d 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_index +++ b/pkg/sql/schemachanger/scplan/testdata/drop_index @@ -9,7 +9,10 @@ CREATE INDEX idx1 ON t1(i); CREATE INDEX idx2 ON t1(lower(j)) WHERE i > 0; CREATE INDEX idx3 ON t1(i) USING HASH; CREATE UNIQUE INDEX idx4 ON t1(j); -CREATE VIEW v AS SELECT count(j) FROM t1@idx4 +CREATE VIEW v AS SELECT count(j) FROM t1@idx4; +CREATE MATERIALIZED VIEW v2 AS SELECT i, j FROM t1; +CREATE INDEX idx ON v2(j); +CREATE MATERIALIZED VIEW v3 AS SELECT j FROM v2@idx ---- ops @@ -978,3 +981,220 @@ DROP INDEX idx4 CASCADE to: [View:{DescID: 105}, DROPPED] kind: PreviousStagePrecedence rule: descriptor TXN_DROPPED before DROPPED + +ops +DROP INDEX v2@idx CASCADE; +---- +StatementPhase stage 1 of 1 with 1 MutationType op + transitions: + [[View:{DescID: 107}, ABSENT], PUBLIC] -> TXN_DROPPED + [[Column:{DescID: 107, ColumnID: 1}, ABSENT], PUBLIC] -> WRITE_ONLY + [[Column:{DescID: 107, ColumnID: 2}, ABSENT], PUBLIC] -> WRITE_ONLY + [[Column:{DescID: 107, ColumnID: 4294967295}, ABSENT], PUBLIC] -> WRITE_ONLY + [[Column:{DescID: 107, ColumnID: 4294967294}, ABSENT], PUBLIC] -> WRITE_ONLY + [[PrimaryIndex:{DescID: 107, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED + ops: + *scop.MarkDescriptorAsSyntheticallyDropped + DescriptorID: 107 +PreCommitPhase stage 1 of 1 with 13 MutationType ops + transitions: + [[IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 106, ColumnID: 3, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT + [[SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0}, ABSENT], PUBLIC] -> VALIDATED + [[Namespace:{DescID: 107, Name: v3, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + [[Owner:{DescID: 107}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 107, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 107, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[View:{DescID: 107}, ABSENT], TXN_DROPPED] -> DROPPED + [[ObjectParent:{DescID: 107, ReferencedDescID: 101}, ABSENT], PUBLIC] -> ABSENT + [[ColumnFamily:{DescID: 107, Name: primary, ColumnFamilyID: 0}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 107, ColumnID: 1}, ABSENT], WRITE_ONLY] -> ABSENT + [[ColumnName:{DescID: 107, Name: j, ColumnID: 1}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 107, ColumnFamilyID: 0, ColumnID: 1}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 107, ColumnID: 2}, ABSENT], WRITE_ONLY] -> ABSENT + [[ColumnName:{DescID: 107, Name: rowid, ColumnID: 2}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 107, ColumnFamilyID: 0, ColumnID: 2}, ABSENT], PUBLIC] -> ABSENT + [[ColumnDefaultExpression:{DescID: 107, ColumnID: 2}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 107, ColumnID: 4294967295}, ABSENT], WRITE_ONLY] -> ABSENT + [[ColumnName:{DescID: 107, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 107, ColumnFamilyID: 0, ColumnID: 4294967295}, ABSENT], PUBLIC] -> ABSENT + [[Column:{DescID: 107, ColumnID: 4294967294}, ABSENT], WRITE_ONLY] -> ABSENT + [[ColumnName:{DescID: 107, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[ColumnType:{DescID: 107, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 107, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 107, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[PrimaryIndex:{DescID: 107, IndexID: 1, ConstraintID: 1}, ABSENT], VALIDATED] -> ABSENT + [[IndexName:{DescID: 107, Name: v3_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + ops: + *scop.MarkDescriptorAsDropped + DescriptorID: 107 + *scop.RemoveViewBackReferencesInRelations + BackReferencedViewID: 107 + RelationIDs: + - 106 + *scop.RemoveAllTableComments + TableID: 107 + *scop.RemoveColumnDefaultExpression + ColumnID: 2 + TableID: 107 + *scop.MakePublicSecondaryIndexWriteOnly + IndexID: 2 + TableID: 106 + *scop.DrainDescriptorName + Namespace: + DatabaseID: 100 + DescriptorID: 107 + Name: v3 + SchemaID: 101 + *scop.MakeDeleteOnlyColumnAbsent + ColumnID: 1 + EventBase: + Authorization: + UserName: root + Statement: DROP INDEX ‹defaultdb›.public.‹v2›@‹idx› CASCADE + StatementTag: DROP INDEX + TargetMetadata: + SourceElementID: 2 + SubWorkID: 1 + TableID: 107 + *scop.MakeDeleteOnlyColumnAbsent + ColumnID: 4294967295 + EventBase: + Authorization: + UserName: root + Statement: DROP INDEX ‹defaultdb›.public.‹v2›@‹idx› CASCADE + StatementTag: DROP INDEX + TargetMetadata: + SourceElementID: 2 + SubWorkID: 1 + TableID: 107 + *scop.MakeDeleteOnlyColumnAbsent + ColumnID: 4294967294 + EventBase: + Authorization: + UserName: root + Statement: DROP INDEX ‹defaultdb›.public.‹v2›@‹idx› CASCADE + StatementTag: DROP INDEX + TargetMetadata: + SourceElementID: 2 + SubWorkID: 1 + TableID: 107 + *scop.MakeDeleteOnlyColumnAbsent + ColumnID: 2 + EventBase: + Authorization: + UserName: root + Statement: DROP INDEX ‹defaultdb›.public.‹v2›@‹idx› CASCADE + StatementTag: DROP INDEX + TargetMetadata: + SourceElementID: 2 + SubWorkID: 1 + TableID: 107 + *scop.SetJobStateOnDescriptor + DescriptorID: 106 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 107 + Initialize: true + *scop.CreateSchemaChangerJob + Authorization: + UserName: root + DescriptorIDs: + - 106 + - 107 + JobID: 1 + NonCancelable: true + RunningStatus: PostCommitNonRevertiblePhase stage 1 of 2 with 6 MutationType ops pending + Statements: + - statement: DROP INDEX v2@idx CASCADE + redactedstatement: DROP INDEX ‹defaultdb›.public.‹v2›@‹idx› CASCADE + statementtag: DROP INDEX +PostCommitNonRevertiblePhase stage 1 of 2 with 8 MutationType ops + transitions: + [[SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0}, ABSENT], VALIDATED] -> DELETE_ONLY + [[IndexName:{DescID: 106, Name: idx, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT + [[View:{DescID: 107}, ABSENT], DROPPED] -> ABSENT + [[IndexData:{DescID: 107, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[TableData:{DescID: 107, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT + ops: + *scop.LogEvent + Element: + View: + forwardReferences: + - columnIds: + - 2 + indexId: 2 + toId: 106 + isMaterialized: true + usesRelationIds: + - 106 + viewId: 107 + EventBase: + Authorization: + UserName: root + Statement: DROP INDEX ‹defaultdb›.public.‹v2›@‹idx› CASCADE + StatementTag: DROP INDEX + TargetMetadata: + SourceElementID: 2 + SubWorkID: 1 + TargetStatus: 1 + *scop.CreateGCJobForTable + DatabaseID: 100 + StatementForDropJob: + Statement: DROP INDEX defaultdb.public.v2@idx CASCADE + TableID: 107 + *scop.LogEvent + Element: + SecondaryIndex: + indexId: 2 + isCreatedExplicitly: true + tableId: 106 + EventBase: + Authorization: + UserName: root + Statement: DROP INDEX ‹defaultdb›.public.‹v2›@‹idx› CASCADE + StatementTag: DROP INDEX + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.MakeWriteOnlyIndexDeleteOnly + IndexID: 2 + TableID: 106 + *scop.SetIndexName + IndexID: 2 + Name: crdb_internal_index_2_name_placeholder + TableID: 106 + *scop.CreateGCJobForIndex + IndexID: 1 + StatementForDropJob: + Statement: DROP INDEX defaultdb.public.v2@idx CASCADE + TableID: 107 + *scop.SetJobStateOnDescriptor + DescriptorID: 106 + *scop.UpdateSchemaChangerJob + DescriptorIDsToRemove: + - 107 + IsNonCancelable: true + JobID: 1 +PostCommitNonRevertiblePhase stage 2 of 2 with 4 MutationType ops + transitions: + [[SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0}, ABSENT], DELETE_ONLY] -> ABSENT + [[IndexData:{DescID: 106, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT + ops: + *scop.MakeIndexAbsent + IndexID: 2 + TableID: 106 + *scop.CreateGCJobForIndex + IndexID: 2 + StatementForDropJob: + Statement: DROP INDEX defaultdb.public.v2@idx CASCADE + TableID: 106 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 106 + JobID: 1 + *scop.UpdateSchemaChangerJob + DescriptorIDsToRemove: + - 106 + IsNonCancelable: true + JobID: 1 diff --git a/pkg/sql/schemachanger/sctest_generated_test.go b/pkg/sql/schemachanger/sctest_generated_test.go index 11cf7db166ad..f096688e360e 100644 --- a/pkg/sql/schemachanger/sctest_generated_test.go +++ b/pkg/sql/schemachanger/sctest_generated_test.go @@ -470,6 +470,31 @@ func TestRollback_drop_index_vanilla_index(t *testing.T) { defer log.Scope(t).Close(t) sctest.Rollback(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_index_vanilla_index", sctest.SingleNodeCluster) } +func TestEndToEndSideEffects_drop_index_with_materialized_view_dep(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.EndToEndSideEffects(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep", sctest.SingleNodeCluster) +} +func TestExecuteWithDMLInjection_drop_index_with_materialized_view_dep(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.ExecuteWithDMLInjection(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep", sctest.SingleNodeCluster) +} +func TestGenerateSchemaChangeCorpus_drop_index_with_materialized_view_dep(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.GenerateSchemaChangeCorpus(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep", sctest.SingleNodeCluster) +} +func TestPause_drop_index_with_materialized_view_dep(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.Pause(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep", sctest.SingleNodeCluster) +} +func TestRollback_drop_index_with_materialized_view_dep(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.Rollback(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep", sctest.SingleNodeCluster) +} func TestEndToEndSideEffects_drop_multiple_columns_separate_statements(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep b/pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep new file mode 100644 index 000000000000..67396345908e --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep @@ -0,0 +1,264 @@ +setup +CREATE TABLE t1(i INT PRIMARY KEY, j INT); +CREATE MATERIALIZED VIEW v2 AS SELECT i, j FROM t1; +CREATE INDEX idx ON v2(j); +CREATE MATERIALIZED VIEW v3 AS SELECT j FROM v2@idx +---- +... ++object {100 101 t1} -> 104 ++object {100 101 v2} -> 105 ++object {100 101 v3} -> 106 + +stage-exec phase=PostCommitNonRevertiblePhase stage=: +INSERT INTO t1 (i, j) VALUES($stageKey, $stageKey); +INSERT INTO t1 (i, j) VALUES($stageKey + 1, $stageKey + 1); +---- + +stage-exec phase=PostCommitNonRevertiblePhase stage=: +DELETE FROM t1 WHERE j=$stageKey+1; +INSERT INTO t1 (i, j) VALUES($stageKey + 1, $stageKey + 1); +---- + +# Each insert will be injected twice per stage, so we should always, +# see a count of 2. +stage-query phase=PostCommitNonRevertiblePhase stage=: +SELECT count(*)=$successfulStageCount*2 FROM t1; +---- +true + +test +DROP INDEX idx CASCADE +---- +begin transaction #1 +# begin StatementPhase +checking for feature: DROP INDEX +increment telemetry for sql.schema.drop_index +## StatementPhase stage 1 of 1 with 1 MutationType op +add synthetic descriptor #106: + ... + id: 106 + isMaterializedView: true + - modificationTime: {} + + modificationTime: + + wallTime: "1640995200000000001" + name: v3 + nextColumnId: 3 + ... + replacementOf: + time: {} + + state: DROP + unexposedParentSchemaId: 101 + version: "2" + ... +# end StatementPhase +# begin PreCommitPhase +## PreCommitPhase stage 1 of 1 with 13 MutationType ops +delete all comments for table descriptor 106 +delete object namespace entry {100 101 v3} -> 106 +upsert descriptor #105 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - dependedOnBy: + - - columnIds: + - - 2 + - id: 106 + - indexId: 2 + + declarativeSchemaChangerState: + + authorization: + + userName: root + + currentStatuses: + + jobId: "1" + + relevantStatements: + + - statement: + + redactedStatement: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE + + statement: DROP INDEX idx CASCADE + + statementTag: DROP INDEX + + targetRanks: + + targets: + dependsOn: + - 104 + ... + formatVersion: 3 + id: 105 + - indexes: + - - createdAtNanos: "1640995200000000000" + - createdExplicitly: true + - foreignKey: {} + - geoConfig: {} + - id: 2 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 2 + - keyColumnNames: + - - j + - keySuffixColumnIds: + - - 3 + - name: idx + - partitioning: {} + - sharded: {} + - version: 4 + + indexes: [] + isMaterializedView: true + modificationTime: {} + + mutations: + + - direction: DROP + + index: + + createdAtNanos: "1640995200000000000" + + createdExplicitly: true + + foreignKey: {} + + geoConfig: {} + + id: 2 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 2 + + keyColumnNames: + + - j + + keySuffixColumnIds: + + - 3 + + name: idx + + partitioning: {} + + sharded: {} + + version: 4 + + mutationId: 1 + + state: WRITE_ONLY + name: v2 + nextColumnId: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "10" + + version: "11" + viewQuery: SELECT i, j FROM defaultdb.public.t1 +upsert descriptor #106 + ... + createAsOfTime: + wallTime: "1640995200000000000" + + declarativeSchemaChangerState: + + authorization: + + userName: root + + currentStatuses: + + jobId: "1" + + relevantStatements: + + - statement: + + redactedStatement: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE + + statement: DROP INDEX idx CASCADE + + statementTag: DROP INDEX + + targetRanks: + + targets: + dependsOn: + - 105 + ... + replacementOf: + time: {} + + state: DROP + unexposedParentSchemaId: 101 + - version: "2" + + version: "3" + viewQuery: SELECT j FROM defaultdb.public.v2@idx +create job #1 (non-cancelable: true): "DROP INDEX defaultdb.public.v2@idx CASCADE" + descriptor IDs: [105 106] +# end PreCommitPhase +commit transaction #1 +notified job registry to adopt jobs: [1] +# begin PostCommitPhase +begin transaction #2 +commit transaction #2 +begin transaction #3 +## PostCommitNonRevertiblePhase stage 1 of 2 with 8 MutationType ops +upsert descriptor #105 + ... + keySuffixColumnIds: + - 3 + - name: idx + + name: crdb_internal_index_2_name_placeholder + partitioning: {} + sharded: {} + version: 4 + mutationId: 1 + - state: WRITE_ONLY + + state: DELETE_ONLY + name: v2 + nextColumnId: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "11" + + version: "12" + viewQuery: SELECT i, j FROM defaultdb.public.t1 +write *eventpb.DropIndex to event log: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE +create job #2 (non-cancelable: true): "GC for DROP INDEX defaultdb.public.v2@idx CASCADE" + descriptor IDs: [106] +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 2 with 2 MutationType ops pending" +set schema change job #1 to non-cancellable +updated schema change job #1 descriptor IDs to [105] +commit transaction #3 +notified job registry to adopt jobs: [2] +begin transaction #4 +## PostCommitNonRevertiblePhase stage 2 of 2 with 4 MutationType ops +upsert descriptor #105 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - currentStatuses: + - jobId: "1" + - relevantStatements: + - - statement: + - redactedStatement: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE + - statement: DROP INDEX idx CASCADE + - statementTag: DROP INDEX + - targetRanks: + - targets: + dependsOn: + - 104 + ... + isMaterializedView: true + modificationTime: {} + - mutations: + - - direction: DROP + - index: + - createdAtNanos: "1640995200000000000" + - createdExplicitly: true + - foreignKey: {} + - geoConfig: {} + - id: 2 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 2 + - keyColumnNames: + - - j + - keySuffixColumnIds: + - - 3 + - name: crdb_internal_index_2_name_placeholder + - partitioning: {} + - sharded: {} + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + + mutations: [] + name: v2 + nextColumnId: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "12" + + version: "13" + viewQuery: SELECT i, j FROM defaultdb.public.t1 +write *eventpb.FinishSchemaChange to event log +create job #3 (non-cancelable: true): "GC for DROP INDEX defaultdb.public.v2@idx CASCADE" + descriptor IDs: [105] +update progress of schema change job #1: "all stages completed" +set schema change job #1 to non-cancellable +updated schema change job #1 descriptor IDs to [106] +commit transaction #4 +notified job registry to adopt jobs: [3] +# end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep b/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep new file mode 100644 index 000000000000..67a2c9d887c3 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep @@ -0,0 +1,91 @@ +/* setup */ +CREATE TABLE t1(i INT PRIMARY KEY, j INT); +CREATE MATERIALIZED VIEW v2 AS SELECT i, j FROM t1; +CREATE INDEX idx ON v2(j); +CREATE MATERIALIZED VIEW v3 AS SELECT j FROM v2@idx; + +/* test */ +EXPLAIN (ddl) DROP INDEX idx CASCADE; +---- +Schema change plan for DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 6 elements transitioning toward ABSENT + │ │ ├── PUBLIC → TXN_DROPPED View:{DescID: 106} + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 106, ColumnID: 1} + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 106, ColumnID: 2} + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 106, ColumnID: 4294967295} + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 106, ColumnID: 4294967294} + │ │ └── PUBLIC → VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ └── 1 Mutation operation + │ └── MarkDescriptorAsSyntheticallyDropped {"DescriptorID":106} + ├── PreCommitPhase + │ └── Stage 1 of 1 in PreCommitPhase + │ ├── 27 elements transitioning toward ABSENT + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 105, ColumnID: 2, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 105, ColumnID: 3, IndexID: 2} + │ │ ├── PUBLIC → VALIDATED SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ │ ├── PUBLIC → ABSENT Namespace:{DescID: 106, Name: v3, ReferencedDescID: 100} + │ │ ├── PUBLIC → ABSENT Owner:{DescID: 106} + │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 106, Name: admin} + │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 106, Name: root} + │ │ ├── TXN_DROPPED → DROPPED View:{DescID: 106} + │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 106, ReferencedDescID: 101} + │ │ ├── PUBLIC → ABSENT ColumnFamily:{DescID: 106, Name: primary, ColumnFamilyID: 0} + │ │ ├── WRITE_ONLY → ABSENT Column:{DescID: 106, ColumnID: 1} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 106, Name: j, ColumnID: 1} + │ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 1} + │ │ ├── WRITE_ONLY → ABSENT Column:{DescID: 106, ColumnID: 2} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 106, Name: rowid, ColumnID: 2} + │ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 2} + │ │ ├── PUBLIC → ABSENT ColumnDefaultExpression:{DescID: 106, ColumnID: 2} + │ │ ├── WRITE_ONLY → ABSENT Column:{DescID: 106, ColumnID: 4294967295} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 106, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295} + │ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 4294967295} + │ │ ├── WRITE_ONLY → ABSENT Column:{DescID: 106, ColumnID: 4294967294} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 106, Name: tableoid, ColumnID: 4294967294} + │ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 4294967294} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1} + │ │ ├── VALIDATED → ABSENT PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ └── PUBLIC → ABSENT IndexName:{DescID: 106, Name: v3_pkey, IndexID: 1} + │ └── 13 Mutation operations + │ ├── MarkDescriptorAsDropped {"DescriptorID":106} + │ ├── RemoveViewBackReferencesInRelations {"BackReferencedViewID":106} + │ ├── RemoveAllTableComments {"TableID":106} + │ ├── RemoveColumnDefaultExpression {"ColumnID":2,"TableID":106} + │ ├── MakePublicSecondaryIndexWriteOnly {"IndexID":2,"TableID":105} + │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":100,"DescriptorID":106,"Name":"v3","SchemaID":101}} + │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":1,"TableID":106} + │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967295,"TableID":106} + │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967294,"TableID":106} + │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":2,"TableID":106} + │ ├── SetJobStateOnDescriptor {"DescriptorID":105,"Initialize":true} + │ ├── SetJobStateOnDescriptor {"DescriptorID":106,"Initialize":true} + │ └── CreateSchemaChangerJob {"NonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── PostCommitNonRevertiblePhase + ├── Stage 1 of 2 in PostCommitNonRevertiblePhase + │ ├── 5 elements transitioning toward ABSENT + │ │ ├── VALIDATED → DELETE_ONLY SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ │ ├── PUBLIC → ABSENT IndexName:{DescID: 105, Name: idx, IndexID: 2} + │ │ ├── DROPPED → ABSENT View:{DescID: 106} + │ │ ├── PUBLIC → ABSENT IndexData:{DescID: 106, IndexID: 1} + │ │ └── PUBLIC → ABSENT TableData:{DescID: 106, ReferencedDescID: 100} + │ └── 8 Mutation operations + │ ├── LogEvent {"TargetStatus":1} + │ ├── CreateGCJobForTable {"DatabaseID":100,"TableID":106} + │ ├── LogEvent {"TargetStatus":1} + │ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":2,"TableID":105} + │ ├── SetIndexName {"IndexID":2,"Name":"crdb_internal_in...","TableID":105} + │ ├── CreateGCJobForIndex {"IndexID":1,"TableID":106} + │ ├── SetJobStateOnDescriptor {"DescriptorID":105} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── Stage 2 of 2 in PostCommitNonRevertiblePhase + ├── 2 elements transitioning toward ABSENT + │ ├── DELETE_ONLY → ABSENT SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ └── PUBLIC → ABSENT IndexData:{DescID: 105, IndexID: 2} + └── 4 Mutation operations + ├── MakeIndexAbsent {"IndexID":2,"TableID":105} + ├── CreateGCJobForIndex {"IndexID":2,"TableID":105} + ├── RemoveJobStateFromDescriptor {"DescriptorID":105} + └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep new file mode 100644 index 000000000000..d523aeb18a67 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep @@ -0,0 +1,624 @@ +/* setup */ +CREATE TABLE t1(i INT PRIMARY KEY, j INT); +CREATE MATERIALIZED VIEW v2 AS SELECT i, j FROM t1; +CREATE INDEX idx ON v2(j); +CREATE MATERIALIZED VIEW v3 AS SELECT j FROM v2@idx; + +/* test */ +EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; +---- +• Schema change plan for DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE; +│ +├── • StatementPhase +│ │ +│ └── • Stage 1 of 1 in StatementPhase +│ │ +│ ├── • 6 elements transitioning toward ABSENT +│ │ │ +│ │ ├── • View:{DescID: 106} +│ │ │ PUBLIC → TXN_DROPPED +│ │ │ +│ │ ├── • Column:{DescID: 106, ColumnID: 1} +│ │ │ │ PUBLIC → WRITE_ONLY +│ │ │ │ +│ │ │ └── • skip PUBLIC → WRITE_ONLY operations +│ │ │ rule: "skip column removal ops on relation drop" +│ │ │ +│ │ ├── • Column:{DescID: 106, ColumnID: 2} +│ │ │ │ PUBLIC → WRITE_ONLY +│ │ │ │ +│ │ │ └── • skip PUBLIC → WRITE_ONLY operations +│ │ │ rule: "skip column removal ops on relation drop" +│ │ │ +│ │ ├── • Column:{DescID: 106, ColumnID: 4294967295} +│ │ │ │ PUBLIC → WRITE_ONLY +│ │ │ │ +│ │ │ └── • skip PUBLIC → WRITE_ONLY operations +│ │ │ rule: "skip column removal ops on relation drop" +│ │ │ +│ │ ├── • Column:{DescID: 106, ColumnID: 4294967294} +│ │ │ │ PUBLIC → WRITE_ONLY +│ │ │ │ +│ │ │ └── • skip PUBLIC → WRITE_ONLY operations +│ │ │ rule: "skip column removal ops on relation drop" +│ │ │ +│ │ └── • PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} +│ │ │ PUBLIC → VALIDATED +│ │ │ +│ │ └── • skip PUBLIC → VALIDATED operations +│ │ rule: "skip index removal ops on relation drop" +│ │ +│ └── • 1 Mutation operation +│ │ +│ └── • MarkDescriptorAsSyntheticallyDropped +│ DescriptorID: 106 +│ +├── • PreCommitPhase +│ │ +│ └── • Stage 1 of 1 in PreCommitPhase +│ │ +│ ├── • 27 elements transitioning toward ABSENT +│ │ │ +│ │ ├── • IndexColumn:{DescID: 105, ColumnID: 2, IndexID: 2} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} +│ │ │ │ rule: "index no longer public before dependents" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip index-column removal ops on index removal" +│ │ │ +│ │ ├── • IndexColumn:{DescID: 105, ColumnID: 3, IndexID: 2} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} +│ │ │ │ rule: "index no longer public before dependents" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip index-column removal ops on index removal" +│ │ │ +│ │ ├── • SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} +│ │ │ │ PUBLIC → VALIDATED +│ │ │ │ +│ │ │ ├── • PreviousTransactionPrecedence dependency from PUBLIC SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} +│ │ │ │ rule: "SecondaryIndex transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" +│ │ │ │ +│ │ │ └── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ rule: "dependent view no longer public before secondary index" +│ │ │ +│ │ ├── • Namespace:{DescID: 106, Name: v3, ReferencedDescID: 100} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ +│ │ ├── • Owner:{DescID: 106} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ ├── • UserPrivileges:{DescID: 106, Name: admin} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ ├── • UserPrivileges:{DescID: 106, Name: root} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ ├── • View:{DescID: 106} +│ │ │ │ TXN_DROPPED → DROPPED +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED View:{DescID: 106} +│ │ │ rule: "descriptor TXN_DROPPED before DROPPED" +│ │ │ +│ │ ├── • ObjectParent:{DescID: 106, ReferencedDescID: 101} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ +│ │ ├── • ColumnFamily:{DescID: 106, Name: primary, ColumnFamilyID: 0} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ ├── • Column:{DescID: 106, ColumnID: 1} +│ │ │ │ WRITE_ONLY → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 106, Name: j, ColumnID: 1} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 1} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ └── • skip WRITE_ONLY → DELETE_ONLY operations +│ │ │ rule: "skip column removal ops on relation drop" +│ │ │ +│ │ ├── • ColumnName:{DescID: 106, Name: j, ColumnID: 1} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 1} +│ │ │ │ rule: "column no longer public before dependents" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip column dependents removal ops on relation drop" +│ │ │ +│ │ ├── • ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 1} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 1} +│ │ │ rule: "column no longer public before dependents" +│ │ │ +│ │ ├── • Column:{DescID: 106, ColumnID: 2} +│ │ │ │ WRITE_ONLY → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 106, Name: rowid, ColumnID: 2} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 2} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT ColumnDefaultExpression:{DescID: 106, ColumnID: 2} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ └── • skip WRITE_ONLY → DELETE_ONLY operations +│ │ │ rule: "skip column removal ops on relation drop" +│ │ │ +│ │ ├── • ColumnName:{DescID: 106, Name: rowid, ColumnID: 2} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 2} +│ │ │ │ rule: "column no longer public before dependents" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip column dependents removal ops on relation drop" +│ │ │ +│ │ ├── • ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 2} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 2} +│ │ │ │ rule: "column no longer public before dependents" +│ │ │ │ +│ │ │ └── • SameStagePrecedence dependency from ABSENT ColumnDefaultExpression:{DescID: 106, ColumnID: 2} +│ │ │ rule: "column type dependents removed right before column type" +│ │ │ +│ │ ├── • ColumnDefaultExpression:{DescID: 106, ColumnID: 2} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 2} +│ │ │ rule: "column no longer public before dependents" +│ │ │ +│ │ ├── • Column:{DescID: 106, ColumnID: 4294967295} +│ │ │ │ WRITE_ONLY → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 106, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 4294967295} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ └── • skip WRITE_ONLY → DELETE_ONLY operations +│ │ │ rule: "skip column removal ops on relation drop" +│ │ │ +│ │ ├── • ColumnName:{DescID: 106, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 4294967295} +│ │ │ │ rule: "column no longer public before dependents" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip column dependents removal ops on relation drop" +│ │ │ +│ │ ├── • ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 4294967295} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 4294967295} +│ │ │ rule: "column no longer public before dependents" +│ │ │ +│ │ ├── • Column:{DescID: 106, ColumnID: 4294967294} +│ │ │ │ WRITE_ONLY → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 106, Name: tableoid, ColumnID: 4294967294} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 4294967294} +│ │ │ │ rule: "dependents removed before column" +│ │ │ │ +│ │ │ └── • skip WRITE_ONLY → DELETE_ONLY operations +│ │ │ rule: "skip column removal ops on relation drop" +│ │ │ +│ │ ├── • ColumnName:{DescID: 106, Name: tableoid, ColumnID: 4294967294} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 4294967294} +│ │ │ │ rule: "column no longer public before dependents" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip column dependents removal ops on relation drop" +│ │ │ +│ │ ├── • ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 4294967294} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 4294967294} +│ │ │ rule: "column no longer public before dependents" +│ │ │ +│ │ ├── • IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 2} +│ │ │ │ rule: "column no longer public before dependents" +│ │ │ │ +│ │ │ ├── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} +│ │ │ │ rule: "index no longer public before dependents" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip index dependents removal ops on relation drop" +│ │ │ rule: "skip index-column removal ops on index removal" +│ │ │ +│ │ ├── • IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 1} +│ │ │ │ rule: "column no longer public before dependents" +│ │ │ │ +│ │ │ ├── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} +│ │ │ │ rule: "index no longer public before dependents" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip index dependents removal ops on relation drop" +│ │ │ rule: "skip index-column removal ops on index removal" +│ │ │ +│ │ ├── • PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} +│ │ │ │ VALIDATED → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1} +│ │ │ │ rule: "dependents removed before index" +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1} +│ │ │ │ rule: "dependents removed before index" +│ │ │ │ +│ │ │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 106, Name: v3_pkey, IndexID: 1} +│ │ │ │ rule: "dependents removed before index" +│ │ │ │ +│ │ │ ├── • skip VALIDATED → WRITE_ONLY operations +│ │ │ │ rule: "skip index removal ops on relation drop" +│ │ │ │ +│ │ │ ├── • skip WRITE_ONLY → DELETE_ONLY operations +│ │ │ │ rule: "skip index removal ops on relation drop" +│ │ │ │ +│ │ │ └── • skip DELETE_ONLY → ABSENT operations +│ │ │ rule: "skip index removal ops on relation drop" +│ │ │ +│ │ └── • IndexName:{DescID: 106, Name: v3_pkey, IndexID: 1} +│ │ │ PUBLIC → ABSENT +│ │ │ +│ │ ├── • Precedence dependency from DROPPED View:{DescID: 106} +│ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ +│ │ ├── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} +│ │ │ rule: "index no longer public before dependents" +│ │ │ +│ │ └── • skip PUBLIC → ABSENT operations +│ │ rule: "skip index dependents removal ops on relation drop" +│ │ +│ └── • 13 Mutation operations +│ │ +│ ├── • MarkDescriptorAsDropped +│ │ DescriptorID: 106 +│ │ +│ ├── • RemoveViewBackReferencesInRelations +│ │ BackReferencedViewID: 106 +│ │ RelationIDs: +│ │ - 105 +│ │ +│ ├── • RemoveAllTableComments +│ │ TableID: 106 +│ │ +│ ├── • RemoveColumnDefaultExpression +│ │ ColumnID: 2 +│ │ TableID: 106 +│ │ +│ ├── • MakePublicSecondaryIndexWriteOnly +│ │ IndexID: 2 +│ │ TableID: 105 +│ │ +│ ├── • DrainDescriptorName +│ │ Namespace: +│ │ DatabaseID: 100 +│ │ DescriptorID: 106 +│ │ Name: v3 +│ │ SchemaID: 101 +│ │ +│ ├── • MakeDeleteOnlyColumnAbsent +│ │ ColumnID: 1 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE +│ │ StatementTag: DROP INDEX +│ │ TargetMetadata: +│ │ SourceElementID: 2 +│ │ SubWorkID: 1 +│ │ TableID: 106 +│ │ +│ ├── • MakeDeleteOnlyColumnAbsent +│ │ ColumnID: 4294967295 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE +│ │ StatementTag: DROP INDEX +│ │ TargetMetadata: +│ │ SourceElementID: 2 +│ │ SubWorkID: 1 +│ │ TableID: 106 +│ │ +│ ├── • MakeDeleteOnlyColumnAbsent +│ │ ColumnID: 4294967294 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE +│ │ StatementTag: DROP INDEX +│ │ TargetMetadata: +│ │ SourceElementID: 2 +│ │ SubWorkID: 1 +│ │ TableID: 106 +│ │ +│ ├── • MakeDeleteOnlyColumnAbsent +│ │ ColumnID: 2 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE +│ │ StatementTag: DROP INDEX +│ │ TargetMetadata: +│ │ SourceElementID: 2 +│ │ SubWorkID: 1 +│ │ TableID: 106 +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 105 +│ │ Initialize: true +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 106 +│ │ Initialize: true +│ │ +│ └── • CreateSchemaChangerJob +│ Authorization: +│ UserName: root +│ DescriptorIDs: +│ - 105 +│ - 106 +│ JobID: 1 +│ NonCancelable: true +│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 2 with 6 MutationType ops pending +│ Statements: +│ - statement: DROP INDEX idx CASCADE +│ redactedstatement: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE +│ statementtag: DROP INDEX +│ +└── • PostCommitNonRevertiblePhase + │ + ├── • Stage 1 of 2 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 5 elements transitioning toward ABSENT + │ │ │ + │ │ ├── • SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ │ │ │ VALIDATED → DELETE_ONLY + │ │ │ │ + │ │ │ └── • PreviousTransactionPrecedence dependency from VALIDATED SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "SecondaryIndex transitions to ABSENT uphold 2-version invariant: VALIDATED->WRITE_ONLY" + │ │ │ + │ │ ├── • IndexName:{DescID: 105, Name: idx, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "index no longer public before index name" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents" + │ │ │ + │ │ ├── • View:{DescID: 106} + │ │ │ │ DROPPED → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index should be validated before dependent view can be absent" + │ │ │ │ + │ │ │ └── • PreviousTransactionPrecedence dependency from DROPPED View:{DescID: 106} + │ │ │ rule: "descriptor DROPPED in transaction before removal" + │ │ │ + │ │ ├── • IndexData:{DescID: 106, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from ABSENT PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ │ │ rule: "index removed before garbage collection" + │ │ │ │ + │ │ │ └── • SameStagePrecedence dependency from DROPPED TableData:{DescID: 106, ReferencedDescID: 100} + │ │ │ rule: "schedule all GC jobs for a descriptor in the same stage" + │ │ │ + │ │ └── • TableData:{DescID: 106, ReferencedDescID: 100} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT View:{DescID: 106} + │ │ rule: "table removed right before garbage collection" + │ │ + │ └── • 8 Mutation operations + │ │ + │ ├── • LogEvent + │ │ Element: + │ │ View: + │ │ forwardReferences: + │ │ - columnIds: + │ │ - 2 + │ │ indexId: 2 + │ │ toId: 105 + │ │ isMaterialized: true + │ │ usesRelationIds: + │ │ - 105 + │ │ viewId: 106 + │ │ EventBase: + │ │ Authorization: + │ │ UserName: root + │ │ Statement: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE + │ │ StatementTag: DROP INDEX + │ │ TargetMetadata: + │ │ SourceElementID: 2 + │ │ SubWorkID: 1 + │ │ TargetStatus: 1 + │ │ + │ ├── • CreateGCJobForTable + │ │ DatabaseID: 100 + │ │ StatementForDropJob: + │ │ Statement: DROP INDEX defaultdb.public.v2@idx CASCADE + │ │ TableID: 106 + │ │ + │ ├── • LogEvent + │ │ Element: + │ │ SecondaryIndex: + │ │ indexId: 2 + │ │ isCreatedExplicitly: true + │ │ tableId: 105 + │ │ EventBase: + │ │ Authorization: + │ │ UserName: root + │ │ Statement: DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx› CASCADE + │ │ StatementTag: DROP INDEX + │ │ TargetMetadata: + │ │ SourceElementID: 1 + │ │ SubWorkID: 1 + │ │ TargetStatus: 1 + │ │ + │ ├── • MakeWriteOnlyIndexDeleteOnly + │ │ IndexID: 2 + │ │ TableID: 105 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 2 + │ │ Name: crdb_internal_index_2_name_placeholder + │ │ TableID: 105 + │ │ + │ ├── • CreateGCJobForIndex + │ │ IndexID: 1 + │ │ StatementForDropJob: + │ │ Statement: DROP INDEX defaultdb.public.v2@idx CASCADE + │ │ TableID: 106 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 105 + │ │ + │ └── • UpdateSchemaChangerJob + │ DescriptorIDsToRemove: + │ - 106 + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 2 of 2 with 2 MutationType ops pending + │ + └── • Stage 2 of 2 in PostCommitNonRevertiblePhase + │ + ├── • 2 elements transitioning toward ABSENT + │ │ + │ ├── • SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 105, ColumnID: 2, IndexID: 2} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 105, ColumnID: 3, IndexID: 2} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • PreviousTransactionPrecedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "SecondaryIndex transitions to ABSENT uphold 2-version invariant: DELETE_ONLY->ABSENT" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 105, Name: idx, IndexID: 2} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ └── • Precedence dependency from ABSENT View:{DescID: 106} + │ │ rule: "dependent view absent before secondary index" + │ │ + │ └── • IndexData:{DescID: 105, IndexID: 2} + │ │ PUBLIC → ABSENT + │ │ + │ └── • Precedence dependency from ABSENT SecondaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 0} + │ rule: "index removed before garbage collection" + │ + └── • 4 Mutation operations + │ + ├── • MakeIndexAbsent + │ IndexID: 2 + │ TableID: 105 + │ + ├── • CreateGCJobForIndex + │ IndexID: 2 + │ StatementForDropJob: + │ Statement: DROP INDEX defaultdb.public.v2@idx CASCADE + │ TableID: 105 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 105 + │ JobID: 1 + │ + └── • UpdateSchemaChangerJob + DescriptorIDsToRemove: + - 105 + IsNonCancelable: true + JobID: 1 + RunningStatus: all stages completed