From 2a48ce9185f619e21641854ea0538cdfa3d70b42 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Mon, 18 Jul 2022 18:44:27 -0400 Subject: [PATCH 1/6] sql/row: pretty print CPut expectation for kv trace Release note: None --- .../execbuilder/testdata/secondary_index_column_families | 6 +++--- pkg/sql/row/updater.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families b/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families index 3934b9f69e16..0076ccda9c31 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families +++ b/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families @@ -227,7 +227,7 @@ Scan /Table/107/2/{NULL-!NULL} query T kvtrace(CPut,prefix=/Table/107/2/) UPDATE t SET y = 5 WHERE x = 1 ---- -CPut /Table/107/2/1/1/1 -> /TUPLE/2:2:Int/5 (replacing [10 35 4], if exists) +CPut /Table/107/2/1/1/1 -> /TUPLE/2:2:Int/5 (replacing /TUPLE/2:2:Int/2, if exists) # Test composite datatypes. statement ok @@ -400,7 +400,7 @@ InitPut /Table/112/3/2/5/1 -> /TUPLE/8:8:Int/8 query T kvtrace(Put,Del,CPut,prefix=/Table/112/2/) UPDATE t SET b = 4, c = NULL, d = NULL, e = 7, f = NULL WHERE y = 2 ---- -CPut /Table/112/2/2/1/2/1 -> /TUPLE/3:3:Int/3/1:4:Int/4 (replacing [10 51 6], if exists) +CPut /Table/112/2/2/1/2/1 -> /TUPLE/3:3:Int/3/1:4:Int/4 (replacing /TUPLE/3:3:Int/3, if exists) Del /Table/112/2/2/1/3/1 CPut /Table/112/2/2/1/4/1 -> /TUPLE/7:7:Int/7 (expecting does not exist) Del /Table/112/2/2/1/5/1 @@ -491,4 +491,4 @@ CPut /Table/113/2/5/1/0 -> /BYTES/0x33061308 (expecting does not exist) query T kvtrace(Put,Del,CPut,prefix=/Table/113/2/) UPDATE t SET z = 5 where y = 5 ---- -CPut /Table/113/2/5/1/0 -> /BYTES/0x330a1308 (replacing [3 51 6 19 8], if exists) +CPut /Table/113/2/5/1/0 -> /BYTES/0x330a1308 (replacing /BYTES/0x33061308, if exists) diff --git a/pkg/sql/row/updater.go b/pkg/sql/row/updater.go index f0eefa66721d..aa9e3b50e962 100644 --- a/pkg/sql/row/updater.go +++ b/pkg/sql/row/updater.go @@ -426,7 +426,7 @@ func (ru *Updater) UpdateRow( k := keys.PrettyPrint(ru.Helper.secIndexValDirs[i], newEntry.Key) v := newEntry.Value.PrettyPrint() if expValue != nil { - log.VEventf(ctx, 2, "CPut %s -> %v (replacing %v, if exists)", k, v, expValue) + log.VEventf(ctx, 2, "CPut %s -> %v (replacing %v, if exists)", k, v, oldEntry.Value.PrettyPrint()) } else { log.VEventf(ctx, 2, "CPut %s -> %v (expecting does not exist)", k, v) } From a3da7b0659ed6290ae45a8f7d58b5f156e10bc83 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Mon, 18 Jul 2022 18:54:38 -0400 Subject: [PATCH 2/6] sql/schemachanger: properly transition indexes to WRITE_ONLY, add rules Release note: None --- .../schemafeed/testdata/add_column | 9 +- .../testdata/boundedstaleness/single_row | 12 +- .../testdata/end_to_end/create_index | 65 +++++++---- .../testdata/explain/create_index | 23 ++-- .../testdata/explain_verbose/create_index | 44 +++++-- .../scexec/scmutationexec/column.go | 13 +++ .../scexec/scmutationexec/index.go | 44 ++++++- pkg/sql/schemachanger/scop/mutation.go | 16 +++ .../scop/mutation_visitor_generated.go | 12 ++ .../internal/opgen/opgen_primary_index.go | 19 +++- .../internal/opgen/opgen_secondary_index.go | 19 +++- .../internal/rules/dep_index_and_column.go | 81 ++++++++++--- .../scplan/internal/rules/testdata/deprules | 47 ++++++-- .../scplan/internal/rules/testdata/oprules | 12 +- .../schemachanger/scplan/testdata/alter_table | 93 ++++++++++----- .../scplan/testdata/create_index | 58 +++++++--- .../schemachanger/scplan/testdata/drop_index | 8 ++ .../end_to_end/alter_table_add_column | 75 ++++++++---- .../alter_table_add_column_default_seq | 107 ++++++++++++------ .../testdata/end_to_end/create_index | 65 +++++++---- .../testdata/explain/alter_table_add_column | 23 ++-- .../alter_table_add_column_default_seq | 24 ++-- .../testdata/explain/create_index | 23 ++-- .../explain_verbose/alter_table_add_column | 49 +++++--- .../alter_table_add_column_default_seq | 52 ++++++--- .../testdata/explain_verbose/create_index | 44 +++++-- .../drop_index_hash_sharded_index | 9 +- .../drop_index_partial_expression_index | 9 +- 28 files changed, 775 insertions(+), 280 deletions(-) diff --git a/pkg/ccl/changefeedccl/schemafeed/testdata/add_column b/pkg/ccl/changefeedccl/schemafeed/testdata/add_column index d8e2973bdbb8..dd4ad0614123 100644 --- a/pkg/ccl/changefeedccl/schemafeed/testdata/add_column +++ b/pkg/ccl/changefeedccl/schemafeed/testdata/add_column @@ -26,9 +26,10 @@ t 4->5: Unknown t 5->6: Unknown t 6->7: Unknown t 7->8: Unknown -t 8->9: AddColumnWithBackfill|PrimaryKeyChange -t 9->10: Unknown +t 8->9: Unknown +t 9->10: AddColumnWithBackfill|PrimaryKeyChange t 10->11: Unknown +t 11->12: Unknown exec SET use_declarative_schema_changer=off; @@ -37,6 +38,6 @@ ALTER TABLE t ADD COLUMN l INT NOT NULL DEFAULT 42; pop f=1 ---- -t 11->12: Unknown t 12->13: Unknown -t 13->14: AddColumnWithBackfill +t 13->14: Unknown +t 14->15: AddColumnWithBackfill diff --git a/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row b/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row index 8eacb82e694b..38ff52cd806d 100644 --- a/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row +++ b/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row @@ -185,7 +185,7 @@ query idx=2 wait-until-follower-read SELECT * FROM t AS OF SYSTEM TIME with_max_staleness('10s', true) WHERE pk = 1 ---- 1 -events (15 found): +events (17 found): * event 1: colbatchscan trace on node_idx 2: local read * event 2: transaction retry on node_idx: 2 * event 3: colbatchscan trace on node_idx 2: local read @@ -200,13 +200,15 @@ events (15 found): * event 12: transaction retry on node_idx: 2 * event 13: colbatchscan trace on node_idx 2: local read * event 14: transaction retry on node_idx: 2 - * event 15: colbatchscan trace on node_idx 2: local follower read + * event 15: colbatchscan trace on node_idx 2: local read + * event 16: transaction retry on node_idx: 2 + * event 17: colbatchscan trace on node_idx 2: local follower read query idx=2 SELECT * FROM t AS OF SYSTEM TIME with_min_timestamp(now() - '10s', true) WHERE pk = 1 ---- 1 -events (15 found): +events (17 found): * event 1: colbatchscan trace on node_idx 2: local read * event 2: transaction retry on node_idx: 2 * event 3: colbatchscan trace on node_idx 2: local read @@ -221,7 +223,9 @@ events (15 found): * event 12: transaction retry on node_idx: 2 * event 13: colbatchscan trace on node_idx 2: local read * event 14: transaction retry on node_idx: 2 - * event 15: colbatchscan trace on node_idx 2: local follower read + * event 15: colbatchscan trace on node_idx 2: local read + * event 16: transaction retry on node_idx: 2 + * event 17: colbatchscan trace on node_idx 2: local follower read # When creating a new table, ensure when nearest_only=True, we correctly error # with the schema not existing if none of the followers have caught up. diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/create_index b/pkg/ccl/schemachangerccl/testdata/end_to_end/create_index index c117f08847c9..9ff3905ede53 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/create_index +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/create_index @@ -146,7 +146,7 @@ notified job registry to adopt jobs: [1] begin transaction #2 commit transaction #2 begin transaction #3 -## PostCommitPhase stage 1 of 6 with 3 MutationType ops +## PostCommitPhase stage 1 of 7 with 3 MutationType ops upsert descriptor #104 ... formatVersion: 3 @@ -168,14 +168,14 @@ upsert descriptor #104 unexposedParentSchemaId: 101 - version: "2" + version: "3" -update progress of schema change job #1: "PostCommitPhase stage 2 of 6 with 1 BackfillType op pending" +update progress of schema change job #1: "PostCommitPhase stage 2 of 7 with 1 BackfillType op pending" commit transaction #3 begin transaction #4 -## PostCommitPhase stage 2 of 6 with 1 BackfillType op +## PostCommitPhase stage 2 of 7 with 1 BackfillType op backfill indexes [2] from index #1 in table #104 commit transaction #4 begin transaction #5 -## PostCommitPhase stage 3 of 6 with 3 MutationType ops +## PostCommitPhase stage 3 of 7 with 3 MutationType ops upsert descriptor #104 ... formatVersion: 3 @@ -197,10 +197,10 @@ upsert descriptor #104 unexposedParentSchemaId: 101 - version: "3" + version: "4" -update progress of schema change job #1: "PostCommitPhase stage 4 of 6 with 1 MutationType op pending" +update progress of schema change job #1: "PostCommitPhase stage 4 of 7 with 1 MutationType op pending" commit transaction #5 begin transaction #6 -## PostCommitPhase stage 4 of 6 with 3 MutationType ops +## PostCommitPhase stage 4 of 7 with 3 MutationType ops upsert descriptor #104 ... formatVersion: 3 @@ -214,7 +214,7 @@ upsert descriptor #104 version: 4 mutationId: 1 - state: DELETE_ONLY - + state: DELETE_AND_WRITE_ONLY + + state: MERGING - direction: ADD index: ... @@ -222,17 +222,42 @@ upsert descriptor #104 unexposedParentSchemaId: 101 - version: "4" + version: "5" -update progress of schema change job #1: "PostCommitPhase stage 5 of 6 with 1 BackfillType op pending" +update progress of schema change job #1: "PostCommitPhase stage 5 of 7 with 1 BackfillType op pending" commit transaction #6 begin transaction #7 -## PostCommitPhase stage 5 of 6 with 1 BackfillType op +## PostCommitPhase stage 5 of 7 with 1 BackfillType op merge temporary indexes [3] into backfilled indexes [2] in table #104 commit transaction #7 begin transaction #8 -## PostCommitPhase stage 6 of 6 with 1 ValidationType op -validate forward indexes [2] in table #104 +## PostCommitPhase stage 6 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + formatVersion: 3 + id: 104 + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + mutations: + - direction: ADD + ... + version: 4 + mutationId: 1 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "5" + + version: "6" +update progress of schema change job #1: "PostCommitPhase stage 7 of 7 with 1 ValidationType op pending" commit transaction #8 begin transaction #9 +## PostCommitPhase stage 7 of 7 with 1 ValidationType op +validate forward indexes [2] in table #104 +commit transaction #9 +begin transaction #10 ## PostCommitNonRevertiblePhase stage 1 of 2 with 5 MutationType ops upsert descriptor #104 ... @@ -245,7 +270,7 @@ upsert descriptor #104 formatVersion: 3 id: 104 - modificationTime: - - wallTime: "1640995200000000006" + - wallTime: "1640995200000000008" + indexes: + - constraintId: 2 + createdExplicitly: true @@ -326,12 +351,12 @@ upsert descriptor #104 ... time: {} unexposedParentSchemaId: 101 - - version: "5" - + version: "6" + - version: "6" + + version: "7" 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 -commit transaction #9 -begin transaction #10 +commit transaction #10 +begin transaction #11 ## PostCommitNonRevertiblePhase stage 2 of 2 with 4 MutationType ops upsert descriptor #104 ... @@ -358,7 +383,7 @@ upsert descriptor #104 - money version: 4 - modificationTime: - - wallTime: "1640995200000000009" + - wallTime: "1640995200000000010" - mutations: - - direction: DROP - index: @@ -401,12 +426,12 @@ upsert descriptor #104 ... time: {} unexposedParentSchemaId: 101 - - version: "6" - + version: "7" + - version: "7" + + version: "8" write *eventpb.FinishSchemaChange to event log for descriptor 104 create job #2 (non-cancelable: true): "GC for " descriptor IDs: [104] update progress of schema change job #1: "all stages completed" -commit transaction #10 +commit transaction #11 notified job registry to adopt jobs: [2] # end PostCommitPhase diff --git a/pkg/ccl/schemachangerccl/testdata/explain/create_index b/pkg/ccl/schemachangerccl/testdata/explain/create_index index ffa3d8a6aacb..47cdfc1f404f 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain/create_index +++ b/pkg/ccl/schemachangerccl/testdata/explain/create_index @@ -39,40 +39,47 @@ Schema change plan for CREATE INDEX ‹id1› ON ‹defaultdb›.‹public›. │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} ├── PostCommitPhase - │ ├── Stage 1 of 6 in PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} │ │ └── 3 Mutation operations │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":3,"TableID":104} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 2 of 6 in PostCommitPhase + │ ├── Stage 2 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── BACKFILL_ONLY → BACKFILLED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 1 Backfill operation │ │ └── BackfillIndex {"IndexID":2,"SourceIndexID":1,"TableID":104} - │ ├── Stage 3 of 6 in PostCommitPhase + │ ├── Stage 3 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── BACKFILLED → DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 3 Mutation operations │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":2,"TableID":104} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 4 of 6 in PostCommitPhase + │ ├── Stage 4 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── DELETE_ONLY → MERGE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 3 Mutation operations - │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":2,"TableID":104} + │ │ ├── MakeBackfilledIndexMerging {"IndexID":2,"TableID":104} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 5 of 6 in PostCommitPhase + │ ├── Stage 5 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── MERGE_ONLY → MERGED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 1 Backfill operation │ │ └── MergeIndex {"BackfilledIndexID":2,"TableID":104,"TemporaryIndexID":3} - │ └── Stage 6 of 6 in PostCommitPhase + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":2,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase │ ├── 1 element transitioning toward PUBLIC - │ │ └── MERGED → VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── WRITE_ONLY → VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} │ └── 1 Validation operation │ └── ValidateUniqueIndex {"IndexID":2,"TableID":104} └── PostCommitNonRevertiblePhase diff --git a/pkg/ccl/schemachangerccl/testdata/explain_verbose/create_index b/pkg/ccl/schemachangerccl/testdata/explain_verbose/create_index index 09af851fcd07..e3482cb67a20 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain_verbose/create_index +++ b/pkg/ccl/schemachangerccl/testdata/explain_verbose/create_index @@ -172,7 +172,7 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1 │ DescriptorIDs: │ - 104 │ JobID: 1 -│ RunningStatus: PostCommitPhase stage 1 of 6 with 1 MutationType op pending +│ RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending │ Statements: │ - statement: CREATE INDEX id1 ON defaultdb.t1 (id, name) STORING (money) PARTITION │ BY LIST (id) (PARTITION p1 VALUES IN (1)) @@ -182,7 +182,7 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1 │ ├── • PostCommitPhase │ │ -│ ├── • Stage 1 of 6 in PostCommitPhase +│ ├── • Stage 1 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT │ │ │ │ @@ -209,9 +209,9 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1 │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 2 of 6 with 1 BackfillType op pending +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending │ │ -│ ├── • Stage 2 of 6 in PostCommitPhase +│ ├── • Stage 2 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -237,7 +237,7 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1 │ │ SourceIndexID: 1 │ │ TableID: 104 │ │ -│ ├── • Stage 3 of 6 in PostCommitPhase +│ ├── • Stage 3 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -255,9 +255,9 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1 │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 4 of 6 with 1 MutationType op pending +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending │ │ -│ ├── • Stage 4 of 6 in PostCommitPhase +│ ├── • Stage 4 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -266,7 +266,7 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1 │ │ │ │ │ └── • 3 Mutation operations │ │ │ -│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ ├── • MakeBackfilledIndexMerging │ │ │ IndexID: 2 │ │ │ TableID: 104 │ │ │ @@ -275,9 +275,9 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1 │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 5 of 6 with 1 BackfillType op pending +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending │ │ -│ ├── • Stage 5 of 6 in PostCommitPhase +│ ├── • Stage 5 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -291,12 +291,32 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1 │ │ TableID: 104 │ │ TemporaryIndexID: 3 │ │ -│ └── • Stage 6 of 6 in PostCommitPhase +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 2 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} -│ │ MERGED → VALIDATED +│ │ WRITE_ONLY → VALIDATED │ │ │ └── • 1 Validation operation │ │ diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/column.go b/pkg/sql/schemachanger/scexec/scmutationexec/column.go index 7ccb2d072a5e..316da854ecf3 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/column.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/column.go @@ -12,6 +12,7 @@ package scmutationexec import ( "context" + "sort" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" @@ -118,6 +119,18 @@ func (m *visitor) MakeColumnPublic(ctx context.Context, op scop.MakeColumnPublic // that okay? tbl.Columns = append(tbl.Columns, *(protoutil.Clone(mut.GetColumn())).(*descpb.ColumnDescriptor)) + + // Ensure that the column is added in the right location. This is important + // when rolling back dropped columns. + getID := func(col *descpb.ColumnDescriptor) int { + if col.PGAttributeNum != 0 { + return int(col.PGAttributeNum) + } + return int(col.ID) + } + sort.Slice(tbl.Columns, func(i, j int) bool { + return getID(&tbl.Columns[i]) < getID(&tbl.Columns[j]) + }) return nil } diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/index.go b/pkg/sql/schemachanger/scexec/scmutationexec/index.go index 537c94c678ce..f3c6f3fc45c9 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/index.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/index.go @@ -142,6 +142,38 @@ func (m *visitor) MakeAddedIndexDeleteAndWriteOnly( ) } +func (m *visitor) MakeBackfilledIndexMerging( + ctx context.Context, op scop.MakeBackfilledIndexMerging, +) error { + tbl, err := m.checkOutTable(ctx, op.TableID) + if err != nil { + return err + } + return mutationStateChange( + tbl, + MakeIndexIDMutationSelector(op.IndexID), + descpb.DescriptorMutation_DELETE_ONLY, + descpb.DescriptorMutation_MERGING, + descpb.DescriptorMutation_ADD, + ) +} + +func (m *visitor) MakeMergedIndexWriteOnly( + ctx context.Context, op scop.MakeMergedIndexWriteOnly, +) error { + tbl, err := m.checkOutTable(ctx, op.TableID) + if err != nil { + return err + } + return mutationStateChange( + tbl, + MakeIndexIDMutationSelector(op.IndexID), + descpb.DescriptorMutation_MERGING, + descpb.DescriptorMutation_DELETE_AND_WRITE_ONLY, + descpb.DescriptorMutation_ADD, + ) +} + func (m *visitor) MakeAddedPrimaryIndexPublic( ctx context.Context, op scop.MakeAddedPrimaryIndexPublic, ) error { @@ -234,11 +266,19 @@ func (m *visitor) MakeDroppedIndexDeleteOnly( if err != nil { return err } + idx, err := tbl.FindIndexWithID(op.IndexID) + if err != nil { + return err + } + // It's okay if the index is in MERGING. + exp := descpb.DescriptorMutation_DELETE_AND_WRITE_ONLY + if idx.Merging() { + exp = descpb.DescriptorMutation_MERGING + } return mutationStateChange( tbl, MakeIndexIDMutationSelector(op.IndexID), - descpb.DescriptorMutation_DELETE_AND_WRITE_ONLY, - descpb.DescriptorMutation_DELETE_ONLY, + exp, descpb.DescriptorMutation_DELETE_ONLY, descpb.DescriptorMutation_DROP, ) } diff --git a/pkg/sql/schemachanger/scop/mutation.go b/pkg/sql/schemachanger/scop/mutation.go index bb9ec7e23dc1..95ace62c59c2 100644 --- a/pkg/sql/schemachanger/scop/mutation.go +++ b/pkg/sql/schemachanger/scop/mutation.go @@ -76,6 +76,22 @@ type MakeAddedIndexDeleteAndWriteOnly struct { IndexID descpb.IndexID } +// MakeBackfilledIndexMerging transitions an index addition mutation from +// DELETE_ONLY to MERGING. +type MakeBackfilledIndexMerging struct { + mutationOp + TableID descpb.ID + IndexID descpb.IndexID +} + +// MakeMergedIndexWriteOnly transitions an index addition mutation from +// MERGING to WRITE_ONLY. +type MakeMergedIndexWriteOnly struct { + mutationOp + TableID descpb.ID + IndexID descpb.IndexID +} + // MakeBackfillingIndexDeleteOnly transitions an index addition mutation from // BACKFILLING to DELETE_ONLY. type MakeBackfillingIndexDeleteOnly struct { diff --git a/pkg/sql/schemachanger/scop/mutation_visitor_generated.go b/pkg/sql/schemachanger/scop/mutation_visitor_generated.go index e91c577fd3ca..fda175f4a341 100644 --- a/pkg/sql/schemachanger/scop/mutation_visitor_generated.go +++ b/pkg/sql/schemachanger/scop/mutation_visitor_generated.go @@ -27,6 +27,8 @@ type MutationVisitor interface { MakeAddedIndexBackfilling(context.Context, MakeAddedIndexBackfilling) error SetAddedIndexPartialPredicate(context.Context, SetAddedIndexPartialPredicate) error MakeAddedIndexDeleteAndWriteOnly(context.Context, MakeAddedIndexDeleteAndWriteOnly) error + MakeBackfilledIndexMerging(context.Context, MakeBackfilledIndexMerging) error + MakeMergedIndexWriteOnly(context.Context, MakeMergedIndexWriteOnly) error MakeBackfillingIndexDeleteOnly(context.Context, MakeBackfillingIndexDeleteOnly) error MakeAddedSecondaryIndexPublic(context.Context, MakeAddedSecondaryIndexPublic) error MakeAddedPrimaryIndexPublic(context.Context, MakeAddedPrimaryIndexPublic) error @@ -120,6 +122,16 @@ func (op MakeAddedIndexDeleteAndWriteOnly) Visit(ctx context.Context, v Mutation return v.MakeAddedIndexDeleteAndWriteOnly(ctx, op) } +// Visit is part of the MutationOp interface. +func (op MakeBackfilledIndexMerging) Visit(ctx context.Context, v MutationVisitor) error { + return v.MakeBackfilledIndexMerging(ctx, op) +} + +// Visit is part of the MutationOp interface. +func (op MakeMergedIndexWriteOnly) Visit(ctx context.Context, v MutationVisitor) error { + return v.MakeMergedIndexWriteOnly(ctx, op) +} + // Visit is part of the MutationOp interface. func (op MakeBackfillingIndexDeleteOnly) Visit(ctx context.Context, v MutationVisitor) error { return v.MakeBackfillingIndexDeleteOnly(ctx, op) diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_primary_index.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_primary_index.go index d46620e4e798..7cb9cd39cbf9 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_primary_index.go +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_primary_index.go @@ -45,14 +45,13 @@ func init() { }), ), to(scpb.Status_MERGE_ONLY, - emit(func(this *scpb.PrimaryIndex) *scop.MakeAddedIndexDeleteAndWriteOnly { - return &scop.MakeAddedIndexDeleteAndWriteOnly{ + emit(func(this *scpb.PrimaryIndex) *scop.MakeBackfilledIndexMerging { + return &scop.MakeBackfilledIndexMerging{ TableID: this.TableID, IndexID: this.IndexID, } }), ), - equiv(scpb.Status_WRITE_ONLY), to(scpb.Status_MERGED, emit(func(this *scpb.PrimaryIndex) *scop.MergeIndex { return &scop.MergeIndex{ @@ -62,6 +61,20 @@ func init() { } }), ), + // The transition from MERGED to WRITE_ONLY must precede index validation. + // In MERGE_ONLY and MERGED, the index receives writes, but writes do not + // enforce uniqueness (they don't use CPut, see ForcePut). In WRITE_ONLY, + // the index receives normal writes. Only once writes are enforcing the + // uniqueness constraint for new can we validate that the index does + // indeed represent a valid uniqueness constraint over all rows. + to(scpb.Status_WRITE_ONLY, + emit(func(this *scpb.PrimaryIndex) *scop.MakeMergedIndexWriteOnly { + return &scop.MakeMergedIndexWriteOnly{ + TableID: this.TableID, + IndexID: this.IndexID, + } + }), + ), to(scpb.Status_VALIDATED, emit(func(this *scpb.PrimaryIndex) *scop.ValidateUniqueIndex { return &scop.ValidateUniqueIndex{ diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_secondary_index.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_secondary_index.go index 054c51664508..f1667efacb53 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_secondary_index.go +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_secondary_index.go @@ -46,14 +46,13 @@ func init() { }), ), to(scpb.Status_MERGE_ONLY, - emit(func(this *scpb.SecondaryIndex) *scop.MakeAddedIndexDeleteAndWriteOnly { - return &scop.MakeAddedIndexDeleteAndWriteOnly{ + emit(func(this *scpb.SecondaryIndex) *scop.MakeBackfilledIndexMerging { + return &scop.MakeBackfilledIndexMerging{ TableID: this.TableID, IndexID: this.IndexID, } }), ), - equiv(scpb.Status_WRITE_ONLY), to(scpb.Status_MERGED, emit(func(this *scpb.SecondaryIndex) *scop.MergeIndex { return &scop.MergeIndex{ @@ -63,6 +62,20 @@ func init() { } }), ), + // The transition from MERGED to WRITE_ONLY must precede index validation. + // In MERGE_ONLY and MERGED, the index receives writes, but writes do not + // enforce uniqueness (they don't use CPut, see ForcePut). In WRITE_ONLY, + // the index receives normal writes. Only once writes are enforcing the + // uniqueness constraint for new can we validate that the index does + // indeed represent a valid uniqueness constraint over all rows. + to(scpb.Status_WRITE_ONLY, + emit(func(this *scpb.SecondaryIndex) *scop.MakeMergedIndexWriteOnly { + return &scop.MakeMergedIndexWriteOnly{ + TableID: this.TableID, + IndexID: this.IndexID, + } + }), + ), to(scpb.Status_VALIDATED, emit(func(this *scpb.SecondaryIndex) *scop.ValidateUniqueIndex { // TODO(ajwerner): Should this say something other than diff --git a/pkg/sql/schemachanger/scplan/internal/rules/dep_index_and_column.go b/pkg/sql/schemachanger/scplan/internal/rules/dep_index_and_column.go index e857c703b18b..cc8713ce3419 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/dep_index_and_column.go +++ b/pkg/sql/schemachanger/scplan/internal/rules/dep_index_and_column.go @@ -497,6 +497,32 @@ func init() { }, ) + // Without this rule, we might have an index which exists and contains + // a column which does not exist. This would lead to panics inside the + // optimizer and an invalid table descriptor. + registerDepRule("indexes containing columns reach absent before column", + scgraph.Precedence, + "index", "column", + func(from, to nodeVars) rel.Clauses { + ct := rel.Var("column-type") + return rel.Clauses{ + from.el.Type((*scpb.PrimaryIndex)(nil), (*scpb.SecondaryIndex)(nil)), + to.el.Type((*scpb.Column)(nil)), + indexContainsColumn( + from.el, to.el, "index-column", "table-id", "column-id", "index-id", + ), + ct.Type((*scpb.ColumnType)(nil)), + joinOnColumnID(to.el, ct, "table-id", "column-id"), + targetStatusEq(from.target, to.target, scpb.ToAbsent), + currentStatusEq(from.node, to.node, scpb.Status_ABSENT), + rel.Filter("columnTypeIsNotBeingDropped", ct)(func( + ct *scpb.ColumnType, + ) bool { + return !ct.IsRelationBeingDropped + }), + } + }) + registerDepRule( "partial predicate removed right before secondary index when not dropping relation", scgraph.SameStagePrecedence, @@ -518,22 +544,24 @@ func init() { ) } +var indexContainsColumn = screl.Schema.Def6( + "indexContainsColumn", + "index", "column", "index-column", "table-id", "column-id", "index-id", func( + index, column, indexColumn, tableID, columnID, indexID rel.Var, + ) rel.Clauses { + return rel.Clauses{ + index.AttrEqVar(screl.IndexID, indexID), + indexColumn.Type((*scpb.IndexColumn)(nil)), + indexColumn.AttrEqVar(screl.DescID, rel.Blank), + joinOnColumnID(column, indexColumn, tableID, columnID), + joinOnIndexID(index, indexColumn, tableID, indexID), + } + }) + // These rules ensure that columns and indexes containing these columns // appear into existence in the correct order. func init() { - indexContainsColumn := screl.Schema.Def6( - "indexContainsColumn", - "index", "column", "index-column", "table-id", "column-id", "index-id", func( - index, column, indexColumn, tableID, columnID, indexID rel.Var, - ) rel.Clauses { - return rel.Clauses{ - index.AttrEqVar(screl.IndexID, indexID), - indexColumn.Type((*scpb.IndexColumn)(nil)), - indexColumn.AttrEqVar(screl.DescID, rel.Blank), - joinOnColumnID(column, indexColumn, tableID, columnID), - joinOnIndexID(index, indexColumn, tableID, indexID), - } - }) + sourceIndexNotSet := screl.Schema.Def1("sourceIndexNotSet", "index", func( index rel.Var, ) rel.Clauses { @@ -554,7 +582,7 @@ func init() { } }) registerDepRule( - "column depends on primary index", + "adding column depends on primary index", scgraph.Precedence, "index", "column", func(from, to nodeVars) rel.Clauses { @@ -566,7 +594,7 @@ func init() { from.el, to.el, "index-column", "table-id", "column-id", "index-id", ), targetStatusEq(from.target, to.target, scpb.ToPublic), - status.In(scpb.Status_WRITE_ONLY, scpb.Status_PUBLIC), + status.In(scpb.Status_PUBLIC), status.Entities(screl.CurrentStatus, from.node, to.node), } }, @@ -784,6 +812,29 @@ func init() { }), } }) + + // We need to ensure that the temporary index has all the relevant writes + // to any columns it contains. We ensure elsewhere that any index which + // will later be merged with the temporary index is not backfilled until + // that temporary index is receiving writes. This rule ensures that those + // write operations contain data for all columns. + registerDepRule( + "column is WRITE_ONLY before temporary index is WRITE_ONLY", + scgraph.Precedence, + "column", "index", + func(from, to nodeVars) rel.Clauses { + return rel.Clauses{ + from.el.Type((*scpb.Column)(nil)), + to.el.Type((*scpb.TemporaryIndex)(nil)), + indexContainsColumn(to.el, from.el, "index-column", "table-id", "column-id", "index-id"), + targetStatus(from.target, scpb.ToPublic), + targetStatus(to.target, scpb.Transient), + currentStatus(from.node, scpb.Status_WRITE_ONLY), + currentStatus(to.node, scpb.Status_WRITE_ONLY), + } + }, + ) + } // This rule ensures that columns depend on each other in increasing order. diff --git a/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules b/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules index 8d21421dd7dc..a2e3c6eea81f 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules +++ b/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules @@ -29,6 +29,12 @@ joinOnColumnID(a, b, desc-id, col-id): - joinOnDescID($a, $b, $desc-id) - $a[ColumnID] = $col-id - $b[ColumnID] = $col-id +indexContainsColumn(index, column, index-column, table-id, column-id, index-id): + - $index[IndexID] = $index-id + - $index-column[Type] = '*scpb.IndexColumn' + - $index-column[DescID] = $_ + - joinOnColumnID($column, $index-column, $table-id, $column-id) + - joinOnIndexID($index, $index-column, $table-id, $index-id) joinOnConstraintID(a, b, desc-id, constraint-id): - joinOnDescID($a, $b, $desc-id) - $a[ConstraintID] = $constraint-id @@ -37,12 +43,6 @@ index-dependents(index, dep, table-id, index-id): - $dep[Type] IN ['*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.IndexColumn'] - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.TemporaryIndex', '*scpb.SecondaryIndex'] - joinOnIndexID($dep, $index, $table-id, $index-id) -indexContainsColumn(index, column, index-column, table-id, column-id, index-id): - - $index[IndexID] = $index-id - - $index-column[Type] = '*scpb.IndexColumn' - - $index-column[DescID] = $_ - - joinOnColumnID($column, $index-column, $table-id, $column-id) - - joinOnIndexID($index, $index-column, $table-id, $index-id) sourceIndexNotSet(index): - $index[SourceIndexID] != 0 columnInPrimaryIndexSwap(index, column, index-column, table-id, column-id, index-id): @@ -418,6 +418,23 @@ deprules - columnTypeIsNotBeingDropped(*scpb.ColumnType)($column-type) - joinTargetNode($column-type, $column-type-target, $column-type-node) - joinTargetNode($column, $column-target, $column-node) +- name: indexes containing columns reach absent before column + from: index-node + kind: Precedence + to: column-node + query: + - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex'] + - $column[Type] = '*scpb.Column' + - indexContainsColumn($index, $column, $index-column, $table-id, $column-id, $index-id) + - $column-type[Type] = '*scpb.ColumnType' + - joinOnColumnID($column, $column-type, $table-id, $column-id) + - $index-target[TargetStatus] = ABSENT + - $column-target[TargetStatus] = ABSENT + - $index-node[CurrentStatus] = ABSENT + - $column-node[CurrentStatus] = ABSENT + - columnTypeIsNotBeingDropped(*scpb.ColumnType)($column-type) + - joinTargetNode($index, $index-target, $index-node) + - joinTargetNode($column, $column-target, $column-node) - name: partial predicate removed right before secondary index when not dropping relation from: partial-predicate-node kind: SameStagePrecedence @@ -433,7 +450,7 @@ deprules - secondaryIndexPartialIsNotBeingDropped(*scpb.SecondaryIndexPartial)($partial-predicate) - joinTargetNode($partial-predicate, $partial-predicate-target, $partial-predicate-node) - joinTargetNode($index, $index-target, $index-node) -- name: column depends on primary index +- name: adding column depends on primary index from: index-node kind: Precedence to: column-node @@ -443,7 +460,7 @@ deprules - columnInPrimaryIndexSwap($index, $column, $index-column, $table-id, $column-id, $index-id) - $index-target[TargetStatus] = PUBLIC - $column-target[TargetStatus] = PUBLIC - - $status IN [WRITE_ONLY, PUBLIC] + - $status IN [PUBLIC] - $index-node[CurrentStatus] = $status - $column-node[CurrentStatus] = $status - joinTargetNode($index, $index-target, $index-node) @@ -621,6 +638,20 @@ deprules - indexes-id-less(scpb.Element, scpb.Element)($a, $b) - joinTargetNode($index-a, $index-a-target, $index-a-node) - joinTargetNode($index-b, $index-b-target, $index-b-node) +- name: column is WRITE_ONLY before temporary index is WRITE_ONLY + from: column-node + kind: Precedence + to: index-node + query: + - $column[Type] = '*scpb.Column' + - $index[Type] = '*scpb.TemporaryIndex' + - indexContainsColumn($index, $column, $index-column, $table-id, $column-id, $index-id) + - $column-target[TargetStatus] = PUBLIC + - $index-target[TargetStatus] = TRANSIENT_ABSENT + - $column-node[CurrentStatus] = WRITE_ONLY + - $index-node[CurrentStatus] = WRITE_ONLY + - joinTargetNode($column, $column-target, $column-node) + - joinTargetNode($index, $index-target, $index-node) - name: ensure columns are in increasing order from: later-column-node kind: SameStagePrecedence diff --git a/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules b/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules index f8848e4b63a0..bd2a0fa119ac 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules +++ b/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules @@ -29,6 +29,12 @@ joinOnColumnID(a, b, desc-id, col-id): - joinOnDescID($a, $b, $desc-id) - $a[ColumnID] = $col-id - $b[ColumnID] = $col-id +indexContainsColumn(index, column, index-column, table-id, column-id, index-id): + - $index[IndexID] = $index-id + - $index-column[Type] = '*scpb.IndexColumn' + - $index-column[DescID] = $_ + - joinOnColumnID($column, $index-column, $table-id, $column-id) + - joinOnIndexID($index, $index-column, $table-id, $index-id) joinOnConstraintID(a, b, desc-id, constraint-id): - joinOnDescID($a, $b, $desc-id) - $a[ConstraintID] = $constraint-id @@ -37,12 +43,6 @@ index-dependents(index, dep, table-id, index-id): - $dep[Type] IN ['*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.IndexColumn'] - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.TemporaryIndex', '*scpb.SecondaryIndex'] - joinOnIndexID($dep, $index, $table-id, $index-id) -indexContainsColumn(index, column, index-column, table-id, column-id, index-id): - - $index[IndexID] = $index-id - - $index-column[Type] = '*scpb.IndexColumn' - - $index-column[DescID] = $_ - - joinOnColumnID($column, $index-column, $table-id, $column-id) - - joinOnIndexID($index, $index-column, $table-id, $index-id) sourceIndexNotSet(index): - $index[SourceIndexID] != 0 columnInPrimaryIndexSwap(index, column, index-column, table-id, column-id, index-id): diff --git a/pkg/sql/schemachanger/scplan/testdata/alter_table b/pkg/sql/schemachanger/scplan/testdata/alter_table index 2fab13926bfd..9d43f4179814 100644 --- a/pkg/sql/schemachanger/scplan/testdata/alter_table +++ b/pkg/sql/schemachanger/scplan/testdata/alter_table @@ -232,13 +232,13 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops DescriptorIDs: - 104 JobID: 1 - RunningStatus: PostCommitPhase stage 1 of 6 with 2 MutationType ops pending + RunningStatus: PostCommitPhase stage 1 of 7 with 2 MutationType ops pending Statements: - statement: ALTER TABLE defaultdb.foo ADD COLUMN j INT8 DEFAULT 123 redactedstatement: ALTER TABLE ‹defaultdb›.public.‹foo› ADD COLUMN ‹j› INT8 DEFAULT ‹123› statementtag: ALTER TABLE -PostCommitPhase stage 1 of 6 with 4 MutationType ops +PostCommitPhase stage 1 of 7 with 4 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY @@ -253,7 +253,7 @@ PostCommitPhase stage 1 of 6 with 4 MutationType ops DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 2 of 6 with 1 BackfillType op +PostCommitPhase stage 2 of 7 with 1 BackfillType op transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED ops: @@ -261,7 +261,7 @@ PostCommitPhase stage 2 of 6 with 1 BackfillType op IndexID: 2 SourceIndexID: 1 TableID: 104 -PostCommitPhase stage 3 of 6 with 3 MutationType ops +PostCommitPhase stage 3 of 7 with 3 MutationType ops transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY ops: @@ -272,18 +272,18 @@ PostCommitPhase stage 3 of 6 with 3 MutationType ops DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 4 of 6 with 3 MutationType ops +PostCommitPhase stage 4 of 7 with 3 MutationType ops transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY ops: - *scop.MakeAddedIndexDeleteAndWriteOnly + *scop.MakeBackfilledIndexMerging IndexID: 2 TableID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 5 of 6 with 1 BackfillType op +PostCommitPhase stage 5 of 7 with 1 BackfillType op transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED ops: @@ -291,9 +291,20 @@ PostCommitPhase stage 5 of 6 with 1 BackfillType op BackfilledIndexID: 2 TableID: 104 TemporaryIndexID: 3 -PostCommitPhase stage 6 of 6 with 1 ValidationType op +PostCommitPhase stage 6 of 7 with 3 MutationType ops + transitions: + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> WRITE_ONLY + ops: + *scop.MakeMergedIndexWriteOnly + IndexID: 2 + TableID: 104 + *scop.SetJobStateOnDescriptor + DescriptorID: 104 + *scop.UpdateSchemaChangerJob + JobID: 1 +PostCommitPhase stage 7 of 7 with 1 ValidationType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], WRITE_ONLY] -> VALIDATED ops: *scop.ValidateUniqueIndex IndexID: 2 @@ -562,7 +573,7 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops DescriptorIDs: - 104 JobID: 1 - RunningStatus: PostCommitPhase stage 1 of 6 with 3 MutationType ops pending + RunningStatus: PostCommitPhase stage 1 of 7 with 3 MutationType ops pending Statements: - statement: ALTER TABLE defaultdb.foo ADD COLUMN j INT8 DEFAULT 123 redactedstatement: ALTER TABLE ‹defaultdb›.public.‹foo› ADD COLUMN ‹j› INT8 DEFAULT @@ -572,7 +583,7 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops redactedstatement: ALTER TABLE ‹defaultdb›.public.‹foo› ADD COLUMN ‹k› INT8 DEFAULT ‹456› statementtag: ALTER TABLE -PostCommitPhase stage 1 of 6 with 5 MutationType ops +PostCommitPhase stage 1 of 7 with 5 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY @@ -581,17 +592,17 @@ PostCommitPhase stage 1 of 6 with 5 MutationType ops *scop.MakeAddedColumnDeleteAndWriteOnly ColumnID: 2 TableID: 104 - *scop.MakeAddedIndexDeleteAndWriteOnly - IndexID: 3 - TableID: 104 *scop.MakeAddedColumnDeleteAndWriteOnly ColumnID: 3 TableID: 104 + *scop.MakeAddedIndexDeleteAndWriteOnly + IndexID: 3 + TableID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 2 of 6 with 1 BackfillType op +PostCommitPhase stage 2 of 7 with 1 BackfillType op transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED ops: @@ -599,7 +610,7 @@ PostCommitPhase stage 2 of 6 with 1 BackfillType op IndexID: 2 SourceIndexID: 1 TableID: 104 -PostCommitPhase stage 3 of 6 with 3 MutationType ops +PostCommitPhase stage 3 of 7 with 3 MutationType ops transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY ops: @@ -610,18 +621,18 @@ PostCommitPhase stage 3 of 6 with 3 MutationType ops DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 4 of 6 with 3 MutationType ops +PostCommitPhase stage 4 of 7 with 3 MutationType ops transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY ops: - *scop.MakeAddedIndexDeleteAndWriteOnly + *scop.MakeBackfilledIndexMerging IndexID: 2 TableID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 5 of 6 with 1 BackfillType op +PostCommitPhase stage 5 of 7 with 1 BackfillType op transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED ops: @@ -629,9 +640,20 @@ PostCommitPhase stage 5 of 6 with 1 BackfillType op BackfilledIndexID: 2 TableID: 104 TemporaryIndexID: 3 -PostCommitPhase stage 6 of 6 with 1 ValidationType op +PostCommitPhase stage 6 of 7 with 3 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> WRITE_ONLY + ops: + *scop.MakeMergedIndexWriteOnly + IndexID: 2 + TableID: 104 + *scop.SetJobStateOnDescriptor + DescriptorID: 104 + *scop.UpdateSchemaChangerJob + JobID: 1 +PostCommitPhase stage 7 of 7 with 1 ValidationType op + transitions: + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], WRITE_ONLY] -> VALIDATED ops: *scop.ValidateUniqueIndex IndexID: 2 @@ -851,13 +873,13 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops DescriptorIDs: - 104 JobID: 1 - RunningStatus: PostCommitPhase stage 1 of 6 with 2 MutationType ops pending + RunningStatus: PostCommitPhase stage 1 of 7 with 2 MutationType ops pending Statements: - statement: ALTER TABLE defaultdb.foo ADD COLUMN a INT8 AS (i + 1) STORED redactedstatement: ALTER TABLE ‹defaultdb›.public.‹foo› ADD COLUMN ‹a› INT8 AS (‹i› + ‹1›) STORED statementtag: ALTER TABLE -PostCommitPhase stage 1 of 6 with 4 MutationType ops +PostCommitPhase stage 1 of 7 with 4 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY @@ -872,7 +894,7 @@ PostCommitPhase stage 1 of 6 with 4 MutationType ops DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 2 of 6 with 1 BackfillType op +PostCommitPhase stage 2 of 7 with 1 BackfillType op transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED ops: @@ -880,7 +902,7 @@ PostCommitPhase stage 2 of 6 with 1 BackfillType op IndexID: 2 SourceIndexID: 1 TableID: 104 -PostCommitPhase stage 3 of 6 with 3 MutationType ops +PostCommitPhase stage 3 of 7 with 3 MutationType ops transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY ops: @@ -891,18 +913,18 @@ PostCommitPhase stage 3 of 6 with 3 MutationType ops DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 4 of 6 with 3 MutationType ops +PostCommitPhase stage 4 of 7 with 3 MutationType ops transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY ops: - *scop.MakeAddedIndexDeleteAndWriteOnly + *scop.MakeBackfilledIndexMerging IndexID: 2 TableID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 5 of 6 with 1 BackfillType op +PostCommitPhase stage 5 of 7 with 1 BackfillType op transitions: [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED ops: @@ -910,9 +932,20 @@ PostCommitPhase stage 5 of 6 with 1 BackfillType op BackfilledIndexID: 2 TableID: 104 TemporaryIndexID: 3 -PostCommitPhase stage 6 of 6 with 1 ValidationType op +PostCommitPhase stage 6 of 7 with 3 MutationType ops + transitions: + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> WRITE_ONLY + ops: + *scop.MakeMergedIndexWriteOnly + IndexID: 2 + TableID: 104 + *scop.SetJobStateOnDescriptor + DescriptorID: 104 + *scop.UpdateSchemaChangerJob + JobID: 1 +PostCommitPhase stage 7 of 7 with 1 ValidationType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], WRITE_ONLY] -> VALIDATED ops: *scop.ValidateUniqueIndex IndexID: 2 diff --git a/pkg/sql/schemachanger/scplan/testdata/create_index b/pkg/sql/schemachanger/scplan/testdata/create_index index f3b7e87c4fbd..7053750f5f59 100644 --- a/pkg/sql/schemachanger/scplan/testdata/create_index +++ b/pkg/sql/schemachanger/scplan/testdata/create_index @@ -69,13 +69,13 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops DescriptorIDs: - 104 JobID: 1 - RunningStatus: PostCommitPhase stage 1 of 6 with 1 MutationType op pending + RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending Statements: - statement: CREATE INDEX id1 ON defaultdb.t1 (id, name) STORING (money) redactedstatement: CREATE INDEX ‹id1› ON ‹defaultdb›.public.‹t1› (‹id›, ‹name›) STORING (‹money›) statementtag: CREATE INDEX -PostCommitPhase stage 1 of 6 with 3 MutationType ops +PostCommitPhase stage 1 of 7 with 3 MutationType ops transitions: [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY ops: @@ -86,7 +86,7 @@ PostCommitPhase stage 1 of 6 with 3 MutationType ops DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 2 of 6 with 1 BackfillType op +PostCommitPhase stage 2 of 7 with 1 BackfillType op transitions: [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED ops: @@ -94,7 +94,7 @@ PostCommitPhase stage 2 of 6 with 1 BackfillType op IndexID: 2 SourceIndexID: 1 TableID: 104 -PostCommitPhase stage 3 of 6 with 3 MutationType ops +PostCommitPhase stage 3 of 7 with 3 MutationType ops transitions: [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY ops: @@ -105,18 +105,18 @@ PostCommitPhase stage 3 of 6 with 3 MutationType ops DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 4 of 6 with 3 MutationType ops +PostCommitPhase stage 4 of 7 with 3 MutationType ops transitions: [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY ops: - *scop.MakeAddedIndexDeleteAndWriteOnly + *scop.MakeBackfilledIndexMerging IndexID: 2 TableID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 5 of 6 with 1 BackfillType op +PostCommitPhase stage 5 of 7 with 1 BackfillType op transitions: [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED ops: @@ -124,9 +124,20 @@ PostCommitPhase stage 5 of 6 with 1 BackfillType op BackfilledIndexID: 2 TableID: 104 TemporaryIndexID: 3 -PostCommitPhase stage 6 of 6 with 1 ValidationType op +PostCommitPhase stage 6 of 7 with 3 MutationType ops + transitions: + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> WRITE_ONLY + ops: + *scop.MakeMergedIndexWriteOnly + IndexID: 2 + TableID: 104 + *scop.SetJobStateOnDescriptor + DescriptorID: 104 + *scop.UpdateSchemaChangerJob + JobID: 1 +PostCommitPhase stage 7 of 7 with 1 ValidationType op transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], WRITE_ONLY] -> VALIDATED ops: *scop.ValidateUniqueIndex IndexID: 2 @@ -304,14 +315,14 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops DescriptorIDs: - 104 JobID: 1 - RunningStatus: PostCommitPhase stage 1 of 6 with 1 MutationType op pending + RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending Statements: - statement: CREATE INVERTED INDEX CONCURRENTLY id1 ON defaultdb.t1 (id, name) STORING (money) redactedstatement: CREATE INVERTED INDEX CONCURRENTLY ‹id1› ON ‹defaultdb›.public.‹t1› (‹id›, ‹name›) STORING (‹money›) statementtag: CREATE INDEX -PostCommitPhase stage 1 of 6 with 3 MutationType ops +PostCommitPhase stage 1 of 7 with 3 MutationType ops transitions: [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY ops: @@ -322,7 +333,7 @@ PostCommitPhase stage 1 of 6 with 3 MutationType ops DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 2 of 6 with 1 BackfillType op +PostCommitPhase stage 2 of 7 with 1 BackfillType op transitions: [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED ops: @@ -330,7 +341,7 @@ PostCommitPhase stage 2 of 6 with 1 BackfillType op IndexID: 2 SourceIndexID: 1 TableID: 104 -PostCommitPhase stage 3 of 6 with 3 MutationType ops +PostCommitPhase stage 3 of 7 with 3 MutationType ops transitions: [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY ops: @@ -341,18 +352,18 @@ PostCommitPhase stage 3 of 6 with 3 MutationType ops DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 4 of 6 with 3 MutationType ops +PostCommitPhase stage 4 of 7 with 3 MutationType ops transitions: [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY ops: - *scop.MakeAddedIndexDeleteAndWriteOnly + *scop.MakeBackfilledIndexMerging IndexID: 2 TableID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 104 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 5 of 6 with 1 BackfillType op +PostCommitPhase stage 5 of 7 with 1 BackfillType op transitions: [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED ops: @@ -360,9 +371,20 @@ PostCommitPhase stage 5 of 6 with 1 BackfillType op BackfilledIndexID: 2 TableID: 104 TemporaryIndexID: 3 -PostCommitPhase stage 6 of 6 with 1 ValidationType op +PostCommitPhase stage 6 of 7 with 3 MutationType ops + transitions: + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> WRITE_ONLY + ops: + *scop.MakeMergedIndexWriteOnly + IndexID: 2 + TableID: 104 + *scop.SetJobStateOnDescriptor + DescriptorID: 104 + *scop.UpdateSchemaChangerJob + JobID: 1 +PostCommitPhase stage 7 of 7 with 1 ValidationType op transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], WRITE_ONLY] -> VALIDATED ops: *scop.ValidateUniqueIndex IndexID: 2 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_index b/pkg/sql/schemachanger/scplan/testdata/drop_index index da85549005ef..b5eb76d4dbe3 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_index +++ b/pkg/sql/schemachanger/scplan/testdata/drop_index @@ -305,6 +305,10 @@ DROP INDEX idx2 CASCADE to: [SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 0}, ABSENT] kind: Precedence rule: dependents removed before index +- from: [SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 0}, ABSENT] + to: [Column:{DescID: 104, ColumnID: 4}, ABSENT] + kind: Precedence + rule: indexes containing columns reach absent before column - from: [SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 0}, DELETE_ONLY] to: [IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4}, ABSENT] kind: Precedence @@ -520,6 +524,10 @@ DROP INDEX idx3 CASCADE to: [SecondaryIndex:{DescID: 104, IndexID: 6, ConstraintID: 0}, ABSENT] kind: Precedence rule: dependents removed before index +- from: [SecondaryIndex:{DescID: 104, IndexID: 6, ConstraintID: 0}, ABSENT] + to: [Column:{DescID: 104, ColumnID: 5}, ABSENT] + kind: Precedence + rule: indexes containing columns reach absent before column - from: [SecondaryIndex:{DescID: 104, IndexID: 6, ConstraintID: 0}, DELETE_ONLY] to: [IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 6}, ABSENT] kind: Precedence diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_column b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_column index 56aee6239d44..a752a391828a 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_column +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_column @@ -159,7 +159,7 @@ notified job registry to adopt jobs: [1] begin transaction #2 commit transaction #2 begin transaction #3 -## PostCommitPhase stage 1 of 6 with 4 MutationType ops +## PostCommitPhase stage 1 of 7 with 4 MutationType ops upsert descriptor #106 ... formatVersion: 3 @@ -188,14 +188,14 @@ upsert descriptor #106 unexposedParentSchemaId: 105 - version: "2" + version: "3" -update progress of schema change job #1: "PostCommitPhase stage 2 of 6 with 1 BackfillType op pending" +update progress of schema change job #1: "PostCommitPhase stage 2 of 7 with 1 BackfillType op pending" commit transaction #3 begin transaction #4 -## PostCommitPhase stage 2 of 6 with 1 BackfillType op +## PostCommitPhase stage 2 of 7 with 1 BackfillType op backfill indexes [2] from index #1 in table #106 commit transaction #4 begin transaction #5 -## PostCommitPhase stage 3 of 6 with 3 MutationType ops +## PostCommitPhase stage 3 of 7 with 3 MutationType ops upsert descriptor #106 ... formatVersion: 3 @@ -217,10 +217,10 @@ upsert descriptor #106 unexposedParentSchemaId: 105 - version: "3" + version: "4" -update progress of schema change job #1: "PostCommitPhase stage 4 of 6 with 1 MutationType op pending" +update progress of schema change job #1: "PostCommitPhase stage 4 of 7 with 1 MutationType op pending" commit transaction #5 begin transaction #6 -## PostCommitPhase stage 4 of 6 with 3 MutationType ops +## PostCommitPhase stage 4 of 7 with 3 MutationType ops upsert descriptor #106 ... formatVersion: 3 @@ -234,7 +234,7 @@ upsert descriptor #106 version: 4 mutationId: 1 - state: DELETE_ONLY - + state: DELETE_AND_WRITE_ONLY + + state: MERGING - direction: ADD index: ... @@ -242,17 +242,42 @@ upsert descriptor #106 unexposedParentSchemaId: 105 - version: "4" + version: "5" -update progress of schema change job #1: "PostCommitPhase stage 5 of 6 with 1 BackfillType op pending" +update progress of schema change job #1: "PostCommitPhase stage 5 of 7 with 1 BackfillType op pending" commit transaction #6 begin transaction #7 -## PostCommitPhase stage 5 of 6 with 1 BackfillType op +## PostCommitPhase stage 5 of 7 with 1 BackfillType op merge temporary indexes [3] into backfilled indexes [2] in table #106 commit transaction #7 begin transaction #8 -## PostCommitPhase stage 6 of 6 with 1 ValidationType op -validate forward indexes [2] in table #106 +## PostCommitPhase stage 6 of 7 with 3 MutationType ops +upsert descriptor #106 + ... + formatVersion: 3 + id: 106 + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 105 + - version: "5" + + version: "6" +update progress of schema change job #1: "PostCommitPhase stage 7 of 7 with 1 ValidationType op pending" commit transaction #8 begin transaction #9 +## PostCommitPhase stage 7 of 7 with 1 ValidationType op +validate forward indexes [2] in table #106 +commit transaction #9 +begin transaction #10 ## PostCommitNonRevertiblePhase stage 1 of 3 with 10 MutationType ops upsert descriptor #106 ... @@ -278,7 +303,7 @@ upsert descriptor #106 formatVersion: 3 id: 106 - modificationTime: - - wallTime: "1640995200000000006" + - wallTime: "1640995200000000008" + modificationTime: {} mutations: - - column: @@ -376,20 +401,20 @@ upsert descriptor #106 ... time: {} unexposedParentSchemaId: 105 - - version: "5" - + version: "6" + - version: "6" + + version: "7" adding table for stats refresh: 106 update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending" set schema change job #1 to non-cancellable -commit transaction #9 -begin transaction #10 +commit transaction #10 +begin transaction #11 ## PostCommitNonRevertiblePhase stage 2 of 3 with 3 MutationType ops upsert descriptor #106 ... formatVersion: 3 id: 106 - modificationTime: - - wallTime: "1640995200000000009" + - wallTime: "1640995200000000010" + modificationTime: {} mutations: - direction: DROP @@ -403,11 +428,11 @@ upsert descriptor #106 ... time: {} unexposedParentSchemaId: 105 - - version: "6" - + version: "7" + - version: "7" + + version: "8" update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 3 of 3 with 4 MutationType ops pending" -commit transaction #10 -begin transaction #11 +commit transaction #11 +begin transaction #12 ## PostCommitNonRevertiblePhase stage 3 of 3 with 6 MutationType ops upsert descriptor #106 ... @@ -432,7 +457,7 @@ upsert descriptor #106 formatVersion: 3 id: 106 - modificationTime: - - wallTime: "1640995200000000010" + - wallTime: "1640995200000000011" - mutations: - - direction: DROP - index: @@ -490,12 +515,12 @@ upsert descriptor #106 ... time: {} unexposedParentSchemaId: 105 - - version: "7" - + version: "8" + - version: "8" + + version: "9" write *eventpb.FinishSchemaChange to event log for descriptor 106 create job #2 (non-cancelable: true): "GC for ALTER TABLE db.public.tbl ADD COLUMN j INT8 NOT NULL DEFAULT 42" descriptor IDs: [106] update progress of schema change job #1: "all stages completed" -commit transaction #11 +commit transaction #12 notified job registry to adopt jobs: [2] # end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_column_default_seq b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_column_default_seq index 1c3da7a1f9d2..be65dce56d8f 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_column_default_seq +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_column_default_seq @@ -204,7 +204,7 @@ notified job registry to adopt jobs: [1] begin transaction #2 commit transaction #2 begin transaction #3 -## PostCommitPhase stage 1 of 6 with 5 MutationType ops +## PostCommitPhase stage 1 of 7 with 5 MutationType ops upsert descriptor #106 ... formatVersion: 3 @@ -247,14 +247,14 @@ upsert descriptor #107 unexposedParentSchemaId: 105 - version: "2" + version: "3" -update progress of schema change job #1: "PostCommitPhase stage 2 of 6 with 1 BackfillType op pending" +update progress of schema change job #1: "PostCommitPhase stage 2 of 7 with 1 BackfillType op pending" commit transaction #3 begin transaction #4 -## PostCommitPhase stage 2 of 6 with 1 BackfillType op +## PostCommitPhase stage 2 of 7 with 1 BackfillType op backfill indexes [2] from index #1 in table #106 commit transaction #4 begin transaction #5 -## PostCommitPhase stage 3 of 6 with 4 MutationType ops +## PostCommitPhase stage 3 of 7 with 4 MutationType ops upsert descriptor #106 ... formatVersion: 3 @@ -290,10 +290,10 @@ upsert descriptor #107 unexposedParentSchemaId: 105 - version: "3" + version: "4" -update progress of schema change job #1: "PostCommitPhase stage 4 of 6 with 1 MutationType op pending" +update progress of schema change job #1: "PostCommitPhase stage 4 of 7 with 1 MutationType op pending" commit transaction #5 begin transaction #6 -## PostCommitPhase stage 4 of 6 with 4 MutationType ops +## PostCommitPhase stage 4 of 7 with 4 MutationType ops upsert descriptor #106 ... formatVersion: 3 @@ -307,7 +307,7 @@ upsert descriptor #106 version: 4 mutationId: 1 - state: DELETE_ONLY - + state: DELETE_AND_WRITE_ONLY + + state: MERGING - direction: ADD index: ... @@ -329,17 +329,56 @@ upsert descriptor #107 unexposedParentSchemaId: 105 - version: "4" + version: "5" -update progress of schema change job #1: "PostCommitPhase stage 5 of 6 with 1 BackfillType op pending" +update progress of schema change job #1: "PostCommitPhase stage 5 of 7 with 1 BackfillType op pending" commit transaction #6 begin transaction #7 -## PostCommitPhase stage 5 of 6 with 1 BackfillType op +## PostCommitPhase stage 5 of 7 with 1 BackfillType op merge temporary indexes [3] into backfilled indexes [2] in table #106 commit transaction #7 begin transaction #8 -## PostCommitPhase stage 6 of 6 with 1 ValidationType op -validate forward indexes [2] in table #106 +## PostCommitPhase stage 6 of 7 with 4 MutationType ops +upsert descriptor #106 + ... + formatVersion: 3 + id: 106 + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 105 + - version: "5" + + version: "6" +upsert descriptor #107 + ... + formatVersion: 3 + id: 107 + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + name: sq1 + parentId: 104 + ... + start: "1" + unexposedParentSchemaId: 105 + - version: "5" + + version: "6" +update progress of schema change job #1: "PostCommitPhase stage 7 of 7 with 1 ValidationType op pending" commit transaction #8 begin transaction #9 +## PostCommitPhase stage 7 of 7 with 1 ValidationType op +validate forward indexes [2] in table #106 +commit transaction #9 +begin transaction #10 ## PostCommitNonRevertiblePhase stage 1 of 3 with 11 MutationType ops upsert descriptor #106 ... @@ -367,7 +406,7 @@ upsert descriptor #106 formatVersion: 3 id: 106 - modificationTime: - - wallTime: "1640995200000000006" + - wallTime: "1640995200000000008" + modificationTime: {} mutations: - - column: @@ -467,8 +506,8 @@ upsert descriptor #106 ... time: {} unexposedParentSchemaId: 105 - - version: "5" - + version: "6" + - version: "6" + + version: "7" upsert descriptor #107 ... userName: root @@ -480,27 +519,27 @@ upsert descriptor #107 formatVersion: 3 id: 107 - modificationTime: - - wallTime: "1640995200000000006" + - wallTime: "1640995200000000008" + modificationTime: {} name: sq1 parentId: 104 ... start: "1" unexposedParentSchemaId: 105 - - version: "5" - + version: "6" + - version: "6" + + version: "7" adding table for stats refresh: 106 update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending" set schema change job #1 to non-cancellable -commit transaction #9 -begin transaction #10 +commit transaction #10 +begin transaction #11 ## PostCommitNonRevertiblePhase stage 2 of 3 with 4 MutationType ops upsert descriptor #106 ... formatVersion: 3 id: 106 - modificationTime: - - wallTime: "1640995200000000009" + - wallTime: "1640995200000000010" + modificationTime: {} mutations: - direction: DROP @@ -514,25 +553,25 @@ upsert descriptor #106 ... time: {} unexposedParentSchemaId: 105 - - version: "6" - + version: "7" + - version: "7" + + version: "8" upsert descriptor #107 ... formatVersion: 3 id: 107 - modificationTime: - - wallTime: "1640995200000000009" + - wallTime: "1640995200000000010" + modificationTime: {} name: sq1 parentId: 104 ... start: "1" unexposedParentSchemaId: 105 - - version: "6" - + version: "7" + - version: "7" + + version: "8" update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 3 of 3 with 4 MutationType ops pending" -commit transaction #10 -begin transaction #11 +commit transaction #11 +begin transaction #12 ## PostCommitNonRevertiblePhase stage 3 of 3 with 7 MutationType ops upsert descriptor #106 ... @@ -557,7 +596,7 @@ upsert descriptor #106 formatVersion: 3 id: 106 - modificationTime: - - wallTime: "1640995200000000010" + - wallTime: "1640995200000000011" - mutations: - - direction: DROP - index: @@ -615,8 +654,8 @@ upsert descriptor #106 ... time: {} unexposedParentSchemaId: 105 - - version: "7" - + version: "8" + - version: "8" + + version: "9" upsert descriptor #107 ... createAsOfTime: @@ -631,19 +670,19 @@ upsert descriptor #107 formatVersion: 3 id: 107 - modificationTime: - - wallTime: "1640995200000000010" + - wallTime: "1640995200000000011" + modificationTime: {} name: sq1 parentId: 104 ... start: "1" unexposedParentSchemaId: 105 - - version: "7" - + version: "8" + - version: "8" + + version: "9" write *eventpb.FinishSchemaChange to event log for descriptor 106 create job #2 (non-cancelable: true): "GC for ALTER TABLE db.public.tbl ADD COLUMN l INT8 NOT NULL DEFAULT nextval('db.public.sq1')" descriptor IDs: [106] update progress of schema change job #1: "all stages completed" -commit transaction #11 +commit transaction #12 notified job registry to adopt jobs: [2] # end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/end_to_end/create_index b/pkg/sql/schemachanger/testdata/end_to_end/create_index index 752f1b555570..61acae4dc70e 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/create_index +++ b/pkg/sql/schemachanger/testdata/end_to_end/create_index @@ -124,7 +124,7 @@ notified job registry to adopt jobs: [1] begin transaction #2 commit transaction #2 begin transaction #3 -## PostCommitPhase stage 1 of 6 with 3 MutationType ops +## PostCommitPhase stage 1 of 7 with 3 MutationType ops upsert descriptor #106 ... formatVersion: 3 @@ -146,14 +146,14 @@ upsert descriptor #106 unexposedParentSchemaId: 101 - version: "2" + version: "3" -update progress of schema change job #1: "PostCommitPhase stage 2 of 6 with 1 BackfillType op pending" +update progress of schema change job #1: "PostCommitPhase stage 2 of 7 with 1 BackfillType op pending" commit transaction #3 begin transaction #4 -## PostCommitPhase stage 2 of 6 with 1 BackfillType op +## PostCommitPhase stage 2 of 7 with 1 BackfillType op backfill indexes [2] from index #1 in table #106 commit transaction #4 begin transaction #5 -## PostCommitPhase stage 3 of 6 with 3 MutationType ops +## PostCommitPhase stage 3 of 7 with 3 MutationType ops upsert descriptor #106 ... formatVersion: 3 @@ -175,10 +175,10 @@ upsert descriptor #106 unexposedParentSchemaId: 101 - version: "3" + version: "4" -update progress of schema change job #1: "PostCommitPhase stage 4 of 6 with 1 MutationType op pending" +update progress of schema change job #1: "PostCommitPhase stage 4 of 7 with 1 MutationType op pending" commit transaction #5 begin transaction #6 -## PostCommitPhase stage 4 of 6 with 3 MutationType ops +## PostCommitPhase stage 4 of 7 with 3 MutationType ops upsert descriptor #106 ... formatVersion: 3 @@ -192,7 +192,7 @@ upsert descriptor #106 version: 4 mutationId: 1 - state: DELETE_ONLY - + state: DELETE_AND_WRITE_ONLY + + state: MERGING - direction: ADD index: ... @@ -200,17 +200,42 @@ upsert descriptor #106 unexposedParentSchemaId: 101 - version: "4" + version: "5" -update progress of schema change job #1: "PostCommitPhase stage 5 of 6 with 1 BackfillType op pending" +update progress of schema change job #1: "PostCommitPhase stage 5 of 7 with 1 BackfillType op pending" commit transaction #6 begin transaction #7 -## PostCommitPhase stage 5 of 6 with 1 BackfillType op +## PostCommitPhase stage 5 of 7 with 1 BackfillType op merge temporary indexes [3] into backfilled indexes [2] in table #106 commit transaction #7 begin transaction #8 -## PostCommitPhase stage 6 of 6 with 1 ValidationType op -validate forward indexes [2] in table #106 +## PostCommitPhase stage 6 of 7 with 3 MutationType ops +upsert descriptor #106 + ... + formatVersion: 3 + id: 106 + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + mutations: + - direction: ADD + ... + version: 4 + mutationId: 1 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "5" + + version: "6" +update progress of schema change job #1: "PostCommitPhase stage 7 of 7 with 1 ValidationType op pending" commit transaction #8 begin transaction #9 +## PostCommitPhase stage 7 of 7 with 1 ValidationType op +validate forward indexes [2] in table #106 +commit transaction #9 +begin transaction #10 ## PostCommitNonRevertiblePhase stage 1 of 2 with 5 MutationType ops upsert descriptor #106 ... @@ -223,7 +248,7 @@ upsert descriptor #106 formatVersion: 3 id: 106 - modificationTime: - - wallTime: "1640995200000000006" + - wallTime: "1640995200000000008" + indexes: + - constraintId: 2 + createdExplicitly: true @@ -284,12 +309,12 @@ upsert descriptor #106 ... time: {} unexposedParentSchemaId: 101 - - version: "5" - + version: "6" + - version: "6" + + version: "7" 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 -commit transaction #9 -begin transaction #10 +commit transaction #10 +begin transaction #11 ## PostCommitNonRevertiblePhase stage 2 of 2 with 4 MutationType ops upsert descriptor #106 ... @@ -314,7 +339,7 @@ upsert descriptor #106 storeColumnNames: [] version: 4 - modificationTime: - - wallTime: "1640995200000000009" + - wallTime: "1640995200000000010" - mutations: - - direction: DROP - index: @@ -347,12 +372,12 @@ upsert descriptor #106 ... time: {} unexposedParentSchemaId: 101 - - version: "6" - + version: "7" + - version: "7" + + version: "8" write *eventpb.FinishSchemaChange to event log for descriptor 106 create job #2 (non-cancelable: true): "GC for " descriptor IDs: [106] update progress of schema change job #1: "all stages completed" -commit transaction #10 +commit transaction #11 notified job registry to adopt jobs: [2] # end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_column b/pkg/sql/schemachanger/testdata/explain/alter_table_add_column index 0cbbba914b63..eee6a8f4f7fc 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_column +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_column @@ -39,7 +39,7 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN │ ├── SetJobStateOnDescriptor {"DescriptorID":106,"Initialize":true} │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} ├── PostCommitPhase - │ ├── Stage 1 of 6 in PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── DELETE_ONLY → WRITE_ONLY Column:{DescID: 106, ColumnID: 2} │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT @@ -49,33 +49,40 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":3,"TableID":106} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 2 of 6 in PostCommitPhase + │ ├── Stage 2 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── BACKFILL_ONLY → BACKFILLED PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 1 Backfill operation │ │ └── BackfillIndex {"IndexID":2,"SourceIndexID":1,"TableID":106} - │ ├── Stage 3 of 6 in PostCommitPhase + │ ├── Stage 3 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── BACKFILLED → DELETE_ONLY PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 3 Mutation operations │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":2,"TableID":106} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 4 of 6 in PostCommitPhase + │ ├── Stage 4 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── DELETE_ONLY → MERGE_ONLY PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 3 Mutation operations - │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":2,"TableID":106} + │ │ ├── MakeBackfilledIndexMerging {"IndexID":2,"TableID":106} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 5 of 6 in PostCommitPhase + │ ├── Stage 5 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── MERGE_ONLY → MERGED PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 1 Backfill operation │ │ └── MergeIndex {"BackfilledIndexID":2,"TableID":106,"TemporaryIndexID":3} - │ └── Stage 6 of 6 in PostCommitPhase + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":2,"TableID":106} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase │ ├── 1 element transitioning toward PUBLIC - │ │ └── MERGED → VALIDATED PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── WRITE_ONLY → VALIDATED PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ └── 1 Validation operation │ └── ValidateUniqueIndex {"IndexID":2,"TableID":106} └── PostCommitNonRevertiblePhase diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_column_default_seq b/pkg/sql/schemachanger/testdata/explain/alter_table_add_column_default_seq index d2871ec85822..b701889d88b6 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_column_default_seq +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_column_default_seq @@ -41,7 +41,7 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN │ ├── SetJobStateOnDescriptor {"DescriptorID":107,"Initialize":true} │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} ├── PostCommitPhase - │ ├── Stage 1 of 6 in PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── DELETE_ONLY → WRITE_ONLY Column:{DescID: 106, ColumnID: 2} │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT @@ -52,12 +52,12 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":107} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 2 of 6 in PostCommitPhase + │ ├── Stage 2 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── BACKFILL_ONLY → BACKFILLED PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 1 Backfill operation │ │ └── BackfillIndex {"IndexID":2,"SourceIndexID":1,"TableID":106} - │ ├── Stage 3 of 6 in PostCommitPhase + │ ├── Stage 3 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── BACKFILLED → DELETE_ONLY PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 4 Mutation operations @@ -65,22 +65,30 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":107} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 4 of 6 in PostCommitPhase + │ ├── Stage 4 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── DELETE_ONLY → MERGE_ONLY PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 4 Mutation operations - │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":2,"TableID":106} + │ │ ├── MakeBackfilledIndexMerging {"IndexID":2,"TableID":106} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":107} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 5 of 6 in PostCommitPhase + │ ├── Stage 5 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── MERGE_ONLY → MERGED PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 1 Backfill operation │ │ └── MergeIndex {"BackfilledIndexID":2,"TableID":106,"TemporaryIndexID":3} - │ └── Stage 6 of 6 in PostCommitPhase + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── 4 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":2,"TableID":106} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":107} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase │ ├── 1 element transitioning toward PUBLIC - │ │ └── MERGED → VALIDATED PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── WRITE_ONLY → VALIDATED PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ └── 1 Validation operation │ └── ValidateUniqueIndex {"IndexID":2,"TableID":106} └── PostCommitNonRevertiblePhase diff --git a/pkg/sql/schemachanger/testdata/explain/create_index b/pkg/sql/schemachanger/testdata/explain/create_index index 274fbce7a8e4..f23b8ce317e0 100644 --- a/pkg/sql/schemachanger/testdata/explain/create_index +++ b/pkg/sql/schemachanger/testdata/explain/create_index @@ -29,40 +29,47 @@ Schema change plan for CREATE INDEX ‹idx1› ON ‹defaultdb›.‹public›. │ ├── SetJobStateOnDescriptor {"DescriptorID":106,"Initialize":true} │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} ├── PostCommitPhase - │ ├── Stage 1 of 6 in PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 106, IndexID: 3, SourceIndexID: 1} │ │ └── 3 Mutation operations │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":3,"TableID":106} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 2 of 6 in PostCommitPhase + │ ├── Stage 2 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── BACKFILL_ONLY → BACKFILLED SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 1 Backfill operation │ │ └── BackfillIndex {"IndexID":2,"SourceIndexID":1,"TableID":106} - │ ├── Stage 3 of 6 in PostCommitPhase + │ ├── Stage 3 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── BACKFILLED → DELETE_ONLY SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 3 Mutation operations │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":2,"TableID":106} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 4 of 6 in PostCommitPhase + │ ├── Stage 4 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── DELETE_ONLY → MERGE_ONLY SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 3 Mutation operations - │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":2,"TableID":106} + │ │ ├── MakeBackfilledIndexMerging {"IndexID":2,"TableID":106} │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} - │ ├── Stage 5 of 6 in PostCommitPhase + │ ├── Stage 5 of 7 in PostCommitPhase │ │ ├── 1 element transitioning toward PUBLIC │ │ │ └── MERGE_ONLY → MERGED SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} │ │ └── 1 Backfill operation │ │ └── MergeIndex {"BackfilledIndexID":2,"TableID":106,"TemporaryIndexID":3} - │ └── Stage 6 of 6 in PostCommitPhase + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":2,"TableID":106} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase │ ├── 1 element transitioning toward PUBLIC - │ │ └── MERGED → VALIDATED SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── WRITE_ONLY → VALIDATED SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} │ └── 1 Validation operation │ └── ValidateUniqueIndex {"IndexID":2,"TableID":106} └── PostCommitNonRevertiblePhase diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_column b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_column index 56dc6121368c..00f78837c243 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_column +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_column @@ -196,7 +196,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN j INT NOT NULL DEFAU │ DescriptorIDs: │ - 106 │ JobID: 1 -│ RunningStatus: PostCommitPhase stage 1 of 6 with 2 MutationType ops pending +│ RunningStatus: PostCommitPhase stage 1 of 7 with 2 MutationType ops pending │ Statements: │ - statement: ALTER TABLE db.public.tbl ADD COLUMN j INT8 NOT NULL DEFAULT 42 │ redactedstatement: ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN ‹j› INT8 NOT NULL @@ -205,7 +205,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN j INT NOT NULL DEFAU │ ├── • PostCommitPhase │ │ -│ ├── • Stage 1 of 6 in PostCommitPhase +│ ├── • Stage 1 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -220,6 +220,9 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN j INT NOT NULL DEFAU │ │ │ └── • TemporaryIndex:{DescID: 106, IndexID: 3, SourceIndexID: 1} │ │ │ │ DELETE_ONLY → WRITE_ONLY │ │ │ │ +│ │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 2} +│ │ │ │ rule: "column is WRITE_ONLY before temporary index is WRITE_ONLY" +│ │ │ │ │ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 3} │ │ │ │ rule: "index-column added to index before temp index receives writes" │ │ │ │ @@ -241,9 +244,9 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN j INT NOT NULL DEFAU │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 2 of 6 with 1 BackfillType op pending +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending │ │ -│ ├── • Stage 2 of 6 in PostCommitPhase +│ ├── • Stage 2 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -266,7 +269,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN j INT NOT NULL DEFAU │ │ SourceIndexID: 1 │ │ TableID: 106 │ │ -│ ├── • Stage 3 of 6 in PostCommitPhase +│ ├── • Stage 3 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -284,9 +287,9 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN j INT NOT NULL DEFAU │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 4 of 6 with 1 MutationType op pending +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending │ │ -│ ├── • Stage 4 of 6 in PostCommitPhase +│ ├── • Stage 4 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -295,7 +298,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN j INT NOT NULL DEFAU │ │ │ │ │ └── • 3 Mutation operations │ │ │ -│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ ├── • MakeBackfilledIndexMerging │ │ │ IndexID: 2 │ │ │ TableID: 106 │ │ │ @@ -304,9 +307,9 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN j INT NOT NULL DEFAU │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 5 of 6 with 1 BackfillType op pending +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending │ │ -│ ├── • Stage 5 of 6 in PostCommitPhase +│ ├── • Stage 5 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -320,12 +323,32 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN j INT NOT NULL DEFAU │ │ TableID: 106 │ │ TemporaryIndexID: 3 │ │ -│ └── • Stage 6 of 6 in PostCommitPhase +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 2 +│ │ │ TableID: 106 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 106 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} -│ │ MERGED → VALIDATED +│ │ WRITE_ONLY → VALIDATED │ │ │ └── • 1 Validation operation │ │ @@ -360,7 +383,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN j INT NOT NULL DEFAU │ │ │ │ WRITE_ONLY → PUBLIC │ │ │ │ │ │ │ └── • Precedence dependency from PUBLIC PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} - │ │ │ rule: "column depends on primary index" + │ │ │ rule: "adding column depends on primary index" │ │ │ │ │ ├── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ VALIDATED → PUBLIC diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_column_default_seq b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_column_default_seq index df8b2343a128..6512f3a330f5 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_column_default_seq +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_column_default_seq @@ -209,7 +209,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN l INT NOT NULL DEFAU │ - 106 │ - 107 │ JobID: 1 -│ RunningStatus: PostCommitPhase stage 1 of 6 with 2 MutationType ops pending +│ RunningStatus: PostCommitPhase stage 1 of 7 with 2 MutationType ops pending │ Statements: │ - statement: ALTER TABLE db.public.tbl ADD COLUMN l INT8 NOT NULL DEFAULT nextval('db.public.sq1') │ redactedstatement: ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN ‹l› INT8 NOT NULL @@ -218,7 +218,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN l INT NOT NULL DEFAU │ ├── • PostCommitPhase │ │ -│ ├── • Stage 1 of 6 in PostCommitPhase +│ ├── • Stage 1 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -233,6 +233,9 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN l INT NOT NULL DEFAU │ │ │ └── • TemporaryIndex:{DescID: 106, IndexID: 3, SourceIndexID: 1} │ │ │ │ DELETE_ONLY → WRITE_ONLY │ │ │ │ +│ │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 2} +│ │ │ │ rule: "column is WRITE_ONLY before temporary index is WRITE_ONLY" +│ │ │ │ │ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 3} │ │ │ │ rule: "index-column added to index before temp index receives writes" │ │ │ │ @@ -257,9 +260,9 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN l INT NOT NULL DEFAU │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 2 of 6 with 1 BackfillType op pending +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending │ │ -│ ├── • Stage 2 of 6 in PostCommitPhase +│ ├── • Stage 2 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -282,7 +285,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN l INT NOT NULL DEFAU │ │ SourceIndexID: 1 │ │ TableID: 106 │ │ -│ ├── • Stage 3 of 6 in PostCommitPhase +│ ├── • Stage 3 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -303,9 +306,9 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN l INT NOT NULL DEFAU │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 4 of 6 with 1 MutationType op pending +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending │ │ -│ ├── • Stage 4 of 6 in PostCommitPhase +│ ├── • Stage 4 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -314,7 +317,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN l INT NOT NULL DEFAU │ │ │ │ │ └── • 4 Mutation operations │ │ │ -│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ ├── • MakeBackfilledIndexMerging │ │ │ IndexID: 2 │ │ │ TableID: 106 │ │ │ @@ -326,9 +329,9 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN l INT NOT NULL DEFAU │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 5 of 6 with 1 BackfillType op pending +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending │ │ -│ ├── • Stage 5 of 6 in PostCommitPhase +│ ├── • Stage 5 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -342,12 +345,35 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN l INT NOT NULL DEFAU │ │ TableID: 106 │ │ TemporaryIndexID: 3 │ │ -│ └── • Stage 6 of 6 in PostCommitPhase +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 4 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 2 +│ │ │ TableID: 106 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 106 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 107 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} -│ │ MERGED → VALIDATED +│ │ WRITE_ONLY → VALIDATED │ │ │ └── • 1 Validation operation │ │ @@ -382,7 +408,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE db.public.tbl ADD COLUMN l INT NOT NULL DEFAU │ │ │ │ WRITE_ONLY → PUBLIC │ │ │ │ │ │ │ └── • Precedence dependency from PUBLIC PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} - │ │ │ rule: "column depends on primary index" + │ │ │ rule: "adding column depends on primary index" │ │ │ │ │ ├── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ VALIDATED → PUBLIC diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/create_index b/pkg/sql/schemachanger/testdata/explain_verbose/create_index index 6a61474749be..e3120fe384e6 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/create_index +++ b/pkg/sql/schemachanger/testdata/explain_verbose/create_index @@ -102,7 +102,7 @@ EXPLAIN (ddl, verbose) CREATE INDEX idx1 ON t (v) WHERE (v = 'a'); │ DescriptorIDs: │ - 106 │ JobID: 1 -│ RunningStatus: PostCommitPhase stage 1 of 6 with 1 MutationType op pending +│ RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending │ Statements: │ - statement: CREATE INDEX idx1 ON t (v) WHERE (v = 'a') │ redactedstatement: CREATE INDEX ‹idx1› ON ‹defaultdb›.‹public›.‹t› (‹v›) WHERE (‹v› @@ -111,7 +111,7 @@ EXPLAIN (ddl, verbose) CREATE INDEX idx1 ON t (v) WHERE (v = 'a'); │ ├── • PostCommitPhase │ │ -│ ├── • Stage 1 of 6 in PostCommitPhase +│ ├── • Stage 1 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT │ │ │ │ @@ -135,9 +135,9 @@ EXPLAIN (ddl, verbose) CREATE INDEX idx1 ON t (v) WHERE (v = 'a'); │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 2 of 6 with 1 BackfillType op pending +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending │ │ -│ ├── • Stage 2 of 6 in PostCommitPhase +│ ├── • Stage 2 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -160,7 +160,7 @@ EXPLAIN (ddl, verbose) CREATE INDEX idx1 ON t (v) WHERE (v = 'a'); │ │ SourceIndexID: 1 │ │ TableID: 106 │ │ -│ ├── • Stage 3 of 6 in PostCommitPhase +│ ├── • Stage 3 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -178,9 +178,9 @@ EXPLAIN (ddl, verbose) CREATE INDEX idx1 ON t (v) WHERE (v = 'a'); │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 4 of 6 with 1 MutationType op pending +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending │ │ -│ ├── • Stage 4 of 6 in PostCommitPhase +│ ├── • Stage 4 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -189,7 +189,7 @@ EXPLAIN (ddl, verbose) CREATE INDEX idx1 ON t (v) WHERE (v = 'a'); │ │ │ │ │ └── • 3 Mutation operations │ │ │ -│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ ├── • MakeBackfilledIndexMerging │ │ │ IndexID: 2 │ │ │ TableID: 106 │ │ │ @@ -198,9 +198,9 @@ EXPLAIN (ddl, verbose) CREATE INDEX idx1 ON t (v) WHERE (v = 'a'); │ │ │ │ │ └── • UpdateSchemaChangerJob │ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 5 of 6 with 1 BackfillType op pending +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending │ │ -│ ├── • Stage 5 of 6 in PostCommitPhase +│ ├── • Stage 5 of 7 in PostCommitPhase │ │ │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ @@ -214,12 +214,32 @@ EXPLAIN (ddl, verbose) CREATE INDEX idx1 ON t (v) WHERE (v = 'a'); │ │ TableID: 106 │ │ TemporaryIndexID: 3 │ │ -│ └── • Stage 6 of 6 in PostCommitPhase +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 2 +│ │ │ TableID: 106 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 106 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase │ │ │ ├── • 1 element transitioning toward PUBLIC │ │ │ │ │ └── • SecondaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1} -│ │ MERGED → VALIDATED +│ │ WRITE_ONLY → VALIDATED │ │ │ └── • 1 Validation operation │ │ diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_hash_sharded_index b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_hash_sharded_index index dd8bea84ac89..5b534801757b 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_hash_sharded_index +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_hash_sharded_index @@ -188,9 +188,12 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_16, ColumnID: 3} │ │ │ rule: "dependents removed before column" │ │ │ - │ │ └── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} - │ │ rule: "dependents removed before column" - │ │ rule: "column type removed right before column when not dropping relation" + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ └── • Precedence dependency from ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ rule: "indexes containing columns reach absent before column" │ │ │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} │ │ │ PUBLIC → ABSENT diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_partial_expression_index b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_partial_expression_index index 6f7cd1f519d5..a758463eaff7 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_partial_expression_index +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_partial_expression_index @@ -160,9 +160,12 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 3} │ │ │ rule: "dependents removed before column" │ │ │ - │ │ └── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} - │ │ rule: "dependents removed before column" - │ │ rule: "column type removed right before column when not dropping relation" + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ └── • Precedence dependency from ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ rule: "indexes containing columns reach absent before column" │ │ │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} │ │ │ PUBLIC → ABSENT From b20acd808bc00d45f4610393aa9d58af7daafe54 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Mon, 18 Jul 2022 19:08:32 -0400 Subject: [PATCH 3/6] sql,sqlerrors: extract some errors for reuse Release note: None --- pkg/sql/alter_table.go | 3 +- pkg/sql/catalog/schemaexpr/BUILD.bazel | 1 + pkg/sql/catalog/schemaexpr/computed_column.go | 8 +--- pkg/sql/drop_table.go | 6 +-- pkg/sql/sqlerrors/errors.go | 39 +++++++++++++++++++ 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/pkg/sql/alter_table.go b/pkg/sql/alter_table.go index c9356bf8922b..55b33720361b 100644 --- a/pkg/sql/alter_table.go +++ b/pkg/sql/alter_table.go @@ -1631,8 +1631,7 @@ func dropColumnImpl( } if tableDesc.GetPrimaryIndex().CollectKeyColumnIDs().Contains(colToDrop.GetID()) { - return nil, pgerror.Newf(pgcode.InvalidColumnReference, - "column %q is referenced by the primary key", colToDrop.GetName()) + return nil, sqlerrors.NewColumnReferencedByPrimaryKeyError(colToDrop.GetName()) } var idxNamesToDelete []string for _, idx := range tableDesc.NonDropIndexes() { diff --git a/pkg/sql/catalog/schemaexpr/BUILD.bazel b/pkg/sql/catalog/schemaexpr/BUILD.bazel index 9009c5d6a930..f4203fd6424e 100644 --- a/pkg/sql/catalog/schemaexpr/BUILD.bazel +++ b/pkg/sql/catalog/schemaexpr/BUILD.bazel @@ -35,6 +35,7 @@ go_library( "//pkg/sql/sem/tree/treebin", "//pkg/sql/sem/volatility", "//pkg/sql/sessiondata", + "//pkg/sql/sqlerrors", "//pkg/sql/types", "//pkg/util/errorutil/unimplemented", "@com_github_cockroachdb_errors//:errors", diff --git a/pkg/sql/catalog/schemaexpr/computed_column.go b/pkg/sql/catalog/schemaexpr/computed_column.go index 85cde994608a..70ecccef73db 100644 --- a/pkg/sql/catalog/schemaexpr/computed_column.go +++ b/pkg/sql/catalog/schemaexpr/computed_column.go @@ -24,6 +24,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sem/transform" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sem/volatility" + "github.com/cockroachdb/cockroach/pkg/sql/sqlerrors" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" "github.com/cockroachdb/errors" @@ -166,12 +167,7 @@ func ValidateColumnHasNoDependents(desc catalog.TableDescriptor, col catalog.Col err = iterColDescriptors(desc, expr, func(colVar catalog.Column) error { if colVar.GetID() == col.GetID() { - return pgerror.Newf( - pgcode.InvalidColumnReference, - "column %q is referenced by computed column %q", - col.GetName(), - c.GetName(), - ) + return sqlerrors.NewColumnReferencedByComputedColumnError(col.GetName(), c.GetName()) } return nil }) diff --git a/pkg/sql/drop_table.go b/pkg/sql/drop_table.go index 431f8df3c09e..6a853d514287 100644 --- a/pkg/sql/drop_table.go +++ b/pkg/sql/drop_table.go @@ -21,11 +21,10 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" "github.com/cockroachdb/cockroach/pkg/sql/descmetadata" - "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/sem/tree" + "github.com/cockroachdb/cockroach/pkg/sql/sqlerrors" "github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/log/eventpb" @@ -209,8 +208,7 @@ func (p *planner) canRemoveFKBackreference( return err } if behavior != tree.DropCascade { - return pgerror.Newf(pgcode.DependentObjectsStillExist, - "%q is referenced by foreign key from table %q", from, table.Name) + return sqlerrors.NewUniqueConstraintReferencedByForeignKeyError(from, table.GetName()) } // Check to see whether we're allowed to edit the table that has a // foreign key constraint on the table that we're dropping right now. diff --git a/pkg/sql/sqlerrors/errors.go b/pkg/sql/sqlerrors/errors.go index 97ee2aaba406..33bd6ee32bb5 100644 --- a/pkg/sql/sqlerrors/errors.go +++ b/pkg/sql/sqlerrors/errors.go @@ -237,6 +237,45 @@ func NewDependentObjectErrorf(format string, args ...interface{}) error { return pgerror.Newf(pgcode.DependentObjectsStillExist, format, args...) } +// NewColumnReferencedByPrimaryKeyError is returned when attempting to drop a +// column which is a part of the table's primary key. +// +// Note that this limitation is not fundamental; in postgres when dropping a +// primary key column, it would silently drop the primary key constraint. At +// the time of writing, cockroach does not permit dropping a primary key +// constraint as it may require populating a new implicit rowid column for the +// implicit primary key we use. +func NewColumnReferencedByPrimaryKeyError(colName string) error { + return pgerror.Newf(pgcode.InvalidColumnReference, + "column %q is referenced by the primary key", colName) +} + +// NewColumnReferencedByComputedColumnError is returned when dropping a column +// and that column being dropped is referenced by a computed column. Note that +// the cockroach behavior where this error is returned does not match the +// postgres behavior. +func NewColumnReferencedByComputedColumnError(droppingColumn, computedColumn string) error { + return pgerror.Newf( + pgcode.InvalidColumnReference, + "column %q is referenced by computed column %q", + droppingColumn, + computedColumn, + ) +} + +// NewUniqueConstraintReferencedByForeignKeyError generates an error to be +// returned when dropping a unique constraint that is relied upon by an +// inbound foreign key constraint. +func NewUniqueConstraintReferencedByForeignKeyError( + uniqueConstraintOrIndexToDrop, tableName string, +) error { + return pgerror.Newf( + pgcode.DependentObjectsStillExist, + "%q is referenced by foreign key from table %q", + uniqueConstraintOrIndexToDrop, tableName, + ) +} + // NewRangeUnavailableError creates an unavailable range error. func NewRangeUnavailableError(rangeID roachpb.RangeID, origErr error) error { return pgerror.Wrapf(origErr, pgcode.RangeUnavailable, "key range id:%d is unavailable", rangeID) From f59548587a76571ec591d46786cacebbb375d881 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Mon, 18 Jul 2022 19:12:55 -0400 Subject: [PATCH 4/6] sql/rowenc: compute primary index encoding columns correctly This commit ensures that the correct primary index entry is encoded when building an entry for a primary index encoded index which does not include every column in the table. This is the case when dropping a column using the declarative schema changer. Release note: None --- pkg/sql/rowenc/index_encoding.go | 41 ++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/pkg/sql/rowenc/index_encoding.go b/pkg/sql/rowenc/index_encoding.go index c08c138a8e5a..e0db413be78c 100644 --- a/pkg/sql/rowenc/index_encoding.go +++ b/pkg/sql/rowenc/index_encoding.go @@ -1042,7 +1042,9 @@ func EncodePrimaryIndex( if containsNull { return nil, MakeNullPKError(tableDesc, index, colMap, values) } - indexedColumns := index.CollectKeyColumnIDs() + + storedColumns := getStoredColumnsForPrimaryIndex(index, colMap) + var entryValue []byte indexEntries := make([]IndexEntry, 0, tableDesc.NumFamilies()) var columnsToEncode []valueEncodedColumn @@ -1077,7 +1079,7 @@ func EncodePrimaryIndex( } for _, colID := range family.ColumnIDs { - if !indexedColumns.Contains(colID) { + if storedColumns.Contains(colID) { columnsToEncode = append(columnsToEncode, valueEncodedColumn{id: colID}) continue } @@ -1113,6 +1115,41 @@ func EncodePrimaryIndex( return indexEntries, nil } +// getStoredColumnsForPrimaryIndex computes the set of columns stored in this +// primary index's value for encoding. Note that EncodePrimaryIndex will utilize +// this set to construct the value, but will augment this with the set of +// key columns which are composite encoded; this is just the set of columns +// stored in the primary index value which are not featured in the index key +// whatsoever. +// +// colMap is expected to include all columns in the table. +func getStoredColumnsForPrimaryIndex( + index catalog.Index, colMap catalog.TableColMap, +) catalog.TableColSet { + + // It should be rare to never that we come across an index which is encoded + // as a primary index but with a version older than this version. + // Nevertheless, for safety, we assume at that version that the stored + // columns set is not populated and instead we defer to the colMap to compute + // the complete set before subtracting the key columns. + if index.GetVersion() < descpb.PrimaryIndexWithStoredColumnsVersion { + var allColumn catalog.TableColSet + colMap.ForEach(func(colID descpb.ColumnID, _ int) { + allColumn.Add(colID) + }) + return allColumn.Difference(index.CollectKeyColumnIDs()) + } + + // Note that the definition of Primary according to the catalog.Index method + // is that the index is installed as the primary index of the table, not + // that it has a primary index encoding. We must call the appropriate + // method based on this distinction to get the desired set of columns. + if !index.Primary() { + return index.CollectSecondaryStoredColumnIDs() + } + return index.CollectPrimaryStoredColumnIDs() +} + // MakeNullPKError generates an error when the value for a primary key column is // null. func MakeNullPKError( From 89422e89e3f4e8b9f5cceb3450c291cb468034a6 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Mon, 18 Jul 2022 19:15:16 -0400 Subject: [PATCH 5/6] sql/logictest,execbuilder: update logic tests to avoid index IDs These hard-coded index IDs embed assumptions which will be violated by the new DROP COLUMN protocol. Release note: None --- .../testdata/logic_test/numeric_references | 16 ++++++++++++-- pkg/sql/opt/exec/execbuilder/testdata/select | 22 ++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/numeric_references b/pkg/sql/logictest/testdata/logic_test/numeric_references index c261f59158f2..fd724597b03a 100644 --- a/pkg/sql/logictest/testdata/logic_test/numeric_references +++ b/pkg/sql/logictest/testdata/logic_test/numeric_references @@ -94,15 +94,27 @@ SELECT * FROM [$num_ref_id(4,3,1) AS num_ref_alias] 200 20 2 300 30 3 +let $num_ref_bc +SELECT index_id + FROM crdb_internal.table_indexes + WHERE descriptor_id = $num_ref_id + AND index_name = 'bc'; + +let $num_ref_pkey +SELECT index_id + FROM crdb_internal.table_indexes + WHERE descriptor_id = $num_ref_id + AND index_name = 'num_ref_pkey'; + query I rowsort -SELECT * FROM [$num_ref_id(4) AS num_ref_alias]@[2] +SELECT * FROM [$num_ref_id(4) AS num_ref_alias]@[$num_ref_bc] ---- 101 200 300 query I rowsort -SELECT * FROM [$num_ref_id(1) AS num_ref_alias]@[1] +SELECT * FROM [$num_ref_id(1) AS num_ref_alias]@[$num_ref_pkey] ---- 1 2 diff --git a/pkg/sql/opt/exec/execbuilder/testdata/select b/pkg/sql/opt/exec/execbuilder/testdata/select index 033e4d1b0e3f..59a9f3896be7 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/select +++ b/pkg/sql/opt/exec/execbuilder/testdata/select @@ -189,8 +189,18 @@ vectorized: true table: num_ref@bc spans: FULL SCAN +let $num_ref_bc +SELECT index_id + FROM crdb_internal.table_indexes + WHERE descriptor_id = $t_id AND index_name = 'bc'; + +let $num_ref_pkey +SELECT index_id + FROM crdb_internal.table_indexes + WHERE descriptor_id = $t_id AND index_name = 'num_ref_pkey'; + query T -EXPLAIN (VERBOSE) SELECT * FROM [$t_id(1) AS num_ref_alias]@[1] +EXPLAIN (VERBOSE) SELECT * FROM [$t_id(1) AS num_ref_alias]@[$num_ref_pkey] ---- distribution: local vectorized: true @@ -202,7 +212,7 @@ vectorized: true spans: FULL SCAN query T -EXPLAIN (VERBOSE) SELECT * FROM [$t_id(1) AS num_ref_alias]@[2] +EXPLAIN (VERBOSE) SELECT * FROM [$t_id(1) AS num_ref_alias]@[$num_ref_bc] ---- distribution: local vectorized: true @@ -214,7 +224,7 @@ vectorized: true spans: FULL SCAN query T -EXPLAIN (VERBOSE) SELECT * FROM [$t_id(3) AS num_ref_alias]@[1] +EXPLAIN (VERBOSE) SELECT * FROM [$t_id(3) AS num_ref_alias]@[$num_ref_pkey] ---- distribution: local vectorized: true @@ -226,7 +236,7 @@ vectorized: true spans: FULL SCAN query T -EXPLAIN (VERBOSE) SELECT * FROM [$t_id(3) AS num_ref_alias]@[2] +EXPLAIN (VERBOSE) SELECT * FROM [$t_id(3) AS num_ref_alias]@[$num_ref_bc] ---- distribution: local vectorized: true @@ -238,7 +248,7 @@ vectorized: true spans: FULL SCAN query T -EXPLAIN (VERBOSE) SELECT * FROM [$t_id(4) AS num_ref_alias]@[1] +EXPLAIN (VERBOSE) SELECT * FROM [$t_id(4) AS num_ref_alias]@[$num_ref_pkey] ---- distribution: local vectorized: true @@ -250,7 +260,7 @@ vectorized: true spans: FULL SCAN query T -EXPLAIN (VERBOSE) SELECT * FROM [$t_id(4) AS num_ref_alias]@[2] +EXPLAIN (VERBOSE) SELECT * FROM [$t_id(4) AS num_ref_alias]@[$num_ref_bc] ---- distribution: local vectorized: true From 07ce7b155892127bde9fff3d976897419d6cd97a Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Mon, 18 Jul 2022 19:17:06 -0400 Subject: [PATCH 6/6] sql/schemachanger: implement `ALTER TABLE ... DROP COLUMN` This is the initial implementation of `ALTER TABLE ... DROP COLUMN` in the declarative schema changer. It explicitly does not have the case of adding and dropping columns from the same table in the same transaction. It also omits: 1) Dropping columns related to multi-region tables 2) Dropping columns with row-level TTLs 3) Dropping columns involved in UNIQUE WITHOUT INDEX constraints 4) Dropping columns involved in CHECK constraints 5) Dropping columns involved in FOREIGN KEY constraints Fixes #84072. Release note: None --- .../testdata/benchmark_expectations | 6 +- pkg/ccl/changefeedccl/changefeed_test.go | 11 +- .../schemafeed/testdata/drop_column | 13 +- pkg/sql/as_of_test.go | 7 +- pkg/sql/backfill.go | 6 +- pkg/sql/catalog/descriptor.go | 3 + pkg/sql/catalog/table_elements.go | 13 +- pkg/sql/catalog/tabledesc/index.go | 12 +- pkg/sql/catalog/tabledesc/structured.go | 27 +- .../logictest/testdata/logic_test/event_log | 7 +- .../logictest/testdata/logic_test/sequences | 4 +- pkg/sql/rowenc/index_encoding.go | 4 +- pkg/sql/schema_changer_test.go | 80 +- pkg/sql/schemachanger/BUILD.bazel | 2 +- pkg/sql/schemachanger/scbuild/BUILD.bazel | 1 + .../schemachanger/scbuild/builder_state.go | 4 +- .../scbuild/internal/scbuildstmt/BUILD.bazel | 1 + .../internal/scbuildstmt/alter_table.go | 3 +- .../scbuildstmt/alter_table_add_column.go | 19 +- .../scbuildstmt/alter_table_drop_column.go | 622 ++++++++++++ .../internal/scbuildstmt/create_index.go | 6 +- .../internal/scbuildstmt/drop_index.go | 14 +- .../scbuild/internal/scbuildstmt/helpers.go | 25 +- .../scbuild/testdata/alter_table_drop_column | 177 ++++ .../testdata/unimplemented_alter_table | 34 +- .../scplan/internal/scstage/build.go | 37 +- pkg/sql/schemachanger/sctest/cumulative.go | 8 +- .../testdata/end_to_end/drop_column_basic | 517 ++++++++++ .../end_to_end/drop_column_computed_index | 631 ++++++++++++ ...op_column_create_index_separate_statements | 930 ++++++++++++++++++ .../end_to_end/drop_column_unique_index | 550 +++++++++++ .../end_to_end/drop_column_with_index | 586 +++++++++++ .../drop_multiple_columns_separate_statements | 790 +++++++++++++++ .../testdata/explain/drop_column_basic | 121 +++ .../explain/drop_column_computed_index | 145 +++ ..._column_create_index_separate_statements.0 | 153 +++ ..._column_create_index_separate_statements.1 | 188 ++++ .../testdata/explain/drop_column_unique_index | 138 +++ .../testdata/explain/drop_column_with_index | 135 +++ ...rop_multiple_columns_separate_statements.0 | 153 +++ ...rop_multiple_columns_separate_statements.1 | 144 +++ .../explain_verbose/drop_column_basic | 473 +++++++++ .../drop_column_computed_index | 642 ++++++++++++ ..._column_create_index_separate_statements.0 | 708 +++++++++++++ ..._column_create_index_separate_statements.1 | 804 +++++++++++++++ .../explain_verbose/drop_column_unique_index | 582 +++++++++++ .../explain_verbose/drop_column_with_index | 572 +++++++++++ ...rop_multiple_columns_separate_statements.0 | 708 +++++++++++++ ...rop_multiple_columns_separate_statements.1 | 660 +++++++++++++ 49 files changed, 11366 insertions(+), 110 deletions(-) create mode 100644 pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go create mode 100644 pkg/sql/schemachanger/scbuild/testdata/alter_table_drop_column create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/drop_column_basic create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/drop_column_computed_index create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/drop_column_create_index_separate_statements create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/drop_column_unique_index create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_index create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/drop_multiple_columns_separate_statements create mode 100644 pkg/sql/schemachanger/testdata/explain/drop_column_basic create mode 100644 pkg/sql/schemachanger/testdata/explain/drop_column_computed_index create mode 100644 pkg/sql/schemachanger/testdata/explain/drop_column_create_index_separate_statements.0 create mode 100644 pkg/sql/schemachanger/testdata/explain/drop_column_create_index_separate_statements.1 create mode 100644 pkg/sql/schemachanger/testdata/explain/drop_column_unique_index create mode 100644 pkg/sql/schemachanger/testdata/explain/drop_column_with_index create mode 100644 pkg/sql/schemachanger/testdata/explain/drop_multiple_columns_separate_statements.0 create mode 100644 pkg/sql/schemachanger/testdata/explain/drop_multiple_columns_separate_statements.1 create mode 100644 pkg/sql/schemachanger/testdata/explain_verbose/drop_column_basic create mode 100644 pkg/sql/schemachanger/testdata/explain_verbose/drop_column_computed_index create mode 100644 pkg/sql/schemachanger/testdata/explain_verbose/drop_column_create_index_separate_statements.0 create mode 100644 pkg/sql/schemachanger/testdata/explain_verbose/drop_column_create_index_separate_statements.1 create mode 100644 pkg/sql/schemachanger/testdata/explain_verbose/drop_column_unique_index create mode 100644 pkg/sql/schemachanger/testdata/explain_verbose/drop_column_with_index create mode 100644 pkg/sql/schemachanger/testdata/explain_verbose/drop_multiple_columns_separate_statements.0 create mode 100644 pkg/sql/schemachanger/testdata/explain_verbose/drop_multiple_columns_separate_statements.1 diff --git a/pkg/bench/rttanalysis/testdata/benchmark_expectations b/pkg/bench/rttanalysis/testdata/benchmark_expectations index f226235b5be3..94c2fdfef09b 100644 --- a/pkg/bench/rttanalysis/testdata/benchmark_expectations +++ b/pkg/bench/rttanalysis/testdata/benchmark_expectations @@ -15,9 +15,9 @@ exp,benchmark 19,AlterTableConfigureZone/alter_table_configure_zone_5_replicas 19,AlterTableConfigureZone/alter_table_configure_zone_7_replicas_ 19,AlterTableConfigureZone/alter_table_configure_zone_ranges -14,AlterTableDropColumn/alter_table_drop_1_column -15,AlterTableDropColumn/alter_table_drop_2_columns -16,AlterTableDropColumn/alter_table_drop_3_columns +18,AlterTableDropColumn/alter_table_drop_1_column +18,AlterTableDropColumn/alter_table_drop_2_columns +18,AlterTableDropColumn/alter_table_drop_3_columns 13,AlterTableDropConstraint/alter_table_drop_1_check_constraint 13,AlterTableDropConstraint/alter_table_drop_2_check_constraints 13,AlterTableDropConstraint/alter_table_drop_3_check_constraints diff --git a/pkg/ccl/changefeedccl/changefeed_test.go b/pkg/ccl/changefeedccl/changefeed_test.go index e88deca7cac9..a25b98cadd64 100644 --- a/pkg/ccl/changefeedccl/changefeed_test.go +++ b/pkg/ccl/changefeedccl/changefeed_test.go @@ -2681,6 +2681,12 @@ func TestChangefeedStopOnSchemaChange(t *testing.T) { }) }) t.Run("drop column", func(t *testing.T) { + // Sinkless feeds are not currently able to restart in the face of + // any schema changes. Dropping a column in the declarative schema + // changer means that an extra error will occur. + if _, isSinkless := f.(*sinklessFeedFactory); isSinkless { + skip.WithIssue(t, 84511) + } sqlDB.Exec(t, `CREATE TABLE drop_column (a INT PRIMARY KEY, b INT)`) defer sqlDB.Exec(t, `DROP TABLE drop_column`) sqlDB.Exec(t, `INSERT INTO drop_column VALUES (0, NULL)`) @@ -2697,12 +2703,7 @@ func TestChangefeedStopOnSchemaChange(t *testing.T) { dropColumn = feed(t, f, `CREATE CHANGEFEED FOR drop_column `+ `WITH schema_change_events='column_changes', schema_change_policy='stop', cursor = '`+tsStr+`'`) defer closeFeed(t, dropColumn) - // NB: You might expect to only see the new row here but we'll see them - // all because we cannot distinguish between the index backfill and - // foreground writes. See #35738. assertPayloads(t, dropColumn, []string{ - `drop_column: [0]->{"after": {"a": 0}}`, - `drop_column: [1]->{"after": {"a": 1}}`, `drop_column: [2]->{"after": {"a": 2}}`, }) }) diff --git a/pkg/ccl/changefeedccl/schemafeed/testdata/drop_column b/pkg/ccl/changefeedccl/schemafeed/testdata/drop_column index df51ec2788fc..95a097d75abb 100644 --- a/pkg/ccl/changefeedccl/schemafeed/testdata/drop_column +++ b/pkg/ccl/changefeedccl/schemafeed/testdata/drop_column @@ -14,7 +14,12 @@ pop f=1 ---- t 1->2: DropColumn t 2->3: Unknown -t 3->4: AddHiddenColumn +t 3->4: Unknown +t 4->5: Unknown +t 5->6: Unknown +t 6->7: PrimaryKeyChange (no column changes) +t 7->8: Unknown +t 8->9: AddHiddenColumn exec SET use_declarative_schema_changer=off; @@ -23,6 +28,6 @@ ALTER TABLE t DROP COLUMN k; pop f=1 ---- -t 4->5: DropColumn -t 5->6: Unknown -t 6->7: AddHiddenColumn +t 9->10: DropColumn +t 10->11: Unknown +t 11->12: AddHiddenColumn diff --git a/pkg/sql/as_of_test.go b/pkg/sql/as_of_test.go index 3f799543cfad..d148e419eafa 100644 --- a/pkg/sql/as_of_test.go +++ b/pkg/sql/as_of_test.go @@ -36,10 +36,15 @@ func TestAsOfTime(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) + ctx, cancel := context.WithCancel(context.Background()) params, _ := tests.CreateTestServerParams() - params.Knobs.GCJob = &sql.GCJobTestingKnobs{RunBeforeResume: func(_ jobspb.JobID) error { select {} }} + params.Knobs.GCJob = &sql.GCJobTestingKnobs{RunBeforeResume: func(_ jobspb.JobID) error { + <-ctx.Done() + return nil + }} s, db, _ := serverutils.StartServer(t, params) defer s.Stopper().Stop(context.Background()) + defer cancel() const val1 = 1 const val2 = 2 diff --git a/pkg/sql/backfill.go b/pkg/sql/backfill.go index 716afb033b9f..97736aa3083c 100644 --- a/pkg/sql/backfill.go +++ b/pkg/sql/backfill.go @@ -1800,7 +1800,7 @@ func populateExpectedCounts( // in-memory copy of the descriptor and add it to the Collection's synthetic // descriptors, so that we can use SQL below to perform the validation. fakeDesc, err := tableDesc.MakeFirstMutationPublic( - catalog.IgnoreConstraints, catalog.IgnorePKSwaps, + catalog.IgnoreConstraints, catalog.IgnorePKSwaps, catalog.RetainDroppingColumns, ) if err != nil { return 0, err @@ -1891,7 +1891,9 @@ func countIndexRowsAndMaybeCheckUniqueness( // Make the mutations public in an in-memory copy of the descriptor and // add it to the Collection's synthetic descriptors, so that we can use // SQL below to perform the validation. - fakeDesc, err := tableDesc.MakeFirstMutationPublic(catalog.IgnoreConstraints) + fakeDesc, err := tableDesc.MakeFirstMutationPublic( + catalog.IgnoreConstraints, catalog.RetainDroppingColumns, + ) if err != nil { return 0, err } diff --git a/pkg/sql/catalog/descriptor.go b/pkg/sql/catalog/descriptor.go index 0ccd7e5a13d9..13c6bb8aaeec 100644 --- a/pkg/sql/catalog/descriptor.go +++ b/pkg/sql/catalog/descriptor.go @@ -60,6 +60,9 @@ const ( // IgnorePKSwaps is used in MakeFirstMutationPublic to indicate that the // table descriptor returned should include newly added constraints. IgnorePKSwaps + // RetainDroppingColumns is used in MakeFirstMutationPublic to indicate that + // the table descriptor should include newly dropped columns. + RetainDroppingColumns ) // DescriptorBuilder interfaces are used to build catalog.Descriptor diff --git a/pkg/sql/catalog/table_elements.go b/pkg/sql/catalog/table_elements.go index 7a3e072ea5ab..746c5ec93629 100644 --- a/pkg/sql/catalog/table_elements.go +++ b/pkg/sql/catalog/table_elements.go @@ -201,13 +201,15 @@ type Index interface { NumCompositeColumns() int GetCompositeColumnID(compositeColumnOrdinal int) descpb.ColumnID UseDeletePreservingEncoding() bool - // ForcePut, if true, forces all writes to use Put rather than CPut or InitPut. + // ForcePut forces all writes to use Put rather than CPut or InitPut. // // Users of this options should take great care as it // effectively mean unique constraints are not respected. // - // Currently (2022-01-19) this two users: delete preserving - // indexes and merging indexes. + // Currently (2022-07-15) there are three users: + // * delete preserving indexes + // * merging indexes + // * dropping primary indexes // // Delete preserving encoding indexes are used only as a log of // index writes during backfill, thus we can blindly put values into @@ -218,6 +220,11 @@ type Index interface { // are merged into the index. Uniqueness for such indexes is // checked by the schema changer before they are brought back // online. + // + // In the case of dropping primary indexes, we always ensure that + // there's a replacement primary index which has become public. + // The reason we must not use cput is that the new primary index + // may not store all the columns stored in this index. ForcePut() bool // CreatedAt is an approximate timestamp at which the index was created. diff --git a/pkg/sql/catalog/tabledesc/index.go b/pkg/sql/catalog/tabledesc/index.go index d81703468d4b..78b3183041f8 100644 --- a/pkg/sql/catalog/tabledesc/index.go +++ b/pkg/sql/catalog/tabledesc/index.go @@ -363,11 +363,15 @@ func (w index) UseDeletePreservingEncoding() bool { } // ForcePut returns true if writes to the index should only use Put (rather than -// CPut or InitPut). This is used by indexes currently being built by the -// MVCC-compliant index backfiller and the temporary indexes that support that -// process. +// CPut or InitPut). This is used by: +// +// * indexes currently being built by the MVCC-compliant index backfiller, and +// * the temporary indexes that support that process, and +// * old primary indexes which are being dropped. +// func (w index) ForcePut() bool { - return w.Merging() || w.desc.UseDeletePreservingEncoding + return w.Merging() || w.desc.UseDeletePreservingEncoding || + w.Dropped() && w.IsUnique() && w.GetEncodingType() == descpb.PrimaryIndexEncoding } func (w index) CreatedAt() time.Time { diff --git a/pkg/sql/catalog/tabledesc/structured.go b/pkg/sql/catalog/tabledesc/structured.go index 1cf5fa9a435b..b381ddf16d15 100644 --- a/pkg/sql/catalog/tabledesc/structured.go +++ b/pkg/sql/catalog/tabledesc/structured.go @@ -2239,6 +2239,7 @@ func (desc *wrapper) MakeFirstMutationPublic( mutationID := desc.Mutations[0].MutationID i := 0 policy := makeMutationPublicationPolicy(filters...) + var clone []descpb.DescriptorMutation for _, mutation := range desc.Mutations { if mutation.MutationID != mutationID { // Mutations are applied in a FIFO order. Only apply the first set @@ -2246,14 +2247,19 @@ func (desc *wrapper) MakeFirstMutationPublic( break } i++ - if policy.shouldSkip(&mutation) { - continue - } - if err := table.MakeMutationComplete(mutation); err != nil { - return nil, err + switch { + case policy.shouldSkip(&mutation): + // Don't add to clone. + case policy.shouldRetain(&mutation): + mutation.Direction = descpb.DescriptorMutation_ADD + fallthrough + default: + if err := table.MakeMutationComplete(mutation); err != nil { + return nil, err + } } } - table.Mutations = table.Mutations[i:] + table.Mutations = append(clone, table.Mutations[i:]...) table.Version++ return table, nil } @@ -2287,6 +2293,15 @@ func (p mutationPublicationPolicy) shouldSkip(m *descpb.DescriptorMutation) bool } } +func (p mutationPublicationPolicy) shouldRetain(m *descpb.DescriptorMutation) bool { + switch { + case m.GetColumn() != nil && m.Direction == descpb.DescriptorMutation_DROP: + return p.includes(catalog.RetainDroppingColumns) + default: + return false + } +} + // MakePublic implements the TableDescriptor interface. func (desc *wrapper) MakePublic() catalog.TableDescriptor { // Clone the ImmutableTable descriptor because we want to create an ImmutableCopy one. diff --git a/pkg/sql/logictest/testdata/logic_test/event_log b/pkg/sql/logictest/testdata/logic_test/event_log index 0bd22b87e4c6..9ebdd516988b 100644 --- a/pkg/sql/logictest/testdata/logic_test/event_log +++ b/pkg/sql/logictest/testdata/logic_test/event_log @@ -1063,8 +1063,11 @@ CREATE VIEW z AS SELECT b FROM x statement ok DROP TABLE x CASCADE + +# Note that the CascadedDroppedViews field should be populated. It is omitted +# temporarily because of #84206. query IT -SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID' +SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID' - 'CascadedDroppedViews' FROM system.eventlog WHERE "eventType" = 'drop_table' ORDER BY "timestamp" DESC, info @@ -1112,4 +1115,4 @@ WHERE "eventType" = 'alter_table' ORDER BY "timestamp" DESC, info LIMIT 1 ---- -1 {"CascadeDroppedViews": ["defaultdb.public.v", "defaultdb.public.vv"], "EventType": "alter_table", "MutationID": 1, "Statement": "ALTER TABLE defaultdb.public.x DROP COLUMN b CASCADE", "TableName": "defaultdb.public.x", "Tag": "ALTER TABLE", "User": "root"} +1 {"EventType": "alter_table", "MutationID": 1, "Statement": "ALTER TABLE defaultdb.public.x DROP COLUMN b CASCADE", "TableName": "defaultdb.public.x", "Tag": "ALTER TABLE", "User": "root"} diff --git a/pkg/sql/logictest/testdata/logic_test/sequences b/pkg/sql/logictest/testdata/logic_test/sequences index 48796e51c8f0..ab2c1cc2c470 100644 --- a/pkg/sql/logictest/testdata/logic_test/sequences +++ b/pkg/sql/logictest/testdata/logic_test/sequences @@ -1131,7 +1131,7 @@ CREATE TABLE ab(a INT DEFAULT nextval('owned_seq'), b INT DEFAULT nextval('owned statement ok ALTER SEQUENCE owned_seq OWNED BY ab.a; -statement error cannot drop table ab because other objects depend on it +statement error cannot drop column a because other objects depend on it ALTER TABLE ab DROP COLUMN a; statement ok @@ -1186,7 +1186,7 @@ CREATE TABLE b(b INT DEFAULT nextval('seq')); statement error cannot drop table a because other objects depend on it DROP TABLE a -statement error cannot drop table a because other objects depend on it +statement error cannot drop column a because other objects depend on it ALTER TABLE a DROP COLUMN a; statement ok diff --git a/pkg/sql/rowenc/index_encoding.go b/pkg/sql/rowenc/index_encoding.go index e0db413be78c..181655eefee7 100644 --- a/pkg/sql/rowenc/index_encoding.go +++ b/pkg/sql/rowenc/index_encoding.go @@ -1130,8 +1130,8 @@ func getStoredColumnsForPrimaryIndex( // It should be rare to never that we come across an index which is encoded // as a primary index but with a version older than this version. // Nevertheless, for safety, we assume at that version that the stored - // columns set is not populated and instead we defer to the colMap to compute - // the complete set before subtracting the key columns. + // columns set is not populated, and instead we defer to the colMap to + // compute the complete set before subtracting the key columns. if index.GetVersion() < descpb.PrimaryIndexWithStoredColumnsVersion { var allColumn catalog.TableColSet colMap.ForEach(func(colID descpb.ColumnID, _ int) { diff --git a/pkg/sql/schema_changer_test.go b/pkg/sql/schema_changer_test.go index 65800aaccc3a..6c71cd5f67ba 100644 --- a/pkg/sql/schema_changer_test.go +++ b/pkg/sql/schema_changer_test.go @@ -346,48 +346,46 @@ func runSchemaChangeWithOperations( // Run a variety of operations during the backfill. ctx := context.Background() + conn, err := sqlDB.Conn(ctx) + require.NoError(t, err) + defer func() { assert.NoError(t, conn.Close()) }() + exec := func(sql string, args ...interface{}) { + t.Helper() + _, err := conn.ExecContext(ctx, sql, args...) + if err != nil { + t.Error(err) + } + } // Update some rows. var updatedKeys []int for i := 0; i < 10; i++ { k := rand.Intn(maxValue) v := maxValue + i + 1 - if _, err := sqlDB.Exec(`UPDATE t.test SET v = $1 WHERE k = $2`, v, k); err != nil { - t.Error(err) - } + exec(`UPDATE t.test SET v = $1 WHERE k = $2`, v, k) updatedKeys = append(updatedKeys, k) } // Reupdate updated values back to what they were before. for _, k := range updatedKeys { if rand.Float32() < 0.5 || !useUpsert { - if _, err := sqlDB.Exec(`UPDATE t.test SET v = $1 WHERE k = $2`, maxValue-k, k); err != nil { - t.Error(err) - } + exec(`UPDATE t.test SET v = $1 WHERE k = $2`, maxValue-k, k) } else { - if _, err := sqlDB.Exec(`UPSERT INTO t.test (k,v) VALUES ($1, $2)`, k, maxValue-k); err != nil { - t.Error(err) - } + exec(`UPSERT INTO t.test (k,v) VALUES ($1, $2)`, k, maxValue-k) } } // Delete some rows. deleteStartKey := rand.Intn(maxValue - 10) for i := 0; i < 10; i++ { - if _, err := sqlDB.Exec(`DELETE FROM t.test WHERE k = $1`, deleteStartKey+i); err != nil { - t.Error(err) - } + exec(`DELETE FROM t.test WHERE k = $1`, deleteStartKey+i) } // Reinsert deleted rows. for i := 0; i < 10; i++ { k := deleteStartKey + i if rand.Float32() < 0.5 || !useUpsert { - if _, err := sqlDB.Exec(`INSERT INTO t.test VALUES($1, $2)`, k, maxValue-k); err != nil { - t.Error(err) - } + exec(`INSERT INTO t.test VALUES($1, $2)`, k, maxValue-k) } else { - if _, err := sqlDB.Exec(`UPSERT INTO t.test VALUES($1, $2)`, k, maxValue-k); err != nil { - t.Error(err) - } + exec(`UPSERT INTO t.test VALUES($1, $2)`, k, maxValue-k) } } @@ -395,17 +393,15 @@ func runSchemaChangeWithOperations( numInserts := 10 for i := 0; i < numInserts; i++ { k := maxValue + i + 1 - if _, err := sqlDB.Exec(`INSERT INTO t.test VALUES($1, $1)`, k); err != nil { - t.Error(err) - } + exec(`INSERT INTO t.test VALUES($1, $1)`, k) } wg.Wait() // for schema change to complete. // Verify the number of keys left behind in the table to // validate schema change operations. We wait for any SCHEMA - // CHANGE GC jobs to complete to ensure our key count doesn't - // include keys from a temporary index. + // CHANGE GC jobs for temp indexes to show that the temp index + // has been cleared. if _, err := sqlDB.Exec(`SHOW JOBS WHEN COMPLETE (SELECT job_id FROM [SHOW JOBS] WHERE job_type = 'SCHEMA CHANGE GC')`); err != nil { t.Fatal(err) } @@ -590,8 +586,6 @@ func TestRaceWithBackfill(t *testing.T) { SQLSchemaChanger: &sql.SchemaChangerTestingKnobs{ BackfillChunkSize: chunkSize, }, - // Disable GC job. - // GCJob: &sql.GCJobTestingKnobs{RunBeforeResume: func(_ jobspb.JobID) error { select {} }}, DistSQL: &execinfra.TestingKnobs{ RunBeforeBackfillChunk: func(sp roachpb.Span) error { notifyBackfill() @@ -616,14 +610,15 @@ CREATE UNIQUE INDEX vidx ON t.test (v); `); err != nil { t.Fatal(err) } - + tableDesc := desctestutils.TestingGetPublicTableDescriptor(kvDB, keys.SystemSQLCodec, "t", "test") + // Add a zone config for the table so that garbage collection happens rapidly. + if _, err := sqltestutils.AddImmediateGCZoneConfig(sqlDB, tableDesc.GetID()); err != nil { + t.Fatal(err) + } // Bulk insert. if err := sqltestutils.BulkInsertIntoTable(sqlDB, maxValue); err != nil { t.Fatal(err) } - - // Split the table into multiple ranges. - tableDesc := desctestutils.TestingGetPublicTableDescriptor(kvDB, keys.SystemSQLCodec, "t", "test") var sps []sql.SplitPoint for i := 1; i <= numNodes-1; i++ { sps = append(sps, sql.SplitPoint{TargetNodeIdx: i, Vals: []interface{}{maxValue / numNodes * i}}) @@ -2181,6 +2176,7 @@ func TestAddColumnDuringColumnDrop(t *testing.T) { backfillNotification := make(chan struct{}) continueBackfillNotification := make(chan struct{}) params.Knobs = base.TestingKnobs{ + SQLSchemaChanger: &sql.SchemaChangerTestingKnobs{ RunBeforeBackfill: func() error { if backfillNotification != nil { @@ -2219,14 +2215,20 @@ CREATE TABLE t.test ( var wg sync.WaitGroup wg.Add(1) go func() { - if _, err := sqlDB.Exec(`ALTER TABLE t.test DROP column v;`); err != nil { + if _, err := sqlDB.Exec(` +SET use_declarative_schema_changer = off; +ALTER TABLE t.test DROP column v; +`); err != nil { t.Error(err) } wg.Done() }() <-notification - if _, err := sqlDB.Exec(`ALTER TABLE t.test ADD column v INT DEFAULT 0;`); !testutils.IsError(err, `column "v" being dropped, try again later`) { + if _, err := sqlDB.Exec(` +SET use_declarative_schema_changer = off; +ALTER TABLE t.test ADD column v INT DEFAULT 0; +`); !testutils.IsError(err, `column "v" being dropped, try again later`) { t.Fatal(err) } @@ -2241,6 +2243,10 @@ CREATE TABLE t.test ( // Test a DROP failure on a unique column. The rollback // process might not be able to reconstruct the index and thus // purges the rollback. For now this is considered acceptable. +// +// TODO(ajwerner): This test is not relevant in the declarative schema +// changer; in the declarative schema changer we don't stop upholding +// the constraint too soon. func TestSchemaUniqueColumnDropFailure(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -2318,7 +2324,11 @@ CREATE TABLE t.test (k INT PRIMARY KEY, v INT UNIQUE DEFAULT 23 CREATE FAMILY F3 go func() { defer wg.Done() // This query stays blocked until the end of the test. - _, _ = sqlDB.Exec(`ALTER TABLE t.test DROP column v`) + // Note that we must use the legacy schema changer because this test + // uses knobs that don't make sense in the declarative schema changer. + _, _ = sqlDB.Exec(` +SET use_declarative_schema_changer = off; +ALTER TABLE t.test DROP column v`) }() // Wait until the job is reverted. @@ -6112,6 +6122,8 @@ ALTER TABLE t.test2 ADD FOREIGN KEY (k) REFERENCES t.test; // job, after reversing the mutations the job is set up to throw an error so // that mutations are attempted to be reverted again. The mutation shouldn't be // attempted to be reversed twice. +// +// NOTE: This test only exercises the legacy schema changer. func TestMultipleRevert(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -6178,7 +6190,9 @@ func TestMultipleRevert(t *testing.T) { runner.Exec(t, `CREATE DATABASE t;`) runner.Exec(t, `CREATE TABLE t.test (k INT PRIMARY KEY, v INT8);`) runner.Exec(t, `INSERT INTO t.test VALUES (1, 2);`) - runner.ExpectErr(t, "job canceled by user", `ALTER TABLE t.public.test DROP COLUMN v;`) + runner.ExpectErr(t, "job canceled by user", ` +SET use_declarative_schema_changer = off; +ALTER TABLE t.public.test DROP COLUMN v;`) // Ensure that the schema change was rolled back. rows := runner.QueryStr(t, "SELECT * FROM t.test") diff --git a/pkg/sql/schemachanger/BUILD.bazel b/pkg/sql/schemachanger/BUILD.bazel index b09113e13465..c8ffa472e7c1 100644 --- a/pkg/sql/schemachanger/BUILD.bazel +++ b/pkg/sql/schemachanger/BUILD.bazel @@ -9,7 +9,7 @@ filegroup( go_test( name = "schemachanger_test", - size = "medium", + size = "large", srcs = [ "end_to_end_test.go", "main_test.go", diff --git a/pkg/sql/schemachanger/scbuild/BUILD.bazel b/pkg/sql/schemachanger/scbuild/BUILD.bazel index a82101fba8e2..3761bc5fb4a7 100644 --- a/pkg/sql/schemachanger/scbuild/BUILD.bazel +++ b/pkg/sql/schemachanger/scbuild/BUILD.bazel @@ -20,6 +20,7 @@ go_library( "//pkg/settings/cluster", "//pkg/sql/catalog", "//pkg/sql/catalog/catpb", + "//pkg/sql/catalog/colinfo", "//pkg/sql/catalog/descpb", "//pkg/sql/catalog/descs", "//pkg/sql/catalog/resolver", diff --git a/pkg/sql/schemachanger/scbuild/builder_state.go b/pkg/sql/schemachanger/scbuild/builder_state.go index 6243f1803c90..86e300a6a198 100644 --- a/pkg/sql/schemachanger/scbuild/builder_state.go +++ b/pkg/sql/schemachanger/scbuild/builder_state.go @@ -18,6 +18,7 @@ import ( "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/colinfo" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/schemadesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/schemaexpr" @@ -804,8 +805,7 @@ func (b *builderState) ResolveColumn( if p.IsExistenceOptional { return nil } - panic(pgerror.Newf(pgcode.UndefinedColumn, - "column %q not found in relation %q", columnName, rel.GetName())) + panic(colinfo.NewUndefinedColumnError(string(columnName))) } return c.ers.Filter(func(_ scpb.Status, _ scpb.TargetStatus, e scpb.Element) bool { idI, _ := screl.Schema.GetAttribute(screl.ColumnID, e) diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel index 20b643210a57..049985121e4c 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel @@ -6,6 +6,7 @@ go_library( srcs = [ "alter_table.go", "alter_table_add_column.go", + "alter_table_drop_column.go", "comment_on.go", "create_index.go", "dependencies.go", diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table.go index c8fe90791e61..51413905506d 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table.go @@ -28,7 +28,8 @@ import ( // declarative schema changer. Operations marked as non-fully supported can // only be with the use_declarative_schema_changer session variable. var supportedAlterTableStatements = map[reflect.Type]supportedStatement{ - reflect.TypeOf((*tree.AlterTableAddColumn)(nil)): {alterTableAddColumn, true}, + reflect.TypeOf((*tree.AlterTableAddColumn)(nil)): {alterTableAddColumn, true}, + reflect.TypeOf((*tree.AlterTableDropColumn)(nil)): {alterTableDropColumn, true}, } func init() { diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go index 1f7abc1b2c9d..25a4cac6a149 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go @@ -226,7 +226,7 @@ func alterTableAddColumn( // Add secondary indexes for this column. var primaryIdx *scpb.PrimaryIndex - if newPrimary := addColumn(b, spec); newPrimary != nil { + if newPrimary := addColumn(b, spec, t); newPrimary != nil { primaryIdx = newPrimary } else { publicTargets := b.QueryByID(tbl.TableID).Filter( @@ -278,7 +278,7 @@ type addColumnSpec struct { // addColumn is a helper function which adds column element targets and ensures // that the new column is backed by a primary index, which it returns. -func addColumn(b BuildCtx, spec addColumnSpec) (backing *scpb.PrimaryIndex) { +func addColumn(b BuildCtx, spec addColumnSpec, n tree.NodeFormatter) (backing *scpb.PrimaryIndex) { b.Add(spec.col) if spec.fam != nil { b.Add(spec.fam) @@ -303,7 +303,7 @@ func addColumn(b BuildCtx, spec addColumnSpec) (backing *scpb.PrimaryIndex) { tableID := spec.tbl.TableID existing, freshlyAdded := getPrimaryIndexes(b, tableID) if freshlyAdded != nil { - handleAddColumnFreshlyAddedPrimaryIndex(b, spec, freshlyAdded) + handleAddColumnFreshlyAddedPrimaryIndex(b, spec, freshlyAdded, n) return freshlyAdded } @@ -373,12 +373,21 @@ func addColumn(b BuildCtx, spec addColumnSpec) (backing *scpb.PrimaryIndex) { // table and a previous command has already created a new primary index. In // this situation, we need to add the new column to this new primary index. func handleAddColumnFreshlyAddedPrimaryIndex( - b BuildCtx, spec addColumnSpec, freshlyAdded *scpb.PrimaryIndex, + b BuildCtx, spec addColumnSpec, freshlyAdded *scpb.PrimaryIndex, n tree.NodeFormatter, ) { - // TODO(ajwerner): Make sure we aren't removing any columns from this index. + // Check to make sure we aren't removing any columns from this index. // If we are, it means that this transaction is both adding and removing // physical columns from the table, and we need an intermediate, transient // primary index. + // + // TODO(ajwerner): Handle adding and dropping columns in the same statement + // and transaction. + if haveDroppingColumn := !b.QueryByID(freshlyAdded.TableID). + Filter(isColumnFilter). + Filter(absentTargetFilter). + IsEmpty(); haveDroppingColumn { + panic(scerrors.NotImplementedErrorf(n, "DROP COLUMN after ADD COLUMN")) + } var tempIndex *scpb.TemporaryIndex scpb.ForEachTemporaryIndex(b.QueryByID(spec.tbl.TableID), func( diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go new file mode 100644 index 000000000000..d3eb0cfabe3a --- /dev/null +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go @@ -0,0 +1,622 @@ +// 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 ( + "sort" + + "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" + "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/schemachanger/screl" + "github.com/cockroachdb/cockroach/pkg/sql/sem/catid" + "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" + "github.com/cockroachdb/cockroach/pkg/sql/sqlerrors" + "github.com/cockroachdb/cockroach/pkg/util/protoutil" + "github.com/cockroachdb/errors" +) + +func alterTableDropColumn( + b BuildCtx, tn *tree.TableName, tbl *scpb.Table, n *tree.AlterTableDropColumn, +) { + checkSafeUpdatesForDropColumn(b) + checkRowLevelTTLColumn(b, tn, tbl, n) + checkRegionalByRowColumnConflict(b, tbl, n) + b.IncrementSchemaChangeAlterCounter("table", "drop_column") + col, elts, done := resolveColumnForDropColumn(b, tn, tbl, n) + if done { + return + } + checkColumnNotInaccessible(col, n) + dropColumn(b, tn, tbl, n, col, elts, n.DropBehavior) +} + +func checkSafeUpdatesForDropColumn(b BuildCtx) { + if !b.SessionData().SafeUpdates { + return + } + err := pgerror.DangerousStatementf("ALTER TABLE DROP COLUMN will " + + "remove all data in that column") + if !b.EvalCtx().TxnIsSingleStmt { + err = errors.WithIssueLink(err, errors.IssueLink{ + IssueURL: "https://github.com/cockroachdb/cockroach/issues/46541", + Detail: "when used in an explicit transaction combined with other " + + "schema changes to the same table, DROP COLUMN can result in data " + + "loss if one of the other schema change fails or is canceled", + }) + } + panic(err) +} + +func checkRowLevelTTLColumn( + b BuildCtx, tn *tree.TableName, tbl *scpb.Table, n *tree.AlterTableDropColumn, +) { + var rowLevelTTL *scpb.RowLevelTTL + publicTargets := b.QueryByID(tbl.TableID).Filter(publicTargetFilter) + scpb.ForEachRowLevelTTL(publicTargets, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.RowLevelTTL, + ) { + rowLevelTTL = e + }) + if n.Column == colinfo.TTLDefaultExpirationColumnName && rowLevelTTL != nil { + panic(errors.WithHintf( + pgerror.Newf( + pgcode.InvalidTableDefinition, + `cannot drop column %s while row-level TTL is active`, + n.Column, + ), + "use ALTER TABLE %s RESET (ttl) instead", + tn, + )) + } +} + +func checkRegionalByRowColumnConflict(b BuildCtx, tbl *scpb.Table, n *tree.AlterTableDropColumn) { + var regionalByRow *scpb.TableLocalityRegionalByRow + // TODO(ajwerner): Does this need to look at status or target status? + scpb.ForEachTableLocalityRegionalByRow(b.QueryByID(tbl.TableID), func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.TableLocalityRegionalByRow, + ) { + regionalByRow = e + }) + if regionalByRow == nil { + return + } + rbrColName := tree.RegionalByRowRegionDefaultColName + if regionalByRow.As != "" { + rbrColName = tree.Name(regionalByRow.As) + } + if rbrColName == n.Column { + panic(errors.WithHintf( + pgerror.Newf( + pgcode.InvalidColumnReference, + "cannot drop column %s as it is used to store the region in a REGIONAL BY ROW table", + n.Column, + ), + "You must change the table locality before dropping this table or alter the table to use a different column to use for the region.", + )) + } + // TODO(ajwerner): Support dropping a column of a REGIONAL BY ROW table. + panic(scerrors.NotImplementedErrorf(n, + "regional by row partitioning is not supported")) +} + +func resolveColumnForDropColumn( + b BuildCtx, tn *tree.TableName, tbl *scpb.Table, n *tree.AlterTableDropColumn, +) (col *scpb.Column, elts ElementResultSet, done bool) { + elts = b.ResolveColumn(tbl.TableID, n.Column, ResolveParams{ + IsExistenceOptional: n.IfExists, + RequiredPrivilege: privilege.CREATE, + }) + var colTargetStatus scpb.TargetStatus + _, colTargetStatus, col = scpb.FindColumn(elts) + if col == nil || colTargetStatus == scpb.ToAbsent { + if !n.IfExists { + panic(errors.AssertionFailedf("failed to find column %v in %v which was already resolved", + n.Column, tn)) + } + return nil, nil, true + } + return col, elts, false +} + +func checkColumnNotInaccessible(col *scpb.Column, n *tree.AlterTableDropColumn) { + if col.IsInaccessible { + panic(pgerror.Newf( + pgcode.InvalidColumnReference, + "cannot drop inaccessible column %q", + n.Column, + )) + } +} + +func dropColumn( + b BuildCtx, + tn *tree.TableName, + tbl *scpb.Table, + n tree.NodeFormatter, + col *scpb.Column, + colElts ElementResultSet, + behavior tree.DropBehavior, +) { + _, _, cn := scpb.FindColumnName(colElts) + _, _, ct := scpb.FindColumnType(colElts) + checkColumnNotInPrimaryKey(b, col, cn) + b.Drop(col) + b.Drop(cn) + b.Drop(ct) + if _, _, cc := scpb.FindColumnComment(colElts); cc != nil { + b.Drop(cc) + } + handleDropColumnExpressions(b, colElts, behavior) + handleDropColumnIndexes(b, tn, col, behavior) + handleDropColumnComputedColumns(b, tn, cn, tbl, n, col, behavior) + handleDropColumnUniqueWithoutIndexConstraints(b, col, n) + handleDropColumnCheckConstraints(b, col, n) + handleDropColumnForeignKeyConstraintForwardReferences(b, col, n) + backrefs := undroppedBackrefs(b, col.TableID) + handleDropColumnViewBackReferences(b, backrefs, col, cn, behavior) + handleDropColumnForeignKeyConstraintBackReferences(b, cn, backrefs, col, n, behavior) + if !ct.IsVirtual { + handleDropColumnPrimaryIndexes(b, tbl, n, col) + } + assertAllColumnElementsAreDropped(colElts) +} + +func checkColumnNotInPrimaryKey(b BuildCtx, col *scpb.Column, cn *scpb.ColumnName) { + publicTargets := b.QueryByID(col.TableID).Filter(publicTargetFilter) + _, _, pi := scpb.FindPrimaryIndex(publicTargets) + var ic *scpb.IndexColumn + scpb.ForEachIndexColumn(publicTargets, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.IndexColumn, + ) { + if e.ColumnID == col.ColumnID && + e.IndexID == pi.IndexID && + e.Kind == scpb.IndexColumn_KEY { + ic = e + } + }) + if ic != nil { + panic(sqlerrors.NewColumnReferencedByPrimaryKeyError(cn.Name)) + } +} + +func handleDropColumnComputedColumns( + b BuildCtx, + tn *tree.TableName, + cn *scpb.ColumnName, + tbl *scpb.Table, + n tree.NodeFormatter, + col *scpb.Column, + behavior tree.DropBehavior, +) { + var toRemove catalog.TableColSet + allElts := b.QueryByID(col.TableID) + publicElts := allElts.Filter(publicTargetFilter) + scpb.ForEachColumnType(publicElts, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.ColumnType, + ) { + // The below check is defensive given, at the time of writing, we already + // dropped the column type for the column in question. + if e.ColumnID == col.ColumnID || + // We only care about references in the computed expression. + e.ComputeExpr == nil { + return + } + if descpb.ColumnIDs.Contains(e.ComputeExpr.ReferencedColumnIDs, col.ColumnID) { + toRemove.Add(e.ColumnID) + } + }) + if !toRemove.Empty() && behavior != tree.DropCascade { + first, _ := toRemove.Next(0) + var computedColumnName *scpb.ColumnName + scpb.ForEachColumnName(publicElts, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.ColumnName, + ) { + if e.ColumnID == first { + computedColumnName = e + } + }) + panic(sqlerrors.NewColumnReferencedByComputedColumnError(cn.Name, computedColumnName.Name)) + } + toRemove.ForEach(func(computedColumnID descpb.ColumnID) { + elts := allElts.Filter(func(_ scpb.Status, _ scpb.TargetStatus, e scpb.Element) bool { + idI, _ := screl.Schema.GetAttribute(screl.ColumnID, e) + return idI != nil && idI.(catid.ColumnID) == computedColumnID + }) + _, _, computedCol := scpb.FindColumn(elts) + dropColumn(b, tn, tbl, n, computedCol, elts, behavior) + }) +} + +func handleDropColumnPrimaryIndexes( + b BuildCtx, tbl *scpb.Table, n tree.NodeFormatter, col *scpb.Column, +) { + // For now, disallow adding and dropping columns at the same time. + // In this case, we may need an intermediate index. + // TODO(ajwerner): Support mixing adding and dropping columns. + if addingAnyColumns := !b.QueryByID(tbl.TableID). + Filter(toPublicNotCurrentlyPublicFilter). + Filter(isColumnFilter). + IsEmpty(); addingAnyColumns { + panic(scerrors.NotImplementedErrorf(n, "DROP COLUMN after ADD COLUMN")) + } + existing, freshlyAdded := getPrimaryIndexes(b, tbl.TableID) + if freshlyAdded != nil { + handleDropColumnFreshlyAddedPrimaryIndex(b, tbl, freshlyAdded, col) + } else { + handleDropColumnCreateNewPrimaryIndex(b, tbl, existing, col) + } +} + +func handleDropColumnCreateNewPrimaryIndex( + b BuildCtx, tbl *scpb.Table, existing *scpb.PrimaryIndex, col *scpb.Column, +) *scpb.PrimaryIndex { + return createNewPrimaryIndex(b, tbl, existing, func( + b BuildCtx, newIndex *scpb.PrimaryIndex, existingColumns []*scpb.IndexColumn, + ) (newColumns []*scpb.IndexColumn) { + var ic *scpb.IndexColumn + for _, c := range existingColumns { + if c.ColumnID == col.ColumnID { + ic = c + break + } + } + if ic == nil { + panic(errors.AssertionFailedf("failed to find column")) + } + if ic.Kind != scpb.IndexColumn_STORED { + panic(errors.AssertionFailedf("can only drop columns which are stored in the primary index, this one is %v ", + ic.Kind)) + } + for _, ec := range existingColumns { + sameKind := ec.Kind == ic.Kind + if sameKind && ec.OrdinalInKind == ic.OrdinalInKind { + continue + } + cloned := protoutil.Clone(ec).(*scpb.IndexColumn) + if sameKind && ec.OrdinalInKind > ic.OrdinalInKind { + cloned.OrdinalInKind-- + } + cloned.IndexID = newIndex.IndexID + newColumns = append(newColumns, cloned) + b.Add(cloned) + } + return newColumns + }) +} + +func handleDropColumnFreshlyAddedPrimaryIndex( + b BuildCtx, tbl *scpb.Table, freshlyAdded *scpb.PrimaryIndex, col *scpb.Column, +) { + // We want to find the freshly added index and go ahead and remove this + // column from the stored set. That means going through the other + // index columns for this index and adjusting their ordinal appropriately. + var storedColumns, storedTempColumns []*scpb.IndexColumn + var tempIndex *scpb.TemporaryIndex + scpb.ForEachTemporaryIndex(b.QueryByID(tbl.TableID), func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.TemporaryIndex, + ) { + if e.IndexID == freshlyAdded.TemporaryIndexID { + tempIndex = e + } + }) + if tempIndex == nil { + panic(errors.AssertionFailedf("failed to find temp index %d", freshlyAdded.TemporaryIndexID)) + } + scpb.ForEachIndexColumn(b.QueryByID(tbl.TableID).Filter(publicTargetFilter), func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.IndexColumn, + ) { + if e.Kind != scpb.IndexColumn_STORED { + return + } + switch e.IndexID { + case tempIndex.IndexID: + storedTempColumns = append(storedTempColumns, e) + case freshlyAdded.IndexID: + storedColumns = append(storedColumns, e) + } + }) + sort.Slice(storedColumns, func(i, j int) bool { + return storedColumns[i].OrdinalInKind < storedColumns[j].OrdinalInKind + }) + sort.Slice(storedColumns, func(i, j int) bool { + return storedTempColumns[i].OrdinalInKind < storedTempColumns[j].OrdinalInKind + }) + n := -1 + for i, c := range storedColumns { + if c.ColumnID == col.ColumnID { + n = i + break + } + } + if n == -1 { + panic(errors.AssertionFailedf("failed to find column %d in index %d", col.ColumnID, freshlyAdded.TemporaryIndexID)) + } + b.Drop(storedColumns[n]) + b.Drop(storedTempColumns[n]) + for i := n + 1; i < len(storedColumns); i++ { + storedColumns[i].OrdinalInKind-- + b.Add(storedColumns[i]) + storedTempColumns[i].OrdinalInKind-- + b.Add(storedTempColumns[i]) + } +} + +func handleDropColumnUniqueWithoutIndexConstraints( + b BuildCtx, col *scpb.Column, n tree.NodeFormatter, +) { + publicTargets := b.QueryByID(col.TableID).Filter(publicTargetFilter) + var constraints []*scpb.UniqueWithoutIndexConstraint + scpb.ForEachUniqueWithoutIndexConstraint(publicTargets, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.UniqueWithoutIndexConstraint, + ) { + if descpb.ColumnIDs(e.ColumnIDs).Contains(col.ColumnID) { + constraints = append(constraints, e) + } + }) + if len(constraints) == 0 { + return + } + // TODO(ajwerner): Support dropping UNIQUE WITHOUT INDEX constraints. + panic(errors.Wrap(scerrors.NotImplementedError(n), + "dropping of UNIQUE WITHOUT INDEX constraints not supported")) +} + +func handleDropColumnCheckConstraints(b BuildCtx, col *scpb.Column, n tree.NodeFormatter) { + publicTargets := b.QueryByID(col.TableID).Filter(publicTargetFilter) + var constraints []*scpb.CheckConstraint + scpb.ForEachCheckConstraint(publicTargets, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.CheckConstraint, + ) { + if descpb.ColumnIDs.Contains(e.ReferencedColumnIDs, col.ColumnID) { + constraints = append(constraints, e) + } + }) + if len(constraints) == 0 { + return + } + // TODO(ajwerner): Support dropping CHECK constraints. + panic(errors.Wrap(scerrors.NotImplementedError(n), + "dropping of CHECK constraints not supported")) +} + +func handleDropColumnForeignKeyConstraintForwardReferences( + b BuildCtx, col *scpb.Column, n tree.NodeFormatter, +) { + publicTargets := b.QueryByID(col.TableID).Filter(publicTargetFilter) + var constraints []*scpb.ForeignKeyConstraint + scpb.ForEachForeignKeyConstraint(publicTargets, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.ForeignKeyConstraint, + ) { + if descpb.ColumnIDs.Contains(e.ColumnIDs, col.ColumnID) { + constraints = append(constraints, e) + } + }) + if len(constraints) == 0 { + return + } + // Here we will drop a constraint with or without cascade for outbound + // constraints. + // TODO(ajwerner): Support dropping FOREIGN KEY constraints. + panic(errors.Wrap(scerrors.NotImplementedError(n), + "dropping of FOREIGN KEY constraints not supported")) +} + +func handleDropColumnForeignKeyConstraintBackReferences( + b BuildCtx, + cn *scpb.ColumnName, + backrefs ElementResultSet, + col *scpb.Column, + n tree.NodeFormatter, + behavior tree.DropBehavior, +) { + publicTargets := b.QueryByID(col.TableID).Filter(publicTargetFilter) + var constraints []*scpb.ForeignKeyConstraint + scpb.ForEachForeignKeyConstraint(publicTargets, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.ForeignKeyConstraint, + ) { + if descpb.ColumnIDs.Contains(e.ReferencedColumnIDs, col.ColumnID) { + constraints = append(constraints, e) + } + }) + scpb.ForEachForeignKeyConstraint(backrefs, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.ForeignKeyConstraint, + ) { + if descpb.ColumnIDs.Contains(e.ReferencedColumnIDs, col.ColumnID) { + constraints = append(constraints, e) + } + }) + if len(constraints) == 0 { + return + } + if behavior != tree.DropCascade { + panic(pgerror.Newf(pgcode.DependentObjectsStillExist, + "cannot drop column %s because other objects depend on it", cn.Name)) + } + // Here we will drop a constraint with or without cascade for outbound + // constraints. + // TODO(ajwerner): Support dropping FOREIGN KEY constraints. + panic(errors.Wrap(scerrors.NotImplementedError(n), + "dropping of FOREIGN KEY constraints not supported")) +} + +func handleDropColumnExpressions(b BuildCtx, colElts ElementResultSet, behavior tree.DropBehavior) { + publicTargets := colElts.Filter(publicTargetFilter) + if _, _, de := scpb.FindColumnDefaultExpression(publicTargets); de != nil { + b.Drop(de) + } + if _, _, ue := scpb.FindColumnOnUpdateExpression(publicTargets); ue != nil { + b.Drop(ue) + } + + // Find all the sequences owned by this column and drop them either restrict + // or cascade. Then, we'll need to check whether these sequences have any + // other backreferences which have not yet been dropped. Note that we don't + // need to wait for the other commands in this statement; postgres fails on + // something like: + // + // create table t (i serial); + // alter table t add column j default nextval('t_i_seq'::regclass); + // alter table t drop column i, drop column j; + // 2BP01: cannot drop column i of table t because other objects depend on it + // + var undroppedBackrefsToCheck catalog.DescriptorIDSet + scpb.ForEachSequenceOwner(colElts, func( + _ scpb.Status, _ scpb.TargetStatus, so *scpb.SequenceOwner, + ) { + if behavior == tree.DropCascade { + dropCascadeDescriptor(b, so.SequenceID) + } else { + dropRestrictDescriptor(b, so.SequenceID) + undroppedBackrefsToCheck.Add(so.SequenceID) + b.Drop(so) + } + }) + // TODO(ajwerner): Track the undropped backrefs to populate a detail + // message like postgres does. For example: + // + // create table t (i serial); + // create table t2 (i int default nextval('t_i_seq'::regclass)); + // drop table t restrict; + // ERROR: cannot drop table t because other objects depend on it + // DETAIL: default value for column i of table t2 depends on sequence t_i_seq + // HINT: Use DROP ... CASCADE to drop the dependent objects too. + // + var hasUndroppedBackrefs bool + undroppedBackrefsToCheck.ForEach(func(seqID descpb.ID) { + udr := undroppedBackrefs(b, seqID) + if !udr.IsEmpty() { + hasUndroppedBackrefs = true + } + }) + _, _, cn := scpb.FindColumnName(colElts) + if hasUndroppedBackrefs { + panic(pgerror.Newf(pgcode.DependentObjectsStillExist, + "cannot drop column %s because other objects depend on it", cn.Name)) + } +} + +func handleDropColumnViewBackReferences( + b BuildCtx, + backrefs ElementResultSet, + col *scpb.Column, + cn *scpb.ColumnName, + dropBehavior tree.DropBehavior, +) { + var views []*scpb.View + scpb.ForEachView(backrefs, func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.View) { + for _, ref := range e.ForwardReferences { + if ref.ToID == col.TableID && + catalog.MakeTableColSet(ref.ColumnIDs...).Contains(col.ColumnID) { + views = append(views, e) + } + } + }) + if len(views) == 0 { + return + } + if dropBehavior == tree.DropCascade { + for _, v := range views { + dropCascadeDescriptor(b, v.ViewID) + } + return + } + depView := views[0] + _, _, ns := scpb.FindNamespace(b.QueryByID(col.TableID)) + _, _, nsDep := scpb.FindNamespace(b.QueryByID(depView.ViewID)) + if nsDep.DatabaseID != ns.DatabaseID || nsDep.SchemaID != ns.SchemaID { + panic(errors.WithHintf(sqlerrors.NewDependentObjectErrorf( + "cannot drop column %q because view %q depends on it", + cn.Name, qualifiedName(b, depView.ViewID)), + "you can drop %s instead.", nsDep.Name)) + } + panic(sqlerrors.NewDependentObjectErrorf( + "cannot drop column %q because view %q depends on it", + cn.Name, nsDep.Name)) +} + +func handleDropColumnIndexes( + b BuildCtx, tn *tree.TableName, col *scpb.Column, dropBehavior tree.DropBehavior, +) { + tableElts := b.QueryByID(col.TableID).Filter(publicTargetFilter) + var indexIDs catid.IndexSet + scpb.ForEachIndexColumn(tableElts, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.IndexColumn, + ) { + if e.ColumnID == col.ColumnID { + indexIDs.Add(e.IndexID) + } + }) + scpb.ForEachSecondaryIndexPartial(tableElts, func( + current scpb.Status, target scpb.TargetStatus, e *scpb.SecondaryIndexPartial, + ) { + if descpb.ColumnIDs.Contains(e.ReferencedColumnIDs, col.ColumnID) { + indexIDs.Add(e.IndexID) + } + }) + var secondaryIndexIDs catid.IndexSet + var indexes []*scpb.SecondaryIndex + var indexNames []*scpb.IndexName + scpb.ForEachSecondaryIndex(tableElts, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.SecondaryIndex, + ) { + if indexIDs.Contains(e.IndexID) { + secondaryIndexIDs.Add(e.IndexID) + indexes = append(indexes, e) + } + }) + scpb.ForEachIndexName(tableElts, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.IndexName, + ) { + if secondaryIndexIDs.Contains(e.IndexID) { + indexNames = append(indexNames, e) + } + }) + if len(indexNames) != len(indexes) { + panic(errors.AssertionFailedf("indexes %v does not match indexNames %v", + indexes, indexNames)) + } + sort.Slice(indexes, func(i, j int) bool { + return indexes[i].IndexID < indexes[j].IndexID + }) + sort.Slice(indexNames, func(i, j int) bool { + return indexNames[i].IndexID < indexNames[j].IndexID + }) + for i, idx := range indexes { + name := tree.TableIndexName{ + Table: *tn, + Index: tree.UnrestrictedName(indexNames[i].Name), + } + indexElts := tableElts.Filter(func( + current scpb.Status, target scpb.TargetStatus, e scpb.Element, + ) bool { + idI, _ := screl.Schema.GetAttribute(screl.IndexID, e) + return idI != nil && idI.(catid.IndexID) == idx.IndexID + }) + dropSecondaryIndex(b, &name, dropBehavior, idx, indexElts) + } +} + +func assertAllColumnElementsAreDropped(colElts ElementResultSet) { + if stillPublic := colElts.Filter(publicTargetFilter); !stillPublic.IsEmpty() { + var elements []scpb.Element + stillPublic.ForEachElementStatus(func(_ scpb.Status, _ scpb.TargetStatus, e scpb.Element) { + elements = append(elements, e) + }) + panic(errors.AssertionFailedf("failed to drop all of the relevant elements: %v", elements)) + } +} diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go index eabf1175064d..b1187d8ac1b2 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go @@ -234,7 +234,7 @@ func CreateIndex(b BuildCtx, n *tree.CreateIndex) { if err != nil { panic(err) } - shardColName := maybeCreateAndAddShardCol(b, int(buckets), relation.(*scpb.Table), keyColNames) + shardColName := maybeCreateAndAddShardCol(b, int(buckets), relation.(*scpb.Table), keyColNames, n) index.Sharding = &catpb.ShardedDescriptor{ IsSharded: true, Name: shardColName, @@ -312,7 +312,7 @@ func nextRelationIndexID(b BuildCtx, relation scpb.Element) catid.IndexID { // `desc`, if one doesn't already exist for the given index column set and number of shard // buckets. func maybeCreateAndAddShardCol( - b BuildCtx, shardBuckets int, tbl *scpb.Table, colNames []string, + b BuildCtx, shardBuckets int, tbl *scpb.Table, colNames []string, n tree.NodeFormatter, ) (shardColName string) { shardColName = tabledesc.GetShardColumnName(colNames, int32(shardBuckets)) elts := b.QueryByID(tbl.TableID) @@ -362,7 +362,7 @@ func maybeCreateAndAddShardCol( ComputeExpr: b.WrapExpression(tbl.TableID, parsedExpr), }, } - addColumn(b, spec) + addColumn(b, spec, n) return shardColName } diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go index f0363479f874..76a10b7d908a 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go @@ -141,7 +141,7 @@ func dropSecondaryIndex( // In this case, if we were to drop 'ui' and no other unique constraint can be // found to replace 'uc' (to continue to serve 'fk'), we will require CASCADE //and drop 'fk' as well. - maybeDropDependentFKConstraints(b, sie, index.String(), dropBehavior) + maybeDropDependentFKConstraints(b, sie, index, dropBehavior) // If shard index, also drop the shard column and all check constraints that // uses this shard column if no other index uses the shard column. @@ -149,7 +149,7 @@ func dropSecondaryIndex( // If expression index, also drop the expression column if no other index is // using the expression column. - dropAdditionallyForExpressionIndex(b, sie, index.String()) + dropAdditionallyForExpressionIndex(b, sie) // Finally, drop the index's resolved elements. toBeDroppedIndexElms.ForEachElementStatus(func(current scpb.Status, target scpb.TargetStatus, e scpb.Element) { @@ -204,7 +204,7 @@ func maybeDropDependentViews( func maybeDropDependentFKConstraints( b BuildCtx, toBeDroppedIndex *scpb.SecondaryIndex, - toBeDroppedIndexName string, + toBeDroppedIndexName *tree.TableIndexName, dropBehavior tree.DropBehavior, ) { scpb.ForEachForeignKeyConstraint(b.BackReferences(toBeDroppedIndex.TableID), func( @@ -227,8 +227,8 @@ func maybeDropDependentFKConstraints( // references), so, we will need to remove the dependent FK // constraint as well. if dropBehavior != tree.DropCascade { - _, _, ns := scpb.FindNamespace(b.QueryByID(toBeDroppedIndex.TableID)) - panic(fmt.Errorf("%q is referenced by foreign key from table %q", toBeDroppedIndexName, ns.Name)) + _, _, ns := scpb.FindNamespace(b.QueryByID(e.TableID)) + panic(fmt.Errorf("%q is referenced by foreign key from table %q", toBeDroppedIndexName.Index, ns.Name)) } // TODO (xiang): enable resolving and dropping FK constraint elements. @@ -308,9 +308,7 @@ func maybeDropAdditionallyForShardedIndex( // dropAdditionallyForExpressionIndex attempts to drop the additional // expression column if the to-be-dropped index is an expression index // and no other index uses this expression column. -func dropAdditionallyForExpressionIndex( - b BuildCtx, toBeDroppedIndex *scpb.SecondaryIndex, toBeDroppedIndexName string, -) { +func dropAdditionallyForExpressionIndex(b BuildCtx, toBeDroppedIndex *scpb.SecondaryIndex) { keyColumnIDs, _, _ := getSortedColumnIDsInIndex(b, toBeDroppedIndex.TableID, toBeDroppedIndex.IndexID) scpb.ForEachColumn(b.QueryByID(toBeDroppedIndex.TableID), func( current scpb.Status, target scpb.TargetStatus, ce *scpb.Column, diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go index 1e5694069a83..db4437add65c 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go @@ -304,15 +304,32 @@ func getSortedColumnIDsInIndex( return keyColumnIDs, keySuffixColumnIDs, storingColumnIDs } +func toPublicNotCurrentlyPublicFilter( + status scpb.Status, target scpb.TargetStatus, _ scpb.Element, +) bool { + return status != scpb.Status_PUBLIC && target == scpb.ToPublic +} + +func isColumnFilter(_ scpb.Status, _ scpb.TargetStatus, e scpb.Element) bool { + _, isColumn := e.(*scpb.Column) + return isColumn +} + func publicTargetFilter(_ scpb.Status, target scpb.TargetStatus, _ scpb.Element) bool { return target == scpb.ToPublic } -func statusAbsentOrBackfillOnly(status scpb.Status, _ scpb.TargetStatus, _ scpb.Element) bool { +func absentTargetFilter(_ scpb.Status, target scpb.TargetStatus, _ scpb.Element) bool { + return target == scpb.ToAbsent +} + +func statusAbsentOrBackfillOnlyFilter( + status scpb.Status, _ scpb.TargetStatus, _ scpb.Element, +) bool { return status == scpb.Status_ABSENT || status == scpb.Status_BACKFILL_ONLY } -func statusPublic(status scpb.Status, _ scpb.TargetStatus, _ scpb.Element) bool { +func statusPublicFilter(status scpb.Status, _ scpb.TargetStatus, _ scpb.Element) bool { return status == scpb.Status_PUBLIC } @@ -331,8 +348,8 @@ func getPrimaryIndexes( allTargets := b.QueryByID(tableID) _, _, freshlyAdded = scpb.FindPrimaryIndex(allTargets. Filter(publicTargetFilter). - Filter(statusAbsentOrBackfillOnly)) - _, _, existing = scpb.FindPrimaryIndex(allTargets.Filter(statusPublic)) + Filter(statusAbsentOrBackfillOnlyFilter)) + _, _, existing = scpb.FindPrimaryIndex(allTargets.Filter(statusPublicFilter)) if existing == nil { // TODO(postamar): can this even be possible? panic(pgerror.Newf(pgcode.NoPrimaryKey, "missing active primary key")) diff --git a/pkg/sql/schemachanger/scbuild/testdata/alter_table_drop_column b/pkg/sql/schemachanger/scbuild/testdata/alter_table_drop_column new file mode 100644 index 000000000000..03d1470d3d9c --- /dev/null +++ b/pkg/sql/schemachanger/scbuild/testdata/alter_table_drop_column @@ -0,0 +1,177 @@ +setup +SET serial_normalization = sql_sequence; +CREATE TABLE defaultdb.t ( + i INT8 PRIMARY KEY, + j INT8 DEFAULT 42 NOT NULL, + k INT8 NOT NULL, + l SERIAL, + INDEX (j), + INDEX (j, k) +); +---- + +build +ALTER TABLE defaultdb.t DROP COLUMN j +---- +- [[Column:{DescID: 104, ColumnID: 2}, ABSENT], PUBLIC] + {columnId: 2, pgAttributeNum: 2, tableId: 104} +- [[ColumnName:{DescID: 104, Name: j, ColumnID: 2}, ABSENT], PUBLIC] + {columnId: 2, name: j, tableId: 104} +- [[ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2}, ABSENT], PUBLIC] + {columnId: 2, tableId: 104, type: {family: IntFamily, oid: 20, width: 64}} +- [[ColumnDefaultExpression:{DescID: 104, ColumnID: 2}, ABSENT], PUBLIC] + {columnId: 2, expr: '42:::INT8', tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 1, indexId: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 2, indexId: 1, kind: STORED, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 3, indexId: 1, kind: STORED, ordinalInKind: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 4, indexId: 1, kind: STORED, ordinalInKind: 2, tableId: 104} +- [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] + {constraintId: 1, indexId: 1, isUnique: true, tableId: 104} +- [[IndexName:{DescID: 104, Name: t_pkey, IndexID: 1}, ABSENT], PUBLIC] + {indexId: 1, name: t_pkey, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}, ABSENT], PUBLIC] + {columnId: 2, indexId: 2, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2}, ABSENT], PUBLIC] + {columnId: 1, indexId: 2, kind: KEY_SUFFIX, tableId: 104} +- [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0}, ABSENT], PUBLIC] + {indexId: 2, tableId: 104} +- [[IndexName:{DescID: 104, Name: t_j_idx, IndexID: 2}, ABSENT], PUBLIC] + {indexId: 2, name: t_j_idx, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, ABSENT], PUBLIC] + {columnId: 2, indexId: 3, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}, ABSENT], PUBLIC] + {columnId: 3, indexId: 3, ordinalInKind: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}, ABSENT], PUBLIC] + {columnId: 1, indexId: 3, kind: KEY_SUFFIX, tableId: 104} +- [[SecondaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 0}, ABSENT], PUBLIC] + {indexId: 3, tableId: 104} +- [[IndexName:{DescID: 104, Name: t_j_k_idx, IndexID: 3}, ABSENT], PUBLIC] + {indexId: 3, name: t_j_k_idx, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4}, PUBLIC], ABSENT] + {columnId: 1, indexId: 4, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4}, PUBLIC], ABSENT] + {columnId: 3, indexId: 4, kind: STORED, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 4}, PUBLIC], ABSENT] + {columnId: 4, indexId: 4, kind: STORED, ordinalInKind: 1, tableId: 104} +- [[PrimaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1}, PUBLIC], ABSENT] + {constraintId: 1, indexId: 4, isUnique: true, sourceIndexId: 1, tableId: 104, temporaryIndexId: 5} +- [[IndexName:{DescID: 104, Name: t_pkey, IndexID: 4}, PUBLIC], ABSENT] + {indexId: 4, name: t_pkey, tableId: 104} +- [[TemporaryIndex:{DescID: 104, IndexID: 5, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] + {constraintId: 1, indexId: 5, isUnique: true, sourceIndexId: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 5}, PUBLIC], ABSENT] + {columnId: 1, indexId: 5, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 5}, PUBLIC], ABSENT] + {columnId: 3, indexId: 5, kind: STORED, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 5}, PUBLIC], ABSENT] + {columnId: 4, indexId: 5, kind: STORED, ordinalInKind: 1, tableId: 104} + +build +ALTER TABLE defaultdb.t DROP COLUMN k +---- +- [[Column:{DescID: 104, ColumnID: 3}, ABSENT], PUBLIC] + {columnId: 3, pgAttributeNum: 3, tableId: 104} +- [[ColumnName:{DescID: 104, Name: k, ColumnID: 3}, ABSENT], PUBLIC] + {columnId: 3, name: k, tableId: 104} +- [[ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3}, ABSENT], PUBLIC] + {columnId: 3, tableId: 104, type: {family: IntFamily, oid: 20, width: 64}} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 1, indexId: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 2, indexId: 1, kind: STORED, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 3, indexId: 1, kind: STORED, ordinalInKind: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 4, indexId: 1, kind: STORED, ordinalInKind: 2, tableId: 104} +- [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] + {constraintId: 1, indexId: 1, isUnique: true, tableId: 104} +- [[IndexName:{DescID: 104, Name: t_pkey, IndexID: 1}, ABSENT], PUBLIC] + {indexId: 1, name: t_pkey, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, ABSENT], PUBLIC] + {columnId: 2, indexId: 3, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}, ABSENT], PUBLIC] + {columnId: 3, indexId: 3, ordinalInKind: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}, ABSENT], PUBLIC] + {columnId: 1, indexId: 3, kind: KEY_SUFFIX, tableId: 104} +- [[SecondaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 0}, ABSENT], PUBLIC] + {indexId: 3, tableId: 104} +- [[IndexName:{DescID: 104, Name: t_j_k_idx, IndexID: 3}, ABSENT], PUBLIC] + {indexId: 3, name: t_j_k_idx, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4}, PUBLIC], ABSENT] + {columnId: 1, indexId: 4, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 4}, PUBLIC], ABSENT] + {columnId: 2, indexId: 4, kind: STORED, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 4}, PUBLIC], ABSENT] + {columnId: 4, indexId: 4, kind: STORED, ordinalInKind: 1, tableId: 104} +- [[PrimaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1}, PUBLIC], ABSENT] + {constraintId: 1, indexId: 4, isUnique: true, sourceIndexId: 1, tableId: 104, temporaryIndexId: 5} +- [[IndexName:{DescID: 104, Name: t_pkey, IndexID: 4}, PUBLIC], ABSENT] + {indexId: 4, name: t_pkey, tableId: 104} +- [[TemporaryIndex:{DescID: 104, IndexID: 5, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] + {constraintId: 1, indexId: 5, isUnique: true, sourceIndexId: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 5}, PUBLIC], ABSENT] + {columnId: 1, indexId: 5, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 5}, PUBLIC], ABSENT] + {columnId: 2, indexId: 5, kind: STORED, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 5}, PUBLIC], ABSENT] + {columnId: 4, indexId: 5, kind: STORED, ordinalInKind: 1, tableId: 104} + +build +ALTER TABLE defaultdb.t DROP COLUMN l +---- +- [[Column:{DescID: 104, ColumnID: 4}, ABSENT], PUBLIC] + {columnId: 4, pgAttributeNum: 4, tableId: 104} +- [[ColumnName:{DescID: 104, Name: l, ColumnID: 4}, ABSENT], PUBLIC] + {columnId: 4, name: l, tableId: 104} +- [[ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4}, ABSENT], PUBLIC] + {columnId: 4, tableId: 104, type: {family: IntFamily, oid: 20, width: 64}} +- [[ColumnDefaultExpression:{DescID: 104, ColumnID: 4}, ABSENT], PUBLIC] + {columnId: 4, expr: 'nextval(105:::REGCLASS)', tableId: 104, usesSequenceIds: [105]} +- [[SequenceOwner:{DescID: 104, ColumnID: 4, ReferencedDescID: 105}, ABSENT], PUBLIC] + {columnId: 4, sequenceId: 105, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 1, indexId: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 2, indexId: 1, kind: STORED, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 3, indexId: 1, kind: STORED, ordinalInKind: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 1}, ABSENT], PUBLIC] + {columnId: 4, indexId: 1, kind: STORED, ordinalInKind: 2, tableId: 104} +- [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] + {constraintId: 1, indexId: 1, isUnique: true, tableId: 104} +- [[IndexName:{DescID: 104, Name: t_pkey, IndexID: 1}, ABSENT], PUBLIC] + {indexId: 1, name: t_pkey, tableId: 104} +- [[Namespace:{DescID: 105, Name: t_l_seq, ReferencedDescID: 100}, ABSENT], PUBLIC] + {databaseId: 100, descriptorId: 105, name: t_l_seq, 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} +- [[Sequence:{DescID: 105}, ABSENT], PUBLIC] + {sequenceId: 105} +- [[ObjectParent:{DescID: 105, ReferencedDescID: 101}, ABSENT], PUBLIC] + {objectId: 105, parentSchemaId: 101} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4}, PUBLIC], ABSENT] + {columnId: 1, indexId: 4, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 4}, PUBLIC], ABSENT] + {columnId: 2, indexId: 4, kind: STORED, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4}, PUBLIC], ABSENT] + {columnId: 3, indexId: 4, kind: STORED, ordinalInKind: 1, tableId: 104} +- [[PrimaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1}, PUBLIC], ABSENT] + {constraintId: 1, indexId: 4, isUnique: true, sourceIndexId: 1, tableId: 104, temporaryIndexId: 5} +- [[IndexName:{DescID: 104, Name: t_pkey, IndexID: 4}, PUBLIC], ABSENT] + {indexId: 4, name: t_pkey, tableId: 104} +- [[TemporaryIndex:{DescID: 104, IndexID: 5, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] + {constraintId: 1, indexId: 5, isUnique: true, sourceIndexId: 1, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 5}, PUBLIC], ABSENT] + {columnId: 1, indexId: 5, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 5}, PUBLIC], ABSENT] + {columnId: 2, indexId: 5, kind: STORED, tableId: 104} +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 5}, PUBLIC], ABSENT] + {columnId: 3, indexId: 5, kind: STORED, ordinalInKind: 1, tableId: 104} diff --git a/pkg/sql/schemachanger/scbuild/testdata/unimplemented_alter_table b/pkg/sql/schemachanger/scbuild/testdata/unimplemented_alter_table index 48ff65ea7ba0..2cd33ad8f7c5 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/unimplemented_alter_table +++ b/pkg/sql/schemachanger/scbuild/testdata/unimplemented_alter_table @@ -1,5 +1,15 @@ setup -CREATE TABLE defaultdb.foo (i INT PRIMARY KEY) +SET experimental_enable_unique_without_index_constraints = true; +CREATE TABLE defaultdb.foo ( + i INT8 PRIMARY KEY, + -- j gets added by the test + k INT8 CHECK (k > 10), + l INT8 UNIQUE, + m INT8 REFERENCES foo (l), + n UUID, + UNIQUE WITHOUT INDEX (n), + o INT -- this column can be dropped +); ---- unimplemented @@ -27,7 +37,27 @@ ALTER TABLE defaultdb.foo ALTER PRIMARY KEY USING COLUMNS (i) ---- unimplemented -ALTER TABLE defaultdb.foo DROP COLUMN i +ALTER TABLE defaultdb.foo DROP COLUMN k +---- + +unimplemented +ALTER TABLE defaultdb.foo DROP COLUMN l CASCADE; +---- + +unimplemented +ALTER TABLE defaultdb.foo DROP COLUMN m +---- + +unimplemented +ALTER TABLE defaultdb.foo DROP COLUMN n +---- + +unimplemented +ALTER TABLE defaultdb.foo DROP COLUMN o, ADD COLUMN p INT +---- + +unimplemented +ALTER TABLE defaultdb.foo ADD COLUMN p INT, DROP COLUMN o ---- unimplemented diff --git a/pkg/sql/schemachanger/scplan/internal/scstage/build.go b/pkg/sql/schemachanger/scplan/internal/scstage/build.go index 99dde6fc0e23..83934907f19a 100644 --- a/pkg/sql/schemachanger/scplan/internal/scstage/build.go +++ b/pkg/sql/schemachanger/scplan/internal/scstage/build.go @@ -12,6 +12,7 @@ package scstage import ( "fmt" + "sort" "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" "github.com/cockroachdb/cockroach/pkg/sql/catalog" @@ -638,20 +639,32 @@ func (bc buildContext) makeDescriptorStates(cur, next *Stage) map[descpb.ID]*scp Revertible: isRevertible(next), } }) + mkStmt := func(rank uint32) scpb.DescriptorState_Statement { + return scpb.DescriptorState_Statement{ + Statement: bc.targetState.Statements[rank], + StatementRank: rank, + } + } // Populate the descriptor states. - noteRelevantStatement := func(state *scpb.DescriptorState, stmtRank uint32) { - for i := range state.RelevantStatements { - stmt := &state.RelevantStatements[i] - if stmt.StatementRank != stmtRank { - continue - } - return + addToRelevantStatements := func( + srs []scpb.DescriptorState_Statement, stmtRank uint32, + ) []scpb.DescriptorState_Statement { + n := len(srs) + if i := sort.Search(n, func(i int) bool { + return srs[i].StatementRank >= stmtRank + }); i == n { + srs = append(srs, mkStmt(stmtRank)) + } else if srs[i].StatementRank != stmtRank { + srs = append(srs, scpb.DescriptorState_Statement{}) + copy(srs[i+1:], srs[i:]) + srs[i] = mkStmt(stmtRank) } - state.RelevantStatements = append(state.RelevantStatements, - scpb.DescriptorState_Statement{ - Statement: bc.targetState.Statements[stmtRank], - StatementRank: stmtRank, - }) + return srs + } + noteRelevantStatement := func(state *scpb.DescriptorState, stmtRank uint32) { + state.RelevantStatements = addToRelevantStatements( + state.RelevantStatements, stmtRank, + ) } for i, t := range bc.targetState.Targets { descID := screl.GetDescID(t.Element()) diff --git a/pkg/sql/schemachanger/sctest/cumulative.go b/pkg/sql/schemachanger/sctest/cumulative.go index 9f2814b0760c..c5ad82f92843 100644 --- a/pkg/sql/schemachanger/sctest/cumulative.go +++ b/pkg/sql/schemachanger/sctest/cumulative.go @@ -88,9 +88,7 @@ func Rollback(t *testing.T, dir string, newCluster NewClusterFunc) { processPlanInPhase( t, newCluster, setup, stmts, scop.PostCommitPhase, func(p scplan.Plan) { n = len(p.StagesForCurrentPhase()) }, - func(db *gosql.DB) { - - }, + func(db *gosql.DB) {}, ) return n } @@ -517,7 +515,7 @@ SELECT name func processPlanInPhase( t *testing.T, newCluster NewClusterFunc, - setup, stmt []parser.Statement, + setup, stmts []parser.Statement, phaseToProcess scop.Phase, processFunc func(p scplan.Plan), after func(db *gosql.DB), @@ -533,7 +531,7 @@ func processPlanInPhase( }) defer cleanup() require.NoError(t, executeSchemaChangeTxn( - context.Background(), t, setup, stmt, db, nil, nil, nil, + context.Background(), t, setup, stmts, db, nil, nil, nil, )) if after != nil { after(db) diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_column_basic b/pkg/sql/schemachanger/testdata/end_to_end/drop_column_basic new file mode 100644 index 000000000000..26ce5731560b --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_column_basic @@ -0,0 +1,517 @@ +setup +create table t (i int primary key, j int) +---- +... ++object {100 101 t} -> 104 + +test +alter table t drop column j +---- +begin transaction #1 +# begin StatementPhase +checking for feature: ALTER TABLE +increment telemetry for sql.schema.alter_table +increment telemetry for sql.schema.alter_table.drop_column +## StatementPhase stage 1 of 1 with 7 MutationType ops +upsert descriptor #104 + ... + oid: 20 + width: 64 + - - id: 2 + - name: j + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + createAsOfTime: + wallTime: "1640995200000000000" + ... + columnNames: + - i + - - j + + - crdb_internal_column_2_name_placeholder + defaultColumnId: 2 + name: primary + formatVersion: 3 + id: 104 + - modificationTime: + - wallTime: "1640995200000000000" + + modificationTime: {} + + mutations: + + - column: + + id: 2 + + name: crdb_internal_column_2_name_placeholder + + nullable: true + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + direction: DROP + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - direction: ADD + + index: + + constraintId: 2 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 2 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - i + + name: crdb_internal_index_2_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnNames: [] + + unique: true + + version: 4 + + mutationId: 1 + + state: BACKFILLING + + - direction: ADD + + index: + + constraintId: 3 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 3 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - i + + name: crdb_internal_index_3_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnNames: [] + + unique: true + + useDeletePreservingEncoding: true + + version: 4 + + mutationId: 1 + + state: DELETE_ONLY + name: t + nextColumnId: 3 + - nextConstraintId: 2 + + nextConstraintId: 4 + nextFamilyId: 1 + - nextIndexId: 2 + + nextIndexId: 4 + nextMutationId: 1 + parentId: 100 + ... + - 2 + storeColumnNames: + - - j + + - crdb_internal_column_2_name_placeholder + unique: true + version: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "1" + + version: "2" +write *eventpb.AlterTable to event log for descriptor #104: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› +# end StatementPhase +# begin PreCommitPhase +## PreCommitPhase stage 1 of 1 with 2 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + + declarativeSchemaChangerState: + + authorization: + + userName: root + + currentStatuses: + + jobId: "1" + + relevantStatements: + + - statement: + + redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + + statement: ALTER TABLE t DROP COLUMN j + + statementTag: ALTER TABLE + + revertible: true + + targetRanks: + + targets: + families: + - columnIds: + ... + formatVersion: 3 + id: 104 + - modificationTime: {} + + modificationTime: + + wallTime: "1640995200000000001" + mutations: + - column: + ... +create job #1 (non-cancelable: false): "ALTER TABLE defaultdb.public.t DROP COLUMN j" + descriptor IDs: [104] +# end PreCommitPhase +commit transaction #1 +notified job registry to adopt jobs: [1] +# begin PostCommitPhase +begin transaction #2 +commit transaction #2 +begin transaction #3 +## PostCommitPhase stage 1 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + formatVersion: 3 + id: 104 + - modificationTime: + - wallTime: "1640995200000000001" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: DELETE_AND_WRITE_ONLY + name: t + nextColumnId: 3 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "2" + + version: "3" +update progress of schema change job #1: "PostCommitPhase stage 2 of 7 with 1 BackfillType op pending" +commit transaction #3 +begin transaction #4 +## PostCommitPhase stage 2 of 7 with 1 BackfillType op +backfill indexes [2] from index #1 in table #104 +commit transaction #4 +begin transaction #5 +## PostCommitPhase stage 3 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + formatVersion: 3 + id: 104 + - modificationTime: + - wallTime: "1640995200000000003" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: BACKFILLING + + state: DELETE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "3" + + version: "4" +update progress of schema change job #1: "PostCommitPhase stage 4 of 7 with 1 MutationType op pending" +commit transaction #5 +begin transaction #6 +## PostCommitPhase stage 4 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + formatVersion: 3 + id: 104 + - modificationTime: + - wallTime: "1640995200000000005" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: MERGING + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "4" + + version: "5" +update progress of schema change job #1: "PostCommitPhase stage 5 of 7 with 1 BackfillType op pending" +commit transaction #6 +begin transaction #7 +## PostCommitPhase stage 5 of 7 with 1 BackfillType op +merge temporary indexes [3] into backfilled indexes [2] in table #104 +commit transaction #7 +begin transaction #8 +## PostCommitPhase stage 6 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + formatVersion: 3 + id: 104 + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "5" + + version: "6" +update progress of schema change job #1: "PostCommitPhase stage 7 of 7 with 1 ValidationType op pending" +commit transaction #8 +begin transaction #9 +## PostCommitPhase stage 7 of 7 with 1 ValidationType op +validate forward indexes [2] in table #104 +commit transaction #9 +begin transaction #10 +## PostCommitNonRevertiblePhase stage 1 of 3 with 10 MutationType ops +upsert descriptor #104 + ... + statement: ALTER TABLE t DROP COLUMN j + statementTag: ALTER TABLE + - revertible: true + targetRanks: + targets: + ... + formatVersion: 3 + id: 104 + - modificationTime: + - wallTime: "1640995200000000008" + + modificationTime: {} + mutations: + - column: + ... + direction: DROP + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 2 + + constraintId: 3 + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 2 + + id: 3 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - i + - name: crdb_internal_index_2_name_placeholder + + name: crdb_internal_index_3_name_placeholder + partitioning: {} + sharded: {} + storeColumnNames: [] + unique: true + + useDeletePreservingEncoding: true + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 3 + - createdExplicitly: true + + constraintId: 1 + + createdAtNanos: "1640995200000000000" + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 3 + + id: 1 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - i + - name: crdb_internal_index_3_name_placeholder + + name: crdb_internal_index_1_name_placeholder + partitioning: {} + sharded: {} + - storeColumnNames: [] + + storeColumnIds: + + - 2 + + storeColumnNames: + + - crdb_internal_column_2_name_placeholder + unique: true + - useDeletePreservingEncoding: true + version: 4 + mutationId: 1 + ... + parentId: 100 + primaryIndex: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + + constraintId: 2 + + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 1 + + id: 2 + interleave: {} + keyColumnDirections: + ... + partitioning: {} + sharded: {} + - storeColumnIds: + - - 2 + - storeColumnNames: + - - crdb_internal_column_2_name_placeholder + + storeColumnNames: [] + unique: true + version: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "6" + + version: "7" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending" +set schema change job #1 to non-cancellable +commit transaction #10 +begin transaction #11 +## PostCommitNonRevertiblePhase stage 2 of 3 with 3 MutationType ops +upsert descriptor #104 + ... + formatVersion: 3 + id: 104 + - modificationTime: + - wallTime: "1640995200000000010" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + name: t + nextColumnId: 3 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "7" + + version: "8" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 3 of 3 with 5 MutationType ops pending" +commit transaction #11 +begin transaction #12 +## PostCommitNonRevertiblePhase stage 3 of 3 with 7 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - currentStatuses: + - jobId: "1" + - relevantStatements: + - - statement: + - redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + - statement: ALTER TABLE t DROP COLUMN j + - statementTag: ALTER TABLE + - targetRanks: + - targets: + families: + - columnIds: + - 1 + - - 2 + columnNames: + - i + - - crdb_internal_column_2_name_placeholder + defaultColumnId: 2 + name: primary + formatVersion: 3 + id: 104 + - modificationTime: + - wallTime: "1640995200000000011" + - mutations: + - - column: + - id: 2 + - name: crdb_internal_column_2_name_placeholder + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - direction: DROP + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 3 + - createdExplicitly: true + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 3 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - i + - name: crdb_internal_index_3_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnNames: [] + - unique: true + - useDeletePreservingEncoding: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 1 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - i + - name: crdb_internal_index_1_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnIds: + - - 2 + - storeColumnNames: + - - crdb_internal_column_2_name_placeholder + - unique: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + + modificationTime: {} + + mutations: [] + name: t + nextColumnId: 3 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "8" + + version: "9" +write *eventpb.FinishSchemaChange to event log for descriptor 104 +create job #2 (non-cancelable: true): "GC for ALTER TABLE defaultdb.public.t DROP COLUMN j" + descriptor IDs: [104] +update progress of schema change job #1: "all stages completed" +commit transaction #12 +notified job registry to adopt jobs: [2] +# end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_column_computed_index b/pkg/sql/schemachanger/testdata/end_to_end/drop_column_computed_index new file mode 100644 index 000000000000..b219e215a13c --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_column_computed_index @@ -0,0 +1,631 @@ +setup +create table t (i int primary key, j int, index((j+1))); +---- +... ++object {100 101 t} -> 104 + +test +alter table t drop column j cascade; +---- +begin transaction #1 +# begin StatementPhase +checking for feature: ALTER TABLE +increment telemetry for sql.schema.alter_table +increment telemetry for sql.schema.alter_table.drop_column +## StatementPhase stage 1 of 1 with 12 MutationType ops +upsert descriptor #104 + ... + oid: 20 + width: 64 + - - id: 2 + - name: j + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - - computeExpr: j + 1:::INT8 + - id: 3 + - inaccessible: true + - name: crdb_internal_idx_expr + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - virtual: true + createAsOfTime: + wallTime: "1640995200000000000" + ... + columnNames: + - i + - - j + + - crdb_internal_column_2_name_placeholder + defaultColumnId: 2 + name: primary + formatVersion: 3 + id: 104 + - indexes: + - - createdAtNanos: "1640995200000000000" + - foreignKey: {} + - geoConfig: {} + - id: 2 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 3 + - keyColumnNames: + - - crdb_internal_idx_expr + - keySuffixColumnIds: + - - 1 + - name: t_expr_idx + - partitioning: {} + - sharded: {} + - version: 3 + - modificationTime: + - wallTime: "1640995200000000000" + + indexes: [] + + modificationTime: {} + + mutations: + + - column: + + id: 2 + + name: crdb_internal_column_2_name_placeholder + + nullable: true + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + direction: DROP + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - column: + + computeExpr: crdb_internal_column_2_name_placeholder + 1:::INT8 + + id: 3 + + inaccessible: true + + name: crdb_internal_column_3_name_placeholder + + nullable: true + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + virtual: true + + direction: DROP + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - direction: DROP + + index: + + createdAtNanos: "1640995200000000000" + + foreignKey: {} + + geoConfig: {} + + id: 2 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 3 + + keyColumnNames: + + - crdb_internal_column_3_name_placeholder + + keySuffixColumnIds: + + - 1 + + name: crdb_internal_index_2_name_placeholder + + partitioning: {} + + sharded: {} + + version: 3 + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - direction: ADD + + index: + + constraintId: 2 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 3 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - i + + name: crdb_internal_index_3_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnNames: [] + + unique: true + + version: 4 + + mutationId: 1 + + state: BACKFILLING + + - direction: ADD + + index: + + constraintId: 3 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 4 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - i + + name: crdb_internal_index_4_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnNames: [] + + unique: true + + useDeletePreservingEncoding: true + + version: 4 + + mutationId: 1 + + state: DELETE_ONLY + name: t + nextColumnId: 4 + - nextConstraintId: 2 + + nextConstraintId: 4 + nextFamilyId: 1 + - nextIndexId: 3 + + nextIndexId: 5 + nextMutationId: 1 + parentId: 100 + ... + - 2 + storeColumnNames: + - - j + + - crdb_internal_column_2_name_placeholder + unique: true + version: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "1" + + version: "2" +write *eventpb.AlterTable to event log for descriptor #104: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +# end StatementPhase +# begin PreCommitPhase +## PreCommitPhase stage 1 of 1 with 2 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + + declarativeSchemaChangerState: + + authorization: + + userName: root + + currentStatuses: + + jobId: "1" + + relevantStatements: + + - statement: + + redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + + statement: ALTER TABLE t DROP COLUMN j CASCADE + + statementTag: ALTER TABLE + + revertible: true + + targetRanks: + + targets: + families: + - columnIds: + ... + id: 104 + indexes: [] + - modificationTime: {} + + modificationTime: + + wallTime: "1640995200000000001" + mutations: + - column: + ... +create job #1 (non-cancelable: false): "ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE" + descriptor IDs: [104] +# end PreCommitPhase +commit transaction #1 +notified job registry to adopt jobs: [1] +# begin PostCommitPhase +begin transaction #2 +commit transaction #2 +begin transaction #3 +## PostCommitPhase stage 1 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000001" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: DELETE_AND_WRITE_ONLY + name: t + nextColumnId: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "2" + + version: "3" +update progress of schema change job #1: "PostCommitPhase stage 2 of 7 with 1 BackfillType op pending" +commit transaction #3 +begin transaction #4 +## PostCommitPhase stage 2 of 7 with 1 BackfillType op +backfill indexes [3] from index #1 in table #104 +commit transaction #4 +begin transaction #5 +## PostCommitPhase stage 3 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000003" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: BACKFILLING + + state: DELETE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "3" + + version: "4" +update progress of schema change job #1: "PostCommitPhase stage 4 of 7 with 1 MutationType op pending" +commit transaction #5 +begin transaction #6 +## PostCommitPhase stage 4 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000005" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: MERGING + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "4" + + version: "5" +update progress of schema change job #1: "PostCommitPhase stage 5 of 7 with 1 BackfillType op pending" +commit transaction #6 +begin transaction #7 +## PostCommitPhase stage 5 of 7 with 1 BackfillType op +merge temporary indexes [4] into backfilled indexes [3] in table #104 +commit transaction #7 +begin transaction #8 +## PostCommitPhase stage 6 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "5" + + version: "6" +update progress of schema change job #1: "PostCommitPhase stage 7 of 7 with 1 ValidationType op pending" +commit transaction #8 +begin transaction #9 +## PostCommitPhase stage 7 of 7 with 1 ValidationType op +validate forward indexes [3] in table #104 +commit transaction #9 +begin transaction #10 +## PostCommitNonRevertiblePhase stage 1 of 3 with 14 MutationType ops +upsert descriptor #104 + ... + statement: ALTER TABLE t DROP COLUMN j CASCADE + statementTag: ALTER TABLE + - revertible: true + targetRanks: + targets: + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000008" + + modificationTime: {} + mutations: + - column: + ... + direction: DROP + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + - column: + computeExpr: crdb_internal_column_2_name_placeholder + 1:::INT8 + ... + direction: DROP + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + - direction: DROP + index: + ... + version: 3 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 2 + + constraintId: 3 + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 3 + + id: 4 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - i + - name: crdb_internal_index_3_name_placeholder + + name: crdb_internal_index_4_name_placeholder + partitioning: {} + sharded: {} + storeColumnNames: [] + unique: true + + useDeletePreservingEncoding: true + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 3 + - createdExplicitly: true + + constraintId: 1 + + createdAtNanos: "1640995200000000000" + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 4 + + id: 1 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - i + - name: crdb_internal_index_4_name_placeholder + + name: crdb_internal_index_1_name_placeholder + partitioning: {} + sharded: {} + - storeColumnNames: [] + + storeColumnIds: + + - 2 + + storeColumnNames: + + - crdb_internal_column_2_name_placeholder + unique: true + - useDeletePreservingEncoding: true + version: 4 + mutationId: 1 + ... + parentId: 100 + primaryIndex: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + + constraintId: 2 + + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 1 + + id: 3 + interleave: {} + keyColumnDirections: + ... + partitioning: {} + sharded: {} + - storeColumnIds: + - - 2 + - storeColumnNames: + - - crdb_internal_column_2_name_placeholder + + storeColumnNames: [] + unique: true + version: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "6" + + version: "7" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending" +set schema change job #1 to non-cancellable +commit transaction #10 +begin transaction #11 +## PostCommitNonRevertiblePhase stage 2 of 3 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000010" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + name: t + nextColumnId: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "7" + + version: "8" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 3 of 3 with 9 MutationType ops pending" +commit transaction #11 +begin transaction #12 +## PostCommitNonRevertiblePhase stage 3 of 3 with 11 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - currentStatuses: + - jobId: "1" + - relevantStatements: + - - statement: + - redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + - statement: ALTER TABLE t DROP COLUMN j CASCADE + - statementTag: ALTER TABLE + - targetRanks: + - targets: + families: + - columnIds: + - 1 + - - 2 + columnNames: + - i + - - crdb_internal_column_2_name_placeholder + defaultColumnId: 2 + name: primary + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000011" + - mutations: + - - column: + - id: 2 + - name: crdb_internal_column_2_name_placeholder + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - direction: DROP + - mutationId: 1 + - state: DELETE_ONLY + - - column: + - computeExpr: crdb_internal_column_2_name_placeholder + 1:::INT8 + - id: 3 + - inaccessible: true + - name: crdb_internal_column_3_name_placeholder + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - virtual: true + - direction: DROP + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - createdAtNanos: "1640995200000000000" + - foreignKey: {} + - geoConfig: {} + - id: 2 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 3 + - keyColumnNames: + - - crdb_internal_column_3_name_placeholder + - keySuffixColumnIds: + - - 1 + - name: crdb_internal_index_2_name_placeholder + - partitioning: {} + - sharded: {} + - version: 3 + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 3 + - createdExplicitly: true + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 4 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - i + - name: crdb_internal_index_4_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnNames: [] + - unique: true + - useDeletePreservingEncoding: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 1 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - i + - name: crdb_internal_index_1_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnIds: + - - 2 + - storeColumnNames: + - - crdb_internal_column_2_name_placeholder + - unique: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + + modificationTime: {} + + mutations: [] + name: t + nextColumnId: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "8" + + version: "9" +write *eventpb.DropIndex to event log for descriptor #104: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +create job #2 (non-cancelable: true): "GC for ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE" + descriptor IDs: [104] +update progress of schema change job #1: "all stages completed" +commit transaction #12 +notified job registry to adopt jobs: [2] +# end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_column_create_index_separate_statements b/pkg/sql/schemachanger/testdata/end_to_end/drop_column_create_index_separate_statements new file mode 100644 index 000000000000..2fd0952c63c1 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_column_create_index_separate_statements @@ -0,0 +1,930 @@ +setup +create table t (i int primary key, j int, k int default 32 on update 42, index((j+1), k)); +---- +... ++object {100 101 t} -> 104 + +test +alter table t drop column j cascade; +create unique index idx on t(k); +---- +begin transaction #1 +# begin StatementPhase +checking for feature: ALTER TABLE +increment telemetry for sql.schema.alter_table +increment telemetry for sql.schema.alter_table.drop_column +## StatementPhase stage 1 of 1 with 14 MutationType ops +upsert descriptor #104 + ... + oid: 20 + width: 64 + - - id: 2 + - name: j + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - defaultExpr: 32:::INT8 + id: 3 + ... + oid: 20 + width: 64 + - - computeExpr: j + 1:::INT8 + - id: 4 + - inaccessible: true + - name: crdb_internal_idx_expr + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - virtual: true + createAsOfTime: + wallTime: "1640995200000000000" + ... + columnNames: + - i + - - j + + - crdb_internal_column_2_name_placeholder + - k + name: primary + formatVersion: 3 + id: 104 + - indexes: + - - createdAtNanos: "1640995200000000000" + - foreignKey: {} + - geoConfig: {} + - id: 2 + - interleave: {} + - keyColumnDirections: + - - ASC + - - ASC + - keyColumnIds: + - - 4 + - - 3 + - keyColumnNames: + - - crdb_internal_idx_expr + - - k + - keySuffixColumnIds: + - - 1 + - name: t_expr_k_idx + - partitioning: {} + - sharded: {} + - version: 3 + - modificationTime: + - wallTime: "1640995200000000000" + + indexes: [] + + modificationTime: {} + + mutations: + + - column: + + id: 2 + + name: crdb_internal_column_2_name_placeholder + + nullable: true + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + direction: DROP + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - column: + + computeExpr: crdb_internal_column_2_name_placeholder + 1:::INT8 + + id: 4 + + inaccessible: true + + name: crdb_internal_column_4_name_placeholder + + nullable: true + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + virtual: true + + direction: DROP + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - direction: DROP + + index: + + createdAtNanos: "1640995200000000000" + + foreignKey: {} + + geoConfig: {} + + id: 2 + + interleave: {} + + keyColumnDirections: + + - ASC + + - ASC + + keyColumnIds: + + - 4 + + - 3 + + keyColumnNames: + + - crdb_internal_column_4_name_placeholder + + - k + + keySuffixColumnIds: + + - 1 + + name: crdb_internal_index_2_name_placeholder + + partitioning: {} + + sharded: {} + + version: 3 + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - direction: ADD + + index: + + constraintId: 2 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 3 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - i + + name: crdb_internal_index_3_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnIds: + + - 3 + + storeColumnNames: + + - k + + unique: true + + version: 4 + + mutationId: 1 + + state: BACKFILLING + + - direction: ADD + + index: + + constraintId: 3 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 4 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - i + + name: crdb_internal_index_4_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnIds: + + - 3 + + storeColumnNames: + + - k + + unique: true + + useDeletePreservingEncoding: true + + version: 4 + + mutationId: 1 + + state: DELETE_ONLY + name: t + nextColumnId: 5 + - nextConstraintId: 2 + + nextConstraintId: 4 + nextFamilyId: 1 + - nextIndexId: 3 + + nextIndexId: 5 + nextMutationId: 1 + parentId: 100 + ... + - 3 + storeColumnNames: + - - j + + - crdb_internal_column_2_name_placeholder + - k + unique: true + ... + time: {} + unexposedParentSchemaId: 101 + - version: "1" + + version: "2" +write *eventpb.AlterTable to event log for descriptor #104: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +checking for feature: CREATE INDEX +# end StatementPhase +# begin PreCommitPhase +## PreCommitPhase stage 1 of 1 with 2 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + + declarativeSchemaChangerState: + + authorization: + + userName: root + + currentStatuses: + + jobId: "1" + + relevantStatements: + + - statement: + + redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + + statement: ALTER TABLE t DROP COLUMN j CASCADE + + statementTag: ALTER TABLE + + - statement: + + redactedStatement: CREATE UNIQUE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹k›) + + statement: CREATE UNIQUE INDEX idx ON t (k) + + statementTag: CREATE INDEX + + statementRank: 1 + + revertible: true + + targetRanks: + + targets: + families: + - columnIds: + ... + id: 104 + indexes: [] + - modificationTime: {} + + modificationTime: + + wallTime: "1640995200000000001" + mutations: + - column: + ... +create job #1 (non-cancelable: false): "ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE; CREATE UNIQUE INDEX idx ON defaultdb.public.t (k)" + descriptor IDs: [104] +# end PreCommitPhase +commit transaction #1 +notified job registry to adopt jobs: [1] +# begin PostCommitPhase +begin transaction #2 +commit transaction #2 +begin transaction #3 +## PostCommitPhase stage 1 of 15 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000001" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: DELETE_AND_WRITE_ONLY + name: t + nextColumnId: 5 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "2" + + version: "3" +update progress of schema change job #1: "PostCommitPhase stage 2 of 15 with 1 BackfillType op pending" +commit transaction #3 +begin transaction #4 +## PostCommitPhase stage 2 of 15 with 1 BackfillType op +backfill indexes [3] from index #1 in table #104 +commit transaction #4 +begin transaction #5 +## PostCommitPhase stage 3 of 15 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000003" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: BACKFILLING + + state: DELETE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "3" + + version: "4" +update progress of schema change job #1: "PostCommitPhase stage 4 of 15 with 1 MutationType op pending" +commit transaction #5 +begin transaction #6 +## PostCommitPhase stage 4 of 15 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000005" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: MERGING + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "4" + + version: "5" +update progress of schema change job #1: "PostCommitPhase stage 5 of 15 with 1 BackfillType op pending" +commit transaction #6 +begin transaction #7 +## PostCommitPhase stage 5 of 15 with 1 BackfillType op +merge temporary indexes [4] into backfilled indexes [3] in table #104 +commit transaction #7 +begin transaction #8 +## PostCommitPhase stage 6 of 15 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "5" + + version: "6" +update progress of schema change job #1: "PostCommitPhase stage 7 of 15 with 1 ValidationType op pending" +commit transaction #8 +begin transaction #9 +## PostCommitPhase stage 7 of 15 with 1 ValidationType op +validate forward indexes [3] in table #104 +commit transaction #9 +begin transaction #10 +## PostCommitPhase stage 8 of 15 with 12 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000008" + + modificationTime: {} + mutations: + - column: + ... + - direction: ADD + index: + - constraintId: 2 + + constraintId: 3 + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 3 + + id: 4 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - i + - name: crdb_internal_index_3_name_placeholder + + name: crdb_internal_index_4_name_placeholder + partitioning: {} + sharded: {} + ... + - k + unique: true + + useDeletePreservingEncoding: true + version: 4 + mutationId: 1 + state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + - direction: DROP + index: + - constraintId: 3 + - createdExplicitly: true + + constraintId: 1 + + createdAtNanos: "1640995200000000000" + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 4 + + id: 1 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - i + - name: crdb_internal_index_4_name_placeholder + + name: crdb_internal_index_1_name_placeholder + partitioning: {} + sharded: {} + storeColumnIds: + + - 2 + - 3 + storeColumnNames: + + - crdb_internal_column_2_name_placeholder + - k + unique: true + - useDeletePreservingEncoding: true + version: 4 + mutationId: 1 + state: DELETE_AND_WRITE_ONLY + + - direction: ADD + + index: + + constraintId: 4 + + createdExplicitly: true + + foreignKey: {} + + geoConfig: {} + + id: 5 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 3 + + keyColumnNames: + + - k + + keySuffixColumnIds: + + - 1 + + name: crdb_internal_index_5_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnNames: [] + + unique: true + + version: 4 + + mutationId: 1 + + state: BACKFILLING + + - direction: ADD + + index: + + constraintId: 5 + + createdExplicitly: true + + foreignKey: {} + + geoConfig: {} + + id: 6 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 3 + + keyColumnNames: + + - k + + keySuffixColumnIds: + + - 1 + + name: crdb_internal_index_6_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnNames: [] + + unique: true + + useDeletePreservingEncoding: true + + version: 4 + + mutationId: 1 + + state: DELETE_ONLY + name: t + nextColumnId: 5 + - nextConstraintId: 4 + + nextConstraintId: 6 + nextFamilyId: 1 + - nextIndexId: 5 + + nextIndexId: 7 + nextMutationId: 1 + parentId: 100 + primaryIndex: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + + constraintId: 2 + + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 1 + + id: 3 + interleave: {} + keyColumnDirections: + ... + sharded: {} + storeColumnIds: + - - 2 + - 3 + storeColumnNames: + - - crdb_internal_column_2_name_placeholder + - k + unique: true + ... + time: {} + unexposedParentSchemaId: 101 + - version: "6" + + version: "7" +update progress of schema change job #1: "PostCommitPhase stage 9 of 15 with 1 MutationType op pending" +commit transaction #10 +begin transaction #11 +## PostCommitPhase stage 9 of 15 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000010" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: DELETE_AND_WRITE_ONLY + name: t + nextColumnId: 5 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "7" + + version: "8" +update progress of schema change job #1: "PostCommitPhase stage 10 of 15 with 1 BackfillType op pending" +commit transaction #11 +begin transaction #12 +## PostCommitPhase stage 10 of 15 with 1 BackfillType op +backfill indexes [5] from index #3 in table #104 +commit transaction #12 +begin transaction #13 +## PostCommitPhase stage 11 of 15 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000011" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: BACKFILLING + + state: DELETE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "8" + + version: "9" +update progress of schema change job #1: "PostCommitPhase stage 12 of 15 with 1 MutationType op pending" +commit transaction #13 +begin transaction #14 +## PostCommitPhase stage 12 of 15 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000013" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: MERGING + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "9" + + version: "10" +update progress of schema change job #1: "PostCommitPhase stage 13 of 15 with 1 BackfillType op pending" +commit transaction #14 +begin transaction #15 +## PostCommitPhase stage 13 of 15 with 1 BackfillType op +merge temporary indexes [6] into backfilled indexes [5] in table #104 +commit transaction #15 +begin transaction #16 +## PostCommitPhase stage 14 of 15 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000014" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "10" + + version: "11" +update progress of schema change job #1: "PostCommitPhase stage 15 of 15 with 1 ValidationType op pending" +commit transaction #16 +begin transaction #17 +## PostCommitPhase stage 15 of 15 with 1 ValidationType op +validate forward indexes [5] in table #104 +commit transaction #17 +begin transaction #18 +## PostCommitNonRevertiblePhase stage 1 of 2 with 16 MutationType ops +upsert descriptor #104 + ... + statementTag: CREATE INDEX + statementRank: 1 + - revertible: true + targetRanks: + targets: + ... + formatVersion: 3 + id: 104 + - indexes: [] + - modificationTime: + - wallTime: "1640995200000000016" + + indexes: + + - constraintId: 4 + + createdExplicitly: true + + foreignKey: {} + + geoConfig: {} + + id: 5 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 3 + + keyColumnNames: + + - k + + keySuffixColumnIds: + + - 1 + + name: idx + + partitioning: {} + + sharded: {} + + storeColumnNames: [] + + unique: true + + version: 4 + + modificationTime: {} + mutations: + - column: + ... + direction: DROP + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + - column: + computeExpr: crdb_internal_column_2_name_placeholder + 1:::INT8 + ... + direction: DROP + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + - direction: DROP + index: + ... + version: 3 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + constraintId: 3 + ... + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + - direction: DROP + index: + ... + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 4 + - createdExplicitly: true + - foreignKey: {} + - geoConfig: {} + - id: 5 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 3 + - keyColumnNames: + - - k + - keySuffixColumnIds: + - - 1 + - name: crdb_internal_index_5_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnNames: [] + - unique: true + - version: 4 + - mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + - index: + constraintId: 5 + createdExplicitly: true + ... + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + name: t + nextColumnId: 5 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "11" + + version: "12" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 2 with 11 MutationType ops pending" +set schema change job #1 to non-cancellable +commit transaction #18 +begin transaction #19 +## PostCommitNonRevertiblePhase stage 2 of 2 with 13 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - currentStatuses: + - jobId: "1" + - relevantStatements: + - - statement: + - redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + - statement: ALTER TABLE t DROP COLUMN j CASCADE + - statementTag: ALTER TABLE + - - statement: + - redactedStatement: CREATE UNIQUE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹k›) + - statement: CREATE UNIQUE INDEX idx ON t (k) + - statementTag: CREATE INDEX + - statementRank: 1 + - targetRanks: + - targets: + families: + - columnIds: + - 1 + - - 2 + - 3 + columnNames: + - i + - - crdb_internal_column_2_name_placeholder + - k + name: primary + ... + unique: true + version: 4 + - modificationTime: + - wallTime: "1640995200000000018" + - mutations: + - - column: + - id: 2 + - name: crdb_internal_column_2_name_placeholder + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - direction: DROP + - mutationId: 1 + - state: DELETE_ONLY + - - column: + - computeExpr: crdb_internal_column_2_name_placeholder + 1:::INT8 + - id: 4 + - inaccessible: true + - name: crdb_internal_column_4_name_placeholder + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - virtual: true + - direction: DROP + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - createdAtNanos: "1640995200000000000" + - foreignKey: {} + - geoConfig: {} + - id: 2 + - interleave: {} + - keyColumnDirections: + - - ASC + - - ASC + - keyColumnIds: + - - 4 + - - 3 + - keyColumnNames: + - - crdb_internal_column_4_name_placeholder + - - k + - keySuffixColumnIds: + - - 1 + - name: crdb_internal_index_2_name_placeholder + - partitioning: {} + - sharded: {} + - version: 3 + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 3 + - createdExplicitly: true + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 4 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - i + - name: crdb_internal_index_4_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnIds: + - - 3 + - storeColumnNames: + - - k + - unique: true + - useDeletePreservingEncoding: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 1 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - i + - name: crdb_internal_index_1_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnIds: + - - 2 + - - 3 + - storeColumnNames: + - - crdb_internal_column_2_name_placeholder + - - k + - unique: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 5 + - createdExplicitly: true + - foreignKey: {} + - geoConfig: {} + - id: 6 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 3 + - keyColumnNames: + - - k + - keySuffixColumnIds: + - - 1 + - name: crdb_internal_index_6_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnNames: [] + - unique: true + - useDeletePreservingEncoding: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + + modificationTime: {} + + mutations: [] + name: t + nextColumnId: 5 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "12" + + version: "13" +write *eventpb.DropIndex to event log for descriptor #104: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +create job #2 (non-cancelable: true): "GC for ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE" + descriptor IDs: [104] +update progress of schema change job #1: "all stages completed" +commit transaction #19 +notified job registry to adopt jobs: [2] +# end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_column_unique_index b/pkg/sql/schemachanger/testdata/end_to_end/drop_column_unique_index new file mode 100644 index 000000000000..419d799ce238 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_column_unique_index @@ -0,0 +1,550 @@ +setup +CREATE DATABASE t; +CREATE TABLE t.test (k INT PRIMARY KEY, v INT, pi DECIMAL DEFAULT (DECIMAL '3.14')); +CREATE UNIQUE INDEX vidx ON t.test (v); +ALTER TABLE t.test ADD COLUMN x DECIMAL DEFAULT (DECIMAL '1.4') CHECK (x >= 0); +---- +... ++database {0 0 t} -> 104 ++schema {104 0 public} -> 105 ++object {104 105 test} -> 106 + +test +ALTER TABLE t.test DROP pi +---- +begin transaction #1 +# begin StatementPhase +checking for feature: ALTER TABLE +increment telemetry for sql.schema.alter_table +increment telemetry for sql.schema.alter_table.drop_column +## StatementPhase stage 1 of 1 with 11 MutationType ops +upsert descriptor #106 + ... + oid: 20 + width: 64 + - - defaultExpr: 3.14:::DECIMAL + - id: 3 + - name: pi + - nullable: true + - type: + - family: DecimalFamily + - oid: 1700 + - defaultExpr: 1.4:::DECIMAL + id: 4 + ... + - k + - v + - - pi + + - crdb_internal_column_3_name_placeholder + - x + name: primary + ... + unique: true + version: 3 + - modificationTime: + - wallTime: "1640995200000000000" + + modificationTime: {} + + mutations: + + - column: + + defaultExpr: 3.14:::DECIMAL + + id: 3 + + name: crdb_internal_column_3_name_placeholder + + nullable: true + + type: + + family: DecimalFamily + + oid: 1700 + + direction: DROP + + mutationId: 3 + + state: DELETE_AND_WRITE_ONLY + + - direction: ADD + + index: + + constraintId: 8 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 4 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - k + + name: crdb_internal_index_4_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnIds: + + - 2 + + - 4 + + storeColumnNames: + + - v + + - x + + unique: true + + version: 4 + + mutationId: 3 + + state: BACKFILLING + + - direction: ADD + + index: + + constraintId: 9 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 5 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - k + + name: crdb_internal_index_5_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnIds: + + - 2 + + - 4 + + storeColumnNames: + + - v + + - x + + unique: true + + useDeletePreservingEncoding: true + + version: 4 + + mutationId: 3 + + state: DELETE_ONLY + name: test + nextColumnId: 5 + - nextConstraintId: 8 + + nextConstraintId: 10 + nextFamilyId: 1 + - nextIndexId: 4 + + nextIndexId: 6 + nextMutationId: 3 + parentId: 104 + ... + storeColumnNames: + - v + - - pi + + - crdb_internal_column_3_name_placeholder + - x + unique: true + ... + time: {} + unexposedParentSchemaId: 105 + - version: "11" + + version: "12" +write *eventpb.AlterTable to event log for descriptor #106: ALTER TABLE ‹t›.‹public›.‹test› DROP COLUMN ‹pi› +# end StatementPhase +# begin PreCommitPhase +## PreCommitPhase stage 1 of 1 with 2 MutationType ops +upsert descriptor #106 + ... + createAsOfTime: + wallTime: "1640995200000000000" + + declarativeSchemaChangerState: + + authorization: + + userName: root + + currentStatuses: + + jobId: "1" + + relevantStatements: + + - statement: + + redactedStatement: ALTER TABLE ‹t›.‹public›.‹test› DROP COLUMN ‹pi› + + statement: ALTER TABLE t.test DROP COLUMN pi + + statementTag: ALTER TABLE + + revertible: true + + targetRanks: + + targets: + families: + - columnIds: + ... + unique: true + version: 3 + - modificationTime: {} + + modificationTime: + + wallTime: "1640995200000000001" + mutations: + - column: + ... +create job #1 (non-cancelable: false): "ALTER TABLE t.public.test DROP COLUMN pi" + descriptor IDs: [106] +# end PreCommitPhase +commit transaction #1 +notified job registry to adopt jobs: [1] +# begin PostCommitPhase +begin transaction #2 +commit transaction #2 +begin transaction #3 +## PostCommitPhase stage 1 of 7 with 3 MutationType ops +upsert descriptor #106 + ... + unique: true + version: 3 + - modificationTime: + - wallTime: "1640995200000000001" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 3 + - state: DELETE_ONLY + + state: DELETE_AND_WRITE_ONLY + name: test + nextColumnId: 5 + ... + time: {} + unexposedParentSchemaId: 105 + - version: "12" + + version: "13" +update progress of schema change job #1: "PostCommitPhase stage 2 of 7 with 1 BackfillType op pending" +commit transaction #3 +begin transaction #4 +## PostCommitPhase stage 2 of 7 with 1 BackfillType op +backfill indexes [4] from index #1 in table #106 +commit transaction #4 +begin transaction #5 +## PostCommitPhase stage 3 of 7 with 3 MutationType ops +upsert descriptor #106 + ... + unique: true + version: 3 + - modificationTime: + - wallTime: "1640995200000000003" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 3 + - state: BACKFILLING + + state: DELETE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 105 + - version: "13" + + version: "14" +update progress of schema change job #1: "PostCommitPhase stage 4 of 7 with 1 MutationType op pending" +commit transaction #5 +begin transaction #6 +## PostCommitPhase stage 4 of 7 with 3 MutationType ops +upsert descriptor #106 + ... + unique: true + version: 3 + - modificationTime: + - wallTime: "1640995200000000005" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 3 + - state: DELETE_ONLY + + state: MERGING + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 105 + - version: "14" + + version: "15" +update progress of schema change job #1: "PostCommitPhase stage 5 of 7 with 1 BackfillType op pending" +commit transaction #6 +begin transaction #7 +## PostCommitPhase stage 5 of 7 with 1 BackfillType op +merge temporary indexes [5] into backfilled indexes [4] in table #106 +commit transaction #7 +begin transaction #8 +## PostCommitPhase stage 6 of 7 with 3 MutationType ops +upsert descriptor #106 + ... + unique: true + version: 3 + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 3 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 105 + - version: "15" + + version: "16" +update progress of schema change job #1: "PostCommitPhase stage 7 of 7 with 1 ValidationType op pending" +commit transaction #8 +begin transaction #9 +## PostCommitPhase stage 7 of 7 with 1 ValidationType op +validate forward indexes [4] in table #106 +commit transaction #9 +begin transaction #10 +## PostCommitNonRevertiblePhase stage 1 of 3 with 12 MutationType ops +upsert descriptor #106 + ... + statement: ALTER TABLE t.test DROP COLUMN pi + statementTag: ALTER TABLE + - revertible: true + targetRanks: + targets: + ... + unique: true + version: 3 + - modificationTime: + - wallTime: "1640995200000000008" + + modificationTime: {} + mutations: + - column: + ... + direction: DROP + mutationId: 3 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 8 + + constraintId: 9 + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 4 + + id: 5 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - k + - name: crdb_internal_index_4_name_placeholder + + name: crdb_internal_index_5_name_placeholder + partitioning: {} + sharded: {} + ... + - x + unique: true + + useDeletePreservingEncoding: true + version: 4 + mutationId: 3 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 9 + - createdExplicitly: true + + constraintId: 1 + + createdAtNanos: "1640995200000000000" + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 5 + + id: 1 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - k + - name: crdb_internal_index_5_name_placeholder + + name: crdb_internal_index_1_name_placeholder + partitioning: {} + sharded: {} + storeColumnIds: + - 2 + + - 3 + - 4 + storeColumnNames: + - v + + - crdb_internal_column_3_name_placeholder + - x + unique: true + - useDeletePreservingEncoding: true + version: 4 + mutationId: 3 + ... + parentId: 104 + primaryIndex: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + + constraintId: 8 + + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 1 + + id: 4 + interleave: {} + keyColumnDirections: + ... + storeColumnIds: + - 2 + - - 3 + - 4 + storeColumnNames: + - v + - - crdb_internal_column_3_name_placeholder + - x + unique: true + ... + time: {} + unexposedParentSchemaId: 105 + - version: "16" + + version: "17" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending" +set schema change job #1 to non-cancellable +commit transaction #10 +begin transaction #11 +## PostCommitNonRevertiblePhase stage 2 of 3 with 3 MutationType ops +upsert descriptor #106 + ... + unique: true + version: 3 + - modificationTime: + - wallTime: "1640995200000000010" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 3 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + name: test + nextColumnId: 5 + ... + time: {} + unexposedParentSchemaId: 105 + - version: "17" + + version: "18" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 3 of 3 with 6 MutationType ops pending" +commit transaction #11 +begin transaction #12 +## PostCommitNonRevertiblePhase stage 3 of 3 with 8 MutationType ops +upsert descriptor #106 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - currentStatuses: + - jobId: "1" + - relevantStatements: + - - statement: + - redactedStatement: ALTER TABLE ‹t›.‹public›.‹test› DROP COLUMN ‹pi› + - statement: ALTER TABLE t.test DROP COLUMN pi + - statementTag: ALTER TABLE + - targetRanks: + - targets: + families: + - columnIds: + - 1 + - 2 + - - 3 + - 4 + columnNames: + - k + - v + - - crdb_internal_column_3_name_placeholder + - x + name: primary + ... + unique: true + version: 3 + - modificationTime: + - wallTime: "1640995200000000011" + - mutations: + - - column: + - defaultExpr: 3.14:::DECIMAL + - id: 3 + - name: crdb_internal_column_3_name_placeholder + - nullable: true + - type: + - family: DecimalFamily + - oid: 1700 + - direction: DROP + - mutationId: 3 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 9 + - createdExplicitly: true + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 5 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - k + - name: crdb_internal_index_5_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnIds: + - - 2 + - - 4 + - storeColumnNames: + - - v + - - x + - unique: true + - useDeletePreservingEncoding: true + - version: 4 + - mutationId: 3 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 1 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - k + - name: crdb_internal_index_1_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnIds: + - - 2 + - - 3 + - - 4 + - storeColumnNames: + - - v + - - crdb_internal_column_3_name_placeholder + - - x + - unique: true + - version: 4 + - mutationId: 3 + - state: DELETE_ONLY + + modificationTime: {} + + mutations: [] + name: test + nextColumnId: 5 + ... + time: {} + unexposedParentSchemaId: 105 + - version: "18" + + version: "19" +write *eventpb.FinishSchemaChange to event log for descriptor 106 +create job #2 (non-cancelable: true): "GC for ALTER TABLE t.public.test DROP COLUMN pi" + descriptor IDs: [106] +update progress of schema change job #1: "all stages completed" +commit transaction #12 +notified job registry to adopt jobs: [2] +# end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_index b/pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_index new file mode 100644 index 000000000000..363c760ea6e8 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_index @@ -0,0 +1,586 @@ +setup +create table t (i int primary key, j int, index (j)) +---- +... ++object {100 101 t} -> 104 + +test +alter table t drop column j +---- +begin transaction #1 +# begin StatementPhase +checking for feature: ALTER TABLE +increment telemetry for sql.schema.alter_table +increment telemetry for sql.schema.alter_table.drop_column +## StatementPhase stage 1 of 1 with 9 MutationType ops +upsert descriptor #104 + ... + oid: 20 + width: 64 + - - id: 2 + - name: j + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + createAsOfTime: + wallTime: "1640995200000000000" + ... + columnNames: + - i + - - j + + - crdb_internal_column_2_name_placeholder + defaultColumnId: 2 + name: primary + formatVersion: 3 + id: 104 + - indexes: + - - createdAtNanos: "1640995200000000000" + - foreignKey: {} + - geoConfig: {} + - id: 2 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 2 + - keyColumnNames: + - - j + - keySuffixColumnIds: + - - 1 + - name: t_j_idx + - partitioning: {} + - sharded: {} + - version: 3 + - modificationTime: + - wallTime: "1640995200000000000" + + indexes: [] + + modificationTime: {} + + mutations: + + - column: + + id: 2 + + name: crdb_internal_column_2_name_placeholder + + nullable: true + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + direction: DROP + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - direction: DROP + + index: + + createdAtNanos: "1640995200000000000" + + foreignKey: {} + + geoConfig: {} + + id: 2 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 2 + + keyColumnNames: + + - crdb_internal_column_2_name_placeholder + + keySuffixColumnIds: + + - 1 + + name: crdb_internal_index_2_name_placeholder + + partitioning: {} + + sharded: {} + + version: 3 + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - direction: ADD + + index: + + constraintId: 2 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 3 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - i + + name: crdb_internal_index_3_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnNames: [] + + unique: true + + version: 4 + + mutationId: 1 + + state: BACKFILLING + + - direction: ADD + + index: + + constraintId: 3 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 4 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - i + + name: crdb_internal_index_4_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnNames: [] + + unique: true + + useDeletePreservingEncoding: true + + version: 4 + + mutationId: 1 + + state: DELETE_ONLY + name: t + nextColumnId: 3 + - nextConstraintId: 2 + + nextConstraintId: 4 + nextFamilyId: 1 + - nextIndexId: 3 + + nextIndexId: 5 + nextMutationId: 1 + parentId: 100 + ... + - 2 + storeColumnNames: + - - j + + - crdb_internal_column_2_name_placeholder + unique: true + version: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "1" + + version: "2" +write *eventpb.AlterTable to event log for descriptor #104: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› +# end StatementPhase +# begin PreCommitPhase +## PreCommitPhase stage 1 of 1 with 2 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + + declarativeSchemaChangerState: + + authorization: + + userName: root + + currentStatuses: + + jobId: "1" + + relevantStatements: + + - statement: + + redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + + statement: ALTER TABLE t DROP COLUMN j + + statementTag: ALTER TABLE + + revertible: true + + targetRanks: + + targets: + families: + - columnIds: + ... + id: 104 + indexes: [] + - modificationTime: {} + + modificationTime: + + wallTime: "1640995200000000001" + mutations: + - column: + ... +create job #1 (non-cancelable: false): "ALTER TABLE defaultdb.public.t DROP COLUMN j" + descriptor IDs: [104] +# end PreCommitPhase +commit transaction #1 +notified job registry to adopt jobs: [1] +# begin PostCommitPhase +begin transaction #2 +commit transaction #2 +begin transaction #3 +## PostCommitPhase stage 1 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000001" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: DELETE_AND_WRITE_ONLY + name: t + nextColumnId: 3 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "2" + + version: "3" +update progress of schema change job #1: "PostCommitPhase stage 2 of 7 with 1 BackfillType op pending" +commit transaction #3 +begin transaction #4 +## PostCommitPhase stage 2 of 7 with 1 BackfillType op +backfill indexes [3] from index #1 in table #104 +commit transaction #4 +begin transaction #5 +## PostCommitPhase stage 3 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000003" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: BACKFILLING + + state: DELETE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "3" + + version: "4" +update progress of schema change job #1: "PostCommitPhase stage 4 of 7 with 1 MutationType op pending" +commit transaction #5 +begin transaction #6 +## PostCommitPhase stage 4 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000005" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: MERGING + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "4" + + version: "5" +update progress of schema change job #1: "PostCommitPhase stage 5 of 7 with 1 BackfillType op pending" +commit transaction #6 +begin transaction #7 +## PostCommitPhase stage 5 of 7 with 1 BackfillType op +merge temporary indexes [4] into backfilled indexes [3] in table #104 +commit transaction #7 +begin transaction #8 +## PostCommitPhase stage 6 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "5" + + version: "6" +update progress of schema change job #1: "PostCommitPhase stage 7 of 7 with 1 ValidationType op pending" +commit transaction #8 +begin transaction #9 +## PostCommitPhase stage 7 of 7 with 1 ValidationType op +validate forward indexes [3] in table #104 +commit transaction #9 +begin transaction #10 +## PostCommitNonRevertiblePhase stage 1 of 3 with 13 MutationType ops +upsert descriptor #104 + ... + statement: ALTER TABLE t DROP COLUMN j + statementTag: ALTER TABLE + - revertible: true + targetRanks: + targets: + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000008" + + modificationTime: {} + mutations: + - column: + ... + direction: DROP + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + - direction: DROP + index: + ... + version: 3 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 2 + + constraintId: 3 + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 3 + + id: 4 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - i + - name: crdb_internal_index_3_name_placeholder + + name: crdb_internal_index_4_name_placeholder + partitioning: {} + sharded: {} + storeColumnNames: [] + unique: true + + useDeletePreservingEncoding: true + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 3 + - createdExplicitly: true + + constraintId: 1 + + createdAtNanos: "1640995200000000000" + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 4 + + id: 1 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - i + - name: crdb_internal_index_4_name_placeholder + + name: crdb_internal_index_1_name_placeholder + partitioning: {} + sharded: {} + - storeColumnNames: [] + + storeColumnIds: + + - 2 + + storeColumnNames: + + - crdb_internal_column_2_name_placeholder + unique: true + - useDeletePreservingEncoding: true + version: 4 + mutationId: 1 + ... + parentId: 100 + primaryIndex: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + + constraintId: 2 + + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 1 + + id: 3 + interleave: {} + keyColumnDirections: + ... + partitioning: {} + sharded: {} + - storeColumnIds: + - - 2 + - storeColumnNames: + - - crdb_internal_column_2_name_placeholder + + storeColumnNames: [] + unique: true + version: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "6" + + version: "7" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending" +set schema change job #1 to non-cancellable +commit transaction #10 +begin transaction #11 +## PostCommitNonRevertiblePhase stage 2 of 3 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000010" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + name: t + nextColumnId: 3 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "7" + + version: "8" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 3 of 3 with 8 MutationType ops pending" +commit transaction #11 +begin transaction #12 +## PostCommitNonRevertiblePhase stage 3 of 3 with 10 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - currentStatuses: + - jobId: "1" + - relevantStatements: + - - statement: + - redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + - statement: ALTER TABLE t DROP COLUMN j + - statementTag: ALTER TABLE + - targetRanks: + - targets: + families: + - columnIds: + - 1 + - - 2 + columnNames: + - i + - - crdb_internal_column_2_name_placeholder + defaultColumnId: 2 + name: primary + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000011" + - mutations: + - - column: + - id: 2 + - name: crdb_internal_column_2_name_placeholder + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - direction: DROP + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - createdAtNanos: "1640995200000000000" + - foreignKey: {} + - geoConfig: {} + - id: 2 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 2 + - keyColumnNames: + - - crdb_internal_column_2_name_placeholder + - keySuffixColumnIds: + - - 1 + - name: crdb_internal_index_2_name_placeholder + - partitioning: {} + - sharded: {} + - version: 3 + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 3 + - createdExplicitly: true + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 4 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - i + - name: crdb_internal_index_4_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnNames: [] + - unique: true + - useDeletePreservingEncoding: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 1 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - i + - name: crdb_internal_index_1_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnIds: + - - 2 + - storeColumnNames: + - - crdb_internal_column_2_name_placeholder + - unique: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + + modificationTime: {} + + mutations: [] + name: t + nextColumnId: 3 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "8" + + version: "9" +write *eventpb.DropIndex to event log for descriptor #104: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› +create job #2 (non-cancelable: true): "GC for ALTER TABLE defaultdb.public.t DROP COLUMN j" + descriptor IDs: [104] +update progress of schema change job #1: "all stages completed" +commit transaction #12 +notified job registry to adopt jobs: [2] +# end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_multiple_columns_separate_statements b/pkg/sql/schemachanger/testdata/end_to_end/drop_multiple_columns_separate_statements new file mode 100644 index 000000000000..e0f111c3bd5c --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_multiple_columns_separate_statements @@ -0,0 +1,790 @@ +setup +create table t (i int primary key, j int, k int default 32 on update 42, index((j+1), k)); +---- +... ++object {100 101 t} -> 104 + +test +alter table t drop column j cascade; +alter table t drop column k cascade; +---- +begin transaction #1 +# begin StatementPhase +checking for feature: ALTER TABLE +increment telemetry for sql.schema.alter_table +increment telemetry for sql.schema.alter_table.drop_column +## StatementPhase stage 1 of 1 with 14 MutationType ops +upsert descriptor #104 + ... + oid: 20 + width: 64 + - - id: 2 + - name: j + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - defaultExpr: 32:::INT8 + id: 3 + ... + oid: 20 + width: 64 + - - computeExpr: j + 1:::INT8 + - id: 4 + - inaccessible: true + - name: crdb_internal_idx_expr + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - virtual: true + createAsOfTime: + wallTime: "1640995200000000000" + ... + columnNames: + - i + - - j + + - crdb_internal_column_2_name_placeholder + - k + name: primary + formatVersion: 3 + id: 104 + - indexes: + - - createdAtNanos: "1640995200000000000" + - foreignKey: {} + - geoConfig: {} + - id: 2 + - interleave: {} + - keyColumnDirections: + - - ASC + - - ASC + - keyColumnIds: + - - 4 + - - 3 + - keyColumnNames: + - - crdb_internal_idx_expr + - - k + - keySuffixColumnIds: + - - 1 + - name: t_expr_k_idx + - partitioning: {} + - sharded: {} + - version: 3 + - modificationTime: + - wallTime: "1640995200000000000" + + indexes: [] + + modificationTime: {} + + mutations: + + - column: + + id: 2 + + name: crdb_internal_column_2_name_placeholder + + nullable: true + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + direction: DROP + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - column: + + computeExpr: crdb_internal_column_2_name_placeholder + 1:::INT8 + + id: 4 + + inaccessible: true + + name: crdb_internal_column_4_name_placeholder + + nullable: true + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + virtual: true + + direction: DROP + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - direction: DROP + + index: + + createdAtNanos: "1640995200000000000" + + foreignKey: {} + + geoConfig: {} + + id: 2 + + interleave: {} + + keyColumnDirections: + + - ASC + + - ASC + + keyColumnIds: + + - 4 + + - 3 + + keyColumnNames: + + - crdb_internal_column_4_name_placeholder + + - k + + keySuffixColumnIds: + + - 1 + + name: crdb_internal_index_2_name_placeholder + + partitioning: {} + + sharded: {} + + version: 3 + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + + - direction: ADD + + index: + + constraintId: 2 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 3 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - i + + name: crdb_internal_index_3_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnIds: + + - 3 + + storeColumnNames: + + - k + + unique: true + + version: 4 + + mutationId: 1 + + state: BACKFILLING + + - direction: ADD + + index: + + constraintId: 3 + + createdExplicitly: true + + encodingType: 1 + + foreignKey: {} + + geoConfig: {} + + id: 4 + + interleave: {} + + keyColumnDirections: + + - ASC + + keyColumnIds: + + - 1 + + keyColumnNames: + + - i + + name: crdb_internal_index_4_name_placeholder + + partitioning: {} + + sharded: {} + + storeColumnIds: + + - 3 + + storeColumnNames: + + - k + + unique: true + + useDeletePreservingEncoding: true + + version: 4 + + mutationId: 1 + + state: DELETE_ONLY + name: t + nextColumnId: 5 + - nextConstraintId: 2 + + nextConstraintId: 4 + nextFamilyId: 1 + - nextIndexId: 3 + + nextIndexId: 5 + nextMutationId: 1 + parentId: 100 + ... + - 3 + storeColumnNames: + - - j + + - crdb_internal_column_2_name_placeholder + - k + unique: true + ... + time: {} + unexposedParentSchemaId: 101 + - version: "1" + + version: "2" +write *eventpb.AlterTable to event log for descriptor #104: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +checking for feature: ALTER TABLE +increment telemetry for sql.schema.alter_table +increment telemetry for sql.schema.alter_table.drop_column +## StatementPhase stage 1 of 1 with 3 MutationType ops +upsert descriptor #104 + ... + oid: 20 + width: 64 + - - defaultExpr: 32:::INT8 + - id: 3 + - name: k + - nullable: true + - onUpdateExpr: 42:::INT8 + - type: + - family: IntFamily + - oid: 20 + - width: 64 + createAsOfTime: + wallTime: "1640995200000000000" + ... + - i + - crdb_internal_column_2_name_placeholder + - - k + + - crdb_internal_column_3_name_placeholder + name: primary + formatVersion: 3 + id: 104 + indexes: [] + - modificationTime: {} + + modificationTime: + + wallTime: "1640995200000000001" + mutations: + - column: + ... + keyColumnNames: + - crdb_internal_column_4_name_placeholder + - - k + + - crdb_internal_column_3_name_placeholder + keySuffixColumnIds: + - 1 + ... + - 3 + storeColumnNames: + - - k + + - crdb_internal_column_3_name_placeholder + unique: true + version: 4 + ... + - 3 + storeColumnNames: + - - k + + - crdb_internal_column_3_name_placeholder + unique: true + useDeletePreservingEncoding: true + ... + mutationId: 1 + state: DELETE_ONLY + + - column: + + defaultExpr: 32:::INT8 + + id: 3 + + name: crdb_internal_column_3_name_placeholder + + nullable: true + + onUpdateExpr: 42:::INT8 + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + direction: DROP + + mutationId: 1 + + state: DELETE_AND_WRITE_ONLY + name: t + nextColumnId: 5 + ... + storeColumnNames: + - crdb_internal_column_2_name_placeholder + - - k + + - crdb_internal_column_3_name_placeholder + unique: true + version: 4 + ... +# end StatementPhase +# begin PreCommitPhase +## PreCommitPhase stage 1 of 1 with 2 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + + declarativeSchemaChangerState: + + authorization: + + userName: root + + currentStatuses: + + jobId: "1" + + relevantStatements: + + - statement: + + redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + + statement: ALTER TABLE t DROP COLUMN j CASCADE + + statementTag: ALTER TABLE + + - statement: + + redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹k› CASCADE + + statement: ALTER TABLE t DROP COLUMN k CASCADE + + statementTag: ALTER TABLE + + statementRank: 1 + + revertible: true + + targetRanks: + + targets: + families: + - columnIds: + ... +create job #1 (non-cancelable: false): "ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE; ALTER TABLE defaultdb.public.t DROP COLUMN k CASCADE" + descriptor IDs: [104] +# end PreCommitPhase +commit transaction #1 +notified job registry to adopt jobs: [1] +# begin PostCommitPhase +begin transaction #2 +commit transaction #2 +begin transaction #3 +## PostCommitPhase stage 1 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000001" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: DELETE_AND_WRITE_ONLY + - column: + defaultExpr: 32:::INT8 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "2" + + version: "3" +update progress of schema change job #1: "PostCommitPhase stage 2 of 7 with 1 BackfillType op pending" +commit transaction #3 +begin transaction #4 +## PostCommitPhase stage 2 of 7 with 1 BackfillType op +backfill indexes [3] from index #1 in table #104 +commit transaction #4 +begin transaction #5 +## PostCommitPhase stage 3 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000003" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: BACKFILLING + + state: DELETE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "3" + + version: "4" +update progress of schema change job #1: "PostCommitPhase stage 4 of 7 with 1 MutationType op pending" +commit transaction #5 +begin transaction #6 +## PostCommitPhase stage 4 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000005" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_ONLY + + state: MERGING + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "4" + + version: "5" +update progress of schema change job #1: "PostCommitPhase stage 5 of 7 with 1 BackfillType op pending" +commit transaction #6 +begin transaction #7 +## PostCommitPhase stage 5 of 7 with 1 BackfillType op +merge temporary indexes [4] into backfilled indexes [3] in table #104 +commit transaction #7 +begin transaction #8 +## PostCommitPhase stage 6 of 7 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000006" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: MERGING + + state: DELETE_AND_WRITE_ONLY + - direction: ADD + index: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "5" + + version: "6" +update progress of schema change job #1: "PostCommitPhase stage 7 of 7 with 1 ValidationType op pending" +commit transaction #8 +begin transaction #9 +## PostCommitPhase stage 7 of 7 with 1 ValidationType op +validate forward indexes [3] in table #104 +commit transaction #9 +begin transaction #10 +## PostCommitNonRevertiblePhase stage 1 of 3 with 19 MutationType ops +upsert descriptor #104 + ... + statementTag: ALTER TABLE + statementRank: 1 + - revertible: true + targetRanks: + targets: + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000008" + + modificationTime: {} + mutations: + - column: + ... + direction: DROP + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + - column: + computeExpr: crdb_internal_column_2_name_placeholder + 1:::INT8 + ... + direction: DROP + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + - direction: DROP + index: + ... + version: 3 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 2 + + constraintId: 3 + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 3 + + id: 4 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - i + - name: crdb_internal_index_3_name_placeholder + + name: crdb_internal_index_4_name_placeholder + partitioning: {} + sharded: {} + - storeColumnIds: + - - 3 + - storeColumnNames: + - - crdb_internal_column_3_name_placeholder + + storeColumnIds: [] + + storeColumnNames: [] + unique: true + + useDeletePreservingEncoding: true + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + - - direction: ADD + + state: DELETE_ONLY + + - column: + + defaultExpr: 32:::INT8 + + id: 3 + + name: crdb_internal_column_3_name_placeholder + + nullable: true + + onUpdateExpr: 42:::INT8 + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + direction: DROP + + mutationId: 1 + + state: DELETE_ONLY + + - direction: DROP + index: + - constraintId: 3 + - createdExplicitly: true + + constraintId: 1 + + createdAtNanos: "1640995200000000000" + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 4 + + id: 1 + interleave: {} + keyColumnDirections: + ... + keyColumnNames: + - i + - name: crdb_internal_index_4_name_placeholder + + name: crdb_internal_index_1_name_placeholder + partitioning: {} + sharded: {} + storeColumnIds: + + - 2 + - 3 + storeColumnNames: + + - crdb_internal_column_2_name_placeholder + - crdb_internal_column_3_name_placeholder + unique: true + - useDeletePreservingEncoding: true + version: 4 + mutationId: 1 + state: DELETE_AND_WRITE_ONLY + - - column: + - defaultExpr: 32:::INT8 + - id: 3 + - name: crdb_internal_column_3_name_placeholder + - nullable: true + - onUpdateExpr: 42:::INT8 + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - direction: DROP + - mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + name: t + nextColumnId: 5 + ... + parentId: 100 + primaryIndex: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + + constraintId: 2 + + createdExplicitly: true + encodingType: 1 + foreignKey: {} + geoConfig: {} + - id: 1 + + id: 3 + interleave: {} + keyColumnDirections: + ... + partitioning: {} + sharded: {} + - storeColumnIds: + - - 2 + - - 3 + - storeColumnNames: + - - crdb_internal_column_2_name_placeholder + - - crdb_internal_column_3_name_placeholder + + storeColumnIds: [] + + storeColumnNames: [] + unique: true + version: 4 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "6" + + version: "7" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending" +set schema change job #1 to non-cancellable +commit transaction #10 +begin transaction #11 +## PostCommitNonRevertiblePhase stage 2 of 3 with 3 MutationType ops +upsert descriptor #104 + ... + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000010" + + modificationTime: {} + mutations: + - column: + ... + version: 4 + mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + state: DELETE_ONLY + name: t + nextColumnId: 5 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "7" + + version: "8" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 3 of 3 with 12 MutationType ops pending" +commit transaction #11 +begin transaction #12 +## PostCommitNonRevertiblePhase stage 3 of 3 with 14 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - currentStatuses: + - jobId: "1" + - relevantStatements: + - - statement: + - redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + - statement: ALTER TABLE t DROP COLUMN j CASCADE + - statementTag: ALTER TABLE + - - statement: + - redactedStatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹k› CASCADE + - statement: ALTER TABLE t DROP COLUMN k CASCADE + - statementTag: ALTER TABLE + - statementRank: 1 + - targetRanks: + - targets: + families: + - columnIds: + - 1 + - - 2 + - - 3 + columnNames: + - i + - - crdb_internal_column_2_name_placeholder + - - crdb_internal_column_3_name_placeholder + name: primary + formatVersion: 3 + id: 104 + indexes: [] + - modificationTime: + - wallTime: "1640995200000000011" + - mutations: + - - column: + - id: 2 + - name: crdb_internal_column_2_name_placeholder + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - direction: DROP + - mutationId: 1 + - state: DELETE_ONLY + - - column: + - computeExpr: crdb_internal_column_2_name_placeholder + 1:::INT8 + - id: 4 + - inaccessible: true + - name: crdb_internal_column_4_name_placeholder + - nullable: true + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - virtual: true + - direction: DROP + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - createdAtNanos: "1640995200000000000" + - foreignKey: {} + - geoConfig: {} + - id: 2 + - interleave: {} + - keyColumnDirections: + - - ASC + - - ASC + - keyColumnIds: + - - 4 + - - 3 + - keyColumnNames: + - - crdb_internal_column_4_name_placeholder + - - crdb_internal_column_3_name_placeholder + - keySuffixColumnIds: + - - 1 + - name: crdb_internal_index_2_name_placeholder + - partitioning: {} + - sharded: {} + - version: 3 + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 3 + - createdExplicitly: true + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 4 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - i + - name: crdb_internal_index_4_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnIds: [] + - storeColumnNames: [] + - unique: true + - useDeletePreservingEncoding: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + - - column: + - defaultExpr: 32:::INT8 + - id: 3 + - name: crdb_internal_column_3_name_placeholder + - nullable: true + - onUpdateExpr: 42:::INT8 + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - direction: DROP + - mutationId: 1 + - state: DELETE_ONLY + - - direction: DROP + - index: + - constraintId: 1 + - createdAtNanos: "1640995200000000000" + - encodingType: 1 + - foreignKey: {} + - geoConfig: {} + - id: 1 + - interleave: {} + - keyColumnDirections: + - - ASC + - keyColumnIds: + - - 1 + - keyColumnNames: + - - i + - name: crdb_internal_index_1_name_placeholder + - partitioning: {} + - sharded: {} + - storeColumnIds: + - - 2 + - - 3 + - storeColumnNames: + - - crdb_internal_column_2_name_placeholder + - - crdb_internal_column_3_name_placeholder + - unique: true + - version: 4 + - mutationId: 1 + - state: DELETE_ONLY + + modificationTime: {} + + mutations: [] + name: t + nextColumnId: 5 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "8" + + version: "9" +write *eventpb.DropIndex to event log for descriptor #104: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +write *eventpb.FinishSchemaChange to event log for descriptor 104 +create job #2 (non-cancelable: true): "GC for ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE" + descriptor IDs: [104] +update progress of schema change job #1: "all stages completed" +commit transaction #12 +notified job registry to adopt jobs: [2] +# end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/explain/drop_column_basic b/pkg/sql/schemachanger/testdata/explain/drop_column_basic new file mode 100644 index 000000000000..2227f4c47c0e --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain/drop_column_basic @@ -0,0 +1,121 @@ +/* setup */ +create table t (i int primary key, j int); + +/* test */ +EXPLAIN (ddl) alter table t drop column j; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 2 elements transitioning toward ABSENT + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ └── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ ├── 3 elements transitioning toward PUBLIC + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ ├── ABSENT → BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} + │ └── 7 Mutation operations + │ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":2,"TableID":104} + │ ├── LogEvent {"TargetStatus":1} + │ ├── SetColumnName {"ColumnID":2,"Name":"crdb_internal_co...","TableID":104} + │ ├── MakeAddedIndexBackfilling {"Index":{"ConstraintID":1,"IndexID":2,"IsUnique":true,"SourceIndexID":1,"TableID":104,"TemporaryIndexID":3}} + │ ├── MakeAddedTempIndexDeleteOnly {"Index":{"ConstraintID":1,"IndexID":3,"IsUnique":true,"SourceIndexID":1,"TableID":104}} + │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":3,"TableID":104} + │ └── AddColumnToIndex {"ColumnID":1,"IndexID":2,"TableID":104} + ├── PreCommitPhase + │ └── Stage 1 of 1 in PreCommitPhase + │ └── 2 Mutation operations + │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} + │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + ├── PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 2 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILL_ONLY → BACKFILLED PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── BackfillIndex {"IndexID":2,"SourceIndexID":1,"TableID":104} + │ ├── Stage 3 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILLED → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":2,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 4 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── DELETE_ONLY → MERGE_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfilledIndexMerging {"IndexID":2,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 5 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGE_ONLY → MERGED PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── MergeIndex {"BackfilledIndexID":2,"TableID":104,"TemporaryIndexID":3} + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":2,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── WRITE_ONLY → VALIDATED PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ └── 1 Validation operation + │ └── ValidateUniqueIndex {"IndexID":2,"TableID":104} + └── PostCommitNonRevertiblePhase + ├── Stage 1 of 3 in PostCommitNonRevertiblePhase + │ ├── 5 elements transitioning toward ABSENT + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ └── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 2} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} + │ └── 10 Mutation operations + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":2,"TableID":104} + │ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":104} + │ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":104} + │ ├── SetIndexName {"IndexID":2,"Name":"t_pkey","TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":3,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":1,"Kind":2,"TableID":104} + │ ├── MakeAddedPrimaryIndexPublic {"IndexID":2,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + ├── Stage 2 of 3 in PostCommitNonRevertiblePhase + │ ├── 1 element transitioning toward ABSENT + │ │ └── WRITE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── 3 Mutation operations + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── Stage 3 of 3 in PostCommitNonRevertiblePhase + ├── 3 elements transitioning toward ABSENT + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 2} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ └── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + ├── 1 element transitioning toward TRANSIENT_ABSENT + │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} + └── 7 Mutation operations + ├── CreateGcJobForIndex {"IndexID":3,"TableID":104} + ├── MakeIndexAbsent {"IndexID":3,"TableID":104} + ├── CreateGcJobForIndex {"IndexID":1,"TableID":104} + ├── MakeIndexAbsent {"IndexID":1,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":2,"TableID":104} + ├── RemoveJobStateFromDescriptor {"DescriptorID":104} + └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/drop_column_computed_index b/pkg/sql/schemachanger/testdata/explain/drop_column_computed_index new file mode 100644 index 000000000000..3f5c6fd428cf --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain/drop_column_computed_index @@ -0,0 +1,145 @@ +/* setup */ +create table t (i int primary key, j int, index((j+1))); + +/* test */ +EXPLAIN (ddl) alter table t drop column j cascade; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 6 elements transitioning toward ABSENT + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 3} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 3} + │ │ ├── PUBLIC → VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_expr_idx, IndexID: 2} + │ ├── 3 elements transitioning toward PUBLIC + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} + │ │ ├── ABSENT → BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ └── 12 Mutation operations + │ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":2,"TableID":104} + │ ├── LogEvent {"TargetStatus":1} + │ ├── SetColumnName {"ColumnID":2,"Name":"crdb_internal_co...","TableID":104} + │ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":3,"TableID":104} + │ ├── LogEvent {"TargetStatus":1} + │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} + │ ├── MakeDroppedNonPrimaryIndexDeleteAndWriteOnly {"IndexID":2,"TableID":104} + │ ├── SetIndexName {"IndexID":2,"Name":"crdb_internal_in...","TableID":104} + │ ├── MakeAddedIndexBackfilling {"Index":{"ConstraintID":1,"IndexID":3,"IsUnique":true,"SourceIndexID":1,"TableID":104,"TemporaryIndexID":4}} + │ ├── MakeAddedTempIndexDeleteOnly {"Index":{"ConstraintID":1,"IndexID":4,"IsUnique":true,"SourceIndexID":1,"TableID":104}} + │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":4,"TableID":104} + │ └── AddColumnToIndex {"ColumnID":1,"IndexID":3,"TableID":104} + ├── PreCommitPhase + │ └── Stage 1 of 1 in PreCommitPhase + │ └── 2 Mutation operations + │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} + │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + ├── PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":4,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 2 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILL_ONLY → BACKFILLED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── BackfillIndex {"IndexID":3,"SourceIndexID":1,"TableID":104} + │ ├── Stage 3 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILLED → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 4 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── DELETE_ONLY → MERGE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfilledIndexMerging {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 5 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGE_ONLY → MERGED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── MergeIndex {"BackfilledIndexID":3,"TableID":104,"TemporaryIndexID":4} + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── WRITE_ONLY → VALIDATED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ └── 1 Validation operation + │ └── ValidateUniqueIndex {"IndexID":3,"TableID":104} + └── PostCommitNonRevertiblePhase + ├── Stage 1 of 3 in PostCommitNonRevertiblePhase + │ ├── 9 elements transitioning toward ABSENT + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ ├── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ └── VALIDATED → DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ └── 14 Mutation operations + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":2,"TableID":104} + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":3,"TableID":104} + │ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":104} + │ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":104} + │ ├── SetIndexName {"IndexID":3,"Name":"t_pkey","TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":4,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":1,"Kind":2,"TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":2,"TableID":104} + │ ├── MakeAddedPrimaryIndexPublic {"IndexID":3,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + ├── Stage 2 of 3 in PostCommitNonRevertiblePhase + │ ├── 1 element transitioning toward ABSENT + │ │ └── WRITE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── 3 Mutation operations + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── Stage 3 of 3 in PostCommitNonRevertiblePhase + ├── 6 elements transitioning toward ABSENT + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 2} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 3} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} + │ ├── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── DELETE_ONLY → ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + ├── 1 element transitioning toward TRANSIENT_ABSENT + │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + └── 11 Mutation operations + ├── CreateGcJobForIndex {"IndexID":4,"TableID":104} + ├── MakeIndexAbsent {"IndexID":4,"TableID":104} + ├── CreateGcJobForIndex {"IndexID":1,"TableID":104} + ├── MakeIndexAbsent {"IndexID":1,"TableID":104} + ├── LogEvent {"TargetStatus":1} + ├── CreateGcJobForIndex {"IndexID":2,"TableID":104} + ├── MakeIndexAbsent {"IndexID":2,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":2,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":3,"TableID":104} + ├── RemoveJobStateFromDescriptor {"DescriptorID":104} + └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/drop_column_create_index_separate_statements.0 b/pkg/sql/schemachanger/testdata/explain/drop_column_create_index_separate_statements.0 new file mode 100644 index 000000000000..a37f8c4f8a6f --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain/drop_column_create_index_separate_statements.0 @@ -0,0 +1,153 @@ +/* setup */ +create table t (i int primary key, j int, k int default 32 on update 42, index((j+1), k)); + +/* test */ +EXPLAIN (ddl) alter table t drop column j cascade; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 6 elements transitioning toward ABSENT + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 4} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 4} + │ │ ├── PUBLIC → VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_expr_k_idx, IndexID: 2} + │ ├── 5 elements transitioning toward PUBLIC + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3} + │ │ ├── ABSENT → BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} + │ │ └── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ └── 14 Mutation operations + │ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":2,"TableID":104} + │ ├── LogEvent {"TargetStatus":1} + │ ├── SetColumnName {"ColumnID":2,"Name":"crdb_internal_co...","TableID":104} + │ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":4,"TableID":104} + │ ├── LogEvent {"TargetStatus":1} + │ ├── SetColumnName {"ColumnID":4,"Name":"crdb_internal_co...","TableID":104} + │ ├── MakeDroppedNonPrimaryIndexDeleteAndWriteOnly {"IndexID":2,"TableID":104} + │ ├── SetIndexName {"IndexID":2,"Name":"crdb_internal_in...","TableID":104} + │ ├── MakeAddedIndexBackfilling {"Index":{"ConstraintID":1,"IndexID":3,"IsUnique":true,"SourceIndexID":1,"TableID":104,"TemporaryIndexID":4}} + │ ├── MakeAddedTempIndexDeleteOnly {"Index":{"ConstraintID":1,"IndexID":4,"IsUnique":true,"SourceIndexID":1,"TableID":104}} + │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":4,"TableID":104} + │ ├── AddColumnToIndex {"ColumnID":3,"IndexID":4,"Kind":2,"TableID":104} + │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":3,"TableID":104} + │ └── AddColumnToIndex {"ColumnID":3,"IndexID":3,"Kind":2,"TableID":104} + ├── PreCommitPhase + │ └── Stage 1 of 1 in PreCommitPhase + │ └── 2 Mutation operations + │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} + │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + ├── PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":4,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 2 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILL_ONLY → BACKFILLED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── BackfillIndex {"IndexID":3,"SourceIndexID":1,"TableID":104} + │ ├── Stage 3 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILLED → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 4 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── DELETE_ONLY → MERGE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfilledIndexMerging {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 5 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGE_ONLY → MERGED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── MergeIndex {"BackfilledIndexID":3,"TableID":104,"TemporaryIndexID":4} + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── WRITE_ONLY → VALIDATED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ └── 1 Validation operation + │ └── ValidateUniqueIndex {"IndexID":3,"TableID":104} + └── PostCommitNonRevertiblePhase + ├── Stage 1 of 3 in PostCommitNonRevertiblePhase + │ ├── 11 elements transitioning toward ABSENT + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 4} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ ├── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ └── VALIDATED → DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ └── 16 Mutation operations + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":2,"TableID":104} + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":4,"TableID":104} + │ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":104} + │ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":104} + │ ├── SetIndexName {"IndexID":3,"Name":"t_pkey","TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":4,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":1,"Kind":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":1,"Kind":2,"Ordinal":1,"TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":2,"TableID":104} + │ ├── MakeAddedPrimaryIndexPublic {"IndexID":3,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":4,"IndexID":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Ordinal":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + ├── Stage 2 of 3 in PostCommitNonRevertiblePhase + │ ├── 1 element transitioning toward ABSENT + │ │ └── WRITE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── 3 Mutation operations + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── Stage 3 of 3 in PostCommitNonRevertiblePhase + ├── 6 elements transitioning toward ABSENT + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 2} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 4} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ ├── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── DELETE_ONLY → ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + ├── 1 element transitioning toward TRANSIENT_ABSENT + │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + └── 11 Mutation operations + ├── CreateGcJobForIndex {"IndexID":4,"TableID":104} + ├── MakeIndexAbsent {"IndexID":4,"TableID":104} + ├── CreateGcJobForIndex {"IndexID":1,"TableID":104} + ├── MakeIndexAbsent {"IndexID":1,"TableID":104} + ├── LogEvent {"TargetStatus":1} + ├── CreateGcJobForIndex {"IndexID":2,"TableID":104} + ├── MakeIndexAbsent {"IndexID":2,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":2,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":4,"TableID":104} + ├── RemoveJobStateFromDescriptor {"DescriptorID":104} + └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/drop_column_create_index_separate_statements.1 b/pkg/sql/schemachanger/testdata/explain/drop_column_create_index_separate_statements.1 new file mode 100644 index 000000000000..f79049a015aa --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain/drop_column_create_index_separate_statements.1 @@ -0,0 +1,188 @@ +/* setup */ +create table t (i int primary key, j int, k int default 32 on update 42, index((j+1), k)); + +/* test */ +alter table t drop column j cascade; +EXPLAIN (ddl) create unique index idx on t(k); +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE; CREATE UNIQUE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹k›); + ├── PreCommitPhase + │ └── Stage 1 of 1 in PreCommitPhase + │ └── 2 Mutation operations + │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} + │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + ├── PostCommitPhase + │ ├── Stage 1 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":4,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 2 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILL_ONLY → BACKFILLED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── BackfillIndex {"IndexID":3,"SourceIndexID":1,"TableID":104} + │ ├── Stage 3 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILLED → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 4 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── DELETE_ONLY → MERGE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfilledIndexMerging {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 5 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGE_ONLY → MERGED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── MergeIndex {"BackfilledIndexID":3,"TableID":104,"TemporaryIndexID":4} + │ ├── Stage 6 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 7 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── WRITE_ONLY → VALIDATED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Validation operation + │ │ └── ValidateUniqueIndex {"IndexID":3,"TableID":104} + │ ├── Stage 8 of 15 in PostCommitPhase + │ │ ├── 2 elements transitioning toward ABSENT + │ │ │ ├── PUBLIC → VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ ├── 7 elements transitioning toward PUBLIC + │ │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ │ ├── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 5} + │ │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 5} + │ │ │ ├── ABSENT → BACKFILL_ONLY SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} + │ │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 6} + │ │ │ └── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 6} + │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ └── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} + │ │ └── 12 Mutation operations + │ │ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":104} + │ │ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":104} + │ │ ├── SetIndexName {"IndexID":3,"Name":"t_pkey","TableID":104} + │ │ ├── MakeAddedPrimaryIndexPublic {"IndexID":3,"TableID":104} + │ │ ├── MakeAddedIndexBackfilling {"IsSecondaryIndex":true} + │ │ ├── MakeAddedTempIndexDeleteOnly {"IsSecondaryIndex":true} + │ │ ├── AddColumnToIndex {"ColumnID":3,"IndexID":6,"TableID":104} + │ │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":6,"Kind":1,"TableID":104} + │ │ ├── AddColumnToIndex {"ColumnID":3,"IndexID":5,"TableID":104} + │ │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":5,"Kind":1,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 9 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} + │ │ └── 3 Mutation operations + │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":6,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 10 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILL_ONLY → BACKFILLED SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} + │ │ └── 1 Backfill operation + │ │ └── BackfillIndex {"IndexID":5,"SourceIndexID":3,"TableID":104} + │ ├── Stage 11 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILLED → DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":5,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 12 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── DELETE_ONLY → MERGE_ONLY SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfilledIndexMerging {"IndexID":5,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 13 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGE_ONLY → MERGED SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} + │ │ └── 1 Backfill operation + │ │ └── MergeIndex {"BackfilledIndexID":5,"TableID":104,"TemporaryIndexID":6} + │ ├── Stage 14 of 15 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":5,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 15 of 15 in PostCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── WRITE_ONLY → VALIDATED SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} + │ └── 1 Validation operation + │ └── ValidateUniqueIndex {"IndexID":5,"TableID":104} + └── PostCommitNonRevertiblePhase + ├── Stage 1 of 2 in PostCommitNonRevertiblePhase + │ ├── 10 elements transitioning toward ABSENT + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 4} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ ├── VALIDATED → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ └── VALIDATED → DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── VALIDATED → PUBLIC SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} + │ │ └── ABSENT → PUBLIC IndexName:{DescID: 104, Name: idx, IndexID: 5} + │ ├── 2 elements transitioning toward TRANSIENT_ABSENT + │ │ ├── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ └── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} + │ └── 16 Mutation operations + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":2,"TableID":104} + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":4,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":1,"Kind":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":1,"Kind":2,"Ordinal":1,"TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":4,"TableID":104} + │ ├── SetIndexName {"IndexID":5,"Name":"idx","TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":6,"TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":1,"TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":2,"TableID":104} + │ ├── MakeAddedSecondaryIndexPublic {"IndexID":5,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":4,"IndexID":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Ordinal":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── Stage 2 of 2 in PostCommitNonRevertiblePhase + ├── 6 elements transitioning toward ABSENT + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 2} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 4} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ ├── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── DELETE_ONLY → ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + ├── 2 elements transitioning toward TRANSIENT_ABSENT + │ ├── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} + └── 13 Mutation operations + ├── CreateGcJobForIndex {"IndexID":4,"TableID":104} + ├── MakeIndexAbsent {"IndexID":4,"TableID":104} + ├── CreateGcJobForIndex {"IndexID":6,"TableID":104} + ├── MakeIndexAbsent {"IndexID":6,"TableID":104} + ├── CreateGcJobForIndex {"IndexID":1,"TableID":104} + ├── MakeIndexAbsent {"IndexID":1,"TableID":104} + ├── LogEvent {"TargetStatus":1} + ├── CreateGcJobForIndex {"IndexID":2,"TableID":104} + ├── MakeIndexAbsent {"IndexID":2,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":2,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":4,"TableID":104} + ├── RemoveJobStateFromDescriptor {"DescriptorID":104} + └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/drop_column_unique_index b/pkg/sql/schemachanger/testdata/explain/drop_column_unique_index new file mode 100644 index 000000000000..882fe4f30d0b --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain/drop_column_unique_index @@ -0,0 +1,138 @@ +/* setup */ +CREATE DATABASE t; +CREATE TABLE t.test (k INT PRIMARY KEY, v INT, pi DECIMAL DEFAULT (DECIMAL '3.14')); +CREATE UNIQUE INDEX vidx ON t.test (v); +ALTER TABLE t.test ADD COLUMN x DECIMAL DEFAULT (DECIMAL '1.4') CHECK (x >= 0); + +/* test */ +EXPLAIN (ddl) ALTER TABLE t.test DROP pi; +---- +Schema change plan for ALTER TABLE ‹t›.‹public›.‹test› DROP COLUMN ‹pi›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 2 elements transitioning toward ABSENT + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 106, ColumnID: 3} + │ │ └── PUBLIC → ABSENT ColumnName:{DescID: 106, Name: pi, ColumnID: 3} + │ ├── 7 elements transitioning toward PUBLIC + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 4} + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 4} + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 106, ColumnID: 4, IndexID: 4} + │ │ ├── ABSENT → BACKFILL_ONLY PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 5} + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 5} + │ │ └── ABSENT → PUBLIC IndexColumn:{DescID: 106, ColumnID: 4, IndexID: 5} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} + │ └── 11 Mutation operations + │ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":3,"TableID":106} + │ ├── LogEvent {"TargetStatus":1} + │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":106} + │ ├── MakeAddedIndexBackfilling {"Index":{"ConstraintID":1,"IndexID":4,"IsUnique":true,"SourceIndexID":1,"TableID":106,"TemporaryIndexID":5}} + │ ├── MakeAddedTempIndexDeleteOnly {"Index":{"ConstraintID":1,"IndexID":5,"IsUnique":true,"SourceIndexID":1,"TableID":106}} + │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":5,"TableID":106} + │ ├── AddColumnToIndex {"ColumnID":2,"IndexID":5,"Kind":2,"TableID":106} + │ ├── AddColumnToIndex {"ColumnID":4,"IndexID":5,"Kind":2,"Ordinal":1,"TableID":106} + │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":4,"TableID":106} + │ ├── AddColumnToIndex {"ColumnID":2,"IndexID":4,"Kind":2,"TableID":106} + │ └── AddColumnToIndex {"ColumnID":4,"IndexID":4,"Kind":2,"Ordinal":1,"TableID":106} + ├── PreCommitPhase + │ └── Stage 1 of 1 in PreCommitPhase + │ └── 2 Mutation operations + │ ├── SetJobStateOnDescriptor {"DescriptorID":106,"Initialize":true} + │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + ├── PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":5,"TableID":106} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 2 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILL_ONLY → BACKFILLED PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── BackfillIndex {"IndexID":4,"SourceIndexID":1,"TableID":106} + │ ├── Stage 3 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILLED → DELETE_ONLY PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":4,"TableID":106} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 4 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── DELETE_ONLY → MERGE_ONLY PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfilledIndexMerging {"IndexID":4,"TableID":106} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 5 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGE_ONLY → MERGED PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── MergeIndex {"BackfilledIndexID":4,"TableID":106,"TemporaryIndexID":5} + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":4,"TableID":106} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":106} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── WRITE_ONLY → VALIDATED PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} + │ └── 1 Validation operation + │ └── ValidateUniqueIndex {"IndexID":4,"TableID":106} + └── PostCommitNonRevertiblePhase + ├── Stage 1 of 3 in PostCommitNonRevertiblePhase + │ ├── 7 elements transitioning toward ABSENT + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 106, ColumnID: 3} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 3, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 4, IndexID: 1} + │ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ └── PUBLIC → ABSENT IndexName:{DescID: 106, Name: test_pkey, IndexID: 1} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} + │ │ └── ABSENT → PUBLIC IndexName:{DescID: 106, Name: test_pkey, IndexID: 4} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} + │ └── 12 Mutation operations + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":3,"TableID":106} + │ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":106} + │ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":106} + │ ├── SetIndexName {"IndexID":4,"Name":"test_pkey","TableID":106} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":5,"TableID":106} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":1,"TableID":106} + │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":1,"Kind":2,"TableID":106} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":1,"Kind":2,"Ordinal":1,"TableID":106} + │ ├── RemoveColumnFromIndex {"ColumnID":4,"IndexID":1,"Kind":2,"Ordinal":2,"TableID":106} + │ ├── MakeAddedPrimaryIndexPublic {"IndexID":4,"TableID":106} + │ ├── SetJobStateOnDescriptor {"DescriptorID":106} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + ├── Stage 2 of 3 in PostCommitNonRevertiblePhase + │ ├── 1 element transitioning toward ABSENT + │ │ └── WRITE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ └── 3 Mutation operations + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":1,"TableID":106} + │ ├── SetJobStateOnDescriptor {"DescriptorID":106} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── Stage 3 of 3 in PostCommitNonRevertiblePhase + ├── 4 elements transitioning toward ABSENT + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 106, ColumnID: 3} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 3} + │ ├── PUBLIC → ABSENT ColumnDefaultExpression:{DescID: 106, ColumnID: 3} + │ └── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + ├── 1 element transitioning toward TRANSIENT_ABSENT + │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} + └── 8 Mutation operations + ├── CreateGcJobForIndex {"IndexID":5,"TableID":106} + ├── MakeIndexAbsent {"IndexID":5,"TableID":106} + ├── CreateGcJobForIndex {"IndexID":1,"TableID":106} + ├── MakeIndexAbsent {"IndexID":1,"TableID":106} + ├── RemoveColumnDefaultExpression {"ColumnID":3,"TableID":106} + ├── MakeColumnAbsent {"ColumnID":3,"TableID":106} + ├── RemoveJobStateFromDescriptor {"DescriptorID":106} + └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/drop_column_with_index b/pkg/sql/schemachanger/testdata/explain/drop_column_with_index new file mode 100644 index 000000000000..251a74bb5ca8 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain/drop_column_with_index @@ -0,0 +1,135 @@ +/* setup */ +create table t (i int primary key, j int, index (j)); + +/* test */ +EXPLAIN (ddl) alter table t drop column j; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 4 elements transitioning toward ABSENT + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ ├── PUBLIC → VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_j_idx, IndexID: 2} + │ ├── 3 elements transitioning toward PUBLIC + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} + │ │ ├── ABSENT → BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ └── 9 Mutation operations + │ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":2,"TableID":104} + │ ├── LogEvent {"TargetStatus":1} + │ ├── SetColumnName {"ColumnID":2,"Name":"crdb_internal_co...","TableID":104} + │ ├── MakeDroppedNonPrimaryIndexDeleteAndWriteOnly {"IndexID":2,"TableID":104} + │ ├── SetIndexName {"IndexID":2,"Name":"crdb_internal_in...","TableID":104} + │ ├── MakeAddedIndexBackfilling {"Index":{"ConstraintID":1,"IndexID":3,"IsUnique":true,"SourceIndexID":1,"TableID":104,"TemporaryIndexID":4}} + │ ├── MakeAddedTempIndexDeleteOnly {"Index":{"ConstraintID":1,"IndexID":4,"IsUnique":true,"SourceIndexID":1,"TableID":104}} + │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":4,"TableID":104} + │ └── AddColumnToIndex {"ColumnID":1,"IndexID":3,"TableID":104} + ├── PreCommitPhase + │ └── Stage 1 of 1 in PreCommitPhase + │ └── 2 Mutation operations + │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} + │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + ├── PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":4,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 2 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILL_ONLY → BACKFILLED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── BackfillIndex {"IndexID":3,"SourceIndexID":1,"TableID":104} + │ ├── Stage 3 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILLED → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 4 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── DELETE_ONLY → MERGE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfilledIndexMerging {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 5 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGE_ONLY → MERGED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── MergeIndex {"BackfilledIndexID":3,"TableID":104,"TemporaryIndexID":4} + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── WRITE_ONLY → VALIDATED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ └── 1 Validation operation + │ └── ValidateUniqueIndex {"IndexID":3,"TableID":104} + └── PostCommitNonRevertiblePhase + ├── Stage 1 of 3 in PostCommitNonRevertiblePhase + │ ├── 8 elements transitioning toward ABSENT + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ ├── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ └── VALIDATED → DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ └── 13 Mutation operations + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":2,"TableID":104} + │ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":104} + │ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":104} + │ ├── SetIndexName {"IndexID":3,"Name":"t_pkey","TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":4,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":1,"Kind":2,"TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":2,"TableID":104} + │ ├── MakeAddedPrimaryIndexPublic {"IndexID":3,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + ├── Stage 2 of 3 in PostCommitNonRevertiblePhase + │ ├── 1 element transitioning toward ABSENT + │ │ └── WRITE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── 3 Mutation operations + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── Stage 3 of 3 in PostCommitNonRevertiblePhase + ├── 4 elements transitioning toward ABSENT + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 2} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ ├── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── DELETE_ONLY → ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + ├── 1 element transitioning toward TRANSIENT_ABSENT + │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + └── 10 Mutation operations + ├── CreateGcJobForIndex {"IndexID":4,"TableID":104} + ├── MakeIndexAbsent {"IndexID":4,"TableID":104} + ├── CreateGcJobForIndex {"IndexID":1,"TableID":104} + ├── MakeIndexAbsent {"IndexID":1,"TableID":104} + ├── LogEvent {"TargetStatus":1} + ├── CreateGcJobForIndex {"IndexID":2,"TableID":104} + ├── MakeIndexAbsent {"IndexID":2,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":2,"TableID":104} + ├── RemoveJobStateFromDescriptor {"DescriptorID":104} + └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/drop_multiple_columns_separate_statements.0 b/pkg/sql/schemachanger/testdata/explain/drop_multiple_columns_separate_statements.0 new file mode 100644 index 000000000000..a37f8c4f8a6f --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain/drop_multiple_columns_separate_statements.0 @@ -0,0 +1,153 @@ +/* setup */ +create table t (i int primary key, j int, k int default 32 on update 42, index((j+1), k)); + +/* test */ +EXPLAIN (ddl) alter table t drop column j cascade; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 6 elements transitioning toward ABSENT + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 4} + │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 4} + │ │ ├── PUBLIC → VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_expr_k_idx, IndexID: 2} + │ ├── 5 elements transitioning toward PUBLIC + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3} + │ │ ├── ABSENT → BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} + │ │ └── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ └── 14 Mutation operations + │ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":2,"TableID":104} + │ ├── LogEvent {"TargetStatus":1} + │ ├── SetColumnName {"ColumnID":2,"Name":"crdb_internal_co...","TableID":104} + │ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":4,"TableID":104} + │ ├── LogEvent {"TargetStatus":1} + │ ├── SetColumnName {"ColumnID":4,"Name":"crdb_internal_co...","TableID":104} + │ ├── MakeDroppedNonPrimaryIndexDeleteAndWriteOnly {"IndexID":2,"TableID":104} + │ ├── SetIndexName {"IndexID":2,"Name":"crdb_internal_in...","TableID":104} + │ ├── MakeAddedIndexBackfilling {"Index":{"ConstraintID":1,"IndexID":3,"IsUnique":true,"SourceIndexID":1,"TableID":104,"TemporaryIndexID":4}} + │ ├── MakeAddedTempIndexDeleteOnly {"Index":{"ConstraintID":1,"IndexID":4,"IsUnique":true,"SourceIndexID":1,"TableID":104}} + │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":4,"TableID":104} + │ ├── AddColumnToIndex {"ColumnID":3,"IndexID":4,"Kind":2,"TableID":104} + │ ├── AddColumnToIndex {"ColumnID":1,"IndexID":3,"TableID":104} + │ └── AddColumnToIndex {"ColumnID":3,"IndexID":3,"Kind":2,"TableID":104} + ├── PreCommitPhase + │ └── Stage 1 of 1 in PreCommitPhase + │ └── 2 Mutation operations + │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} + │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + ├── PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":4,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 2 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILL_ONLY → BACKFILLED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── BackfillIndex {"IndexID":3,"SourceIndexID":1,"TableID":104} + │ ├── Stage 3 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILLED → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 4 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── DELETE_ONLY → MERGE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfilledIndexMerging {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 5 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGE_ONLY → MERGED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── MergeIndex {"BackfilledIndexID":3,"TableID":104,"TemporaryIndexID":4} + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── WRITE_ONLY → VALIDATED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ └── 1 Validation operation + │ └── ValidateUniqueIndex {"IndexID":3,"TableID":104} + └── PostCommitNonRevertiblePhase + ├── Stage 1 of 3 in PostCommitNonRevertiblePhase + │ ├── 11 elements transitioning toward ABSENT + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 4} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ ├── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ └── VALIDATED → DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ └── 16 Mutation operations + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":2,"TableID":104} + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":4,"TableID":104} + │ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":104} + │ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":104} + │ ├── SetIndexName {"IndexID":3,"Name":"t_pkey","TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":4,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":1,"Kind":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":1,"Kind":2,"Ordinal":1,"TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":2,"TableID":104} + │ ├── MakeAddedPrimaryIndexPublic {"IndexID":3,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":4,"IndexID":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Ordinal":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + ├── Stage 2 of 3 in PostCommitNonRevertiblePhase + │ ├── 1 element transitioning toward ABSENT + │ │ └── WRITE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── 3 Mutation operations + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── Stage 3 of 3 in PostCommitNonRevertiblePhase + ├── 6 elements transitioning toward ABSENT + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 2} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 4} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ ├── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── DELETE_ONLY → ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + ├── 1 element transitioning toward TRANSIENT_ABSENT + │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + └── 11 Mutation operations + ├── CreateGcJobForIndex {"IndexID":4,"TableID":104} + ├── MakeIndexAbsent {"IndexID":4,"TableID":104} + ├── CreateGcJobForIndex {"IndexID":1,"TableID":104} + ├── MakeIndexAbsent {"IndexID":1,"TableID":104} + ├── LogEvent {"TargetStatus":1} + ├── CreateGcJobForIndex {"IndexID":2,"TableID":104} + ├── MakeIndexAbsent {"IndexID":2,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":2,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":4,"TableID":104} + ├── RemoveJobStateFromDescriptor {"DescriptorID":104} + └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/drop_multiple_columns_separate_statements.1 b/pkg/sql/schemachanger/testdata/explain/drop_multiple_columns_separate_statements.1 new file mode 100644 index 000000000000..bc7c5fcee7a2 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain/drop_multiple_columns_separate_statements.1 @@ -0,0 +1,144 @@ +/* setup */ +create table t (i int primary key, j int, k int default 32 on update 42, index((j+1), k)); + +/* test */ +alter table t drop column j cascade; +EXPLAIN (ddl) alter table t drop column k cascade; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE; ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹k› CASCADE; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 2 elements transitioning toward ABSENT + │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 3} + │ │ └── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: k, ColumnID: 3} + │ └── 3 Mutation operations + │ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":3,"TableID":104} + │ ├── LogEvent {"TargetStatus":1} + │ └── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} + ├── PreCommitPhase + │ └── Stage 1 of 1 in PreCommitPhase + │ └── 2 Mutation operations + │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} + │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + ├── PostCommitPhase + │ ├── Stage 1 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ └── DELETE_ONLY → WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeAddedIndexDeleteAndWriteOnly {"IndexID":4,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 2 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILL_ONLY → BACKFILLED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── BackfillIndex {"IndexID":3,"SourceIndexID":1,"TableID":104} + │ ├── Stage 3 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── BACKFILLED → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfillingIndexDeleteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 4 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── DELETE_ONLY → MERGE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeBackfilledIndexMerging {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ ├── Stage 5 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGE_ONLY → MERGED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 1 Backfill operation + │ │ └── MergeIndex {"BackfilledIndexID":3,"TableID":104,"TemporaryIndexID":4} + │ ├── Stage 6 of 7 in PostCommitPhase + │ │ ├── 1 element transitioning toward PUBLIC + │ │ │ └── MERGED → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── 3 Mutation operations + │ │ ├── MakeMergedIndexWriteOnly {"IndexID":3,"TableID":104} + │ │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ │ └── UpdateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} + │ └── Stage 7 of 7 in PostCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── WRITE_ONLY → VALIDATED PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ └── 1 Validation operation + │ └── ValidateUniqueIndex {"IndexID":3,"TableID":104} + └── PostCommitNonRevertiblePhase + ├── Stage 1 of 3 in PostCommitNonRevertiblePhase + │ ├── 14 elements transitioning toward ABSENT + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 4} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ ├── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ ├── VALIDATED → DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3} + │ │ └── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ └── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ ├── 1 element transitioning toward TRANSIENT_ABSENT + │ │ └── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ └── 19 Mutation operations + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":3,"TableID":104} + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":2,"TableID":104} + │ ├── MakeDroppedColumnDeleteOnly {"ColumnID":4,"TableID":104} + │ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":104} + │ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"Kind":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":4,"Kind":2,"TableID":104} + │ ├── SetIndexName {"IndexID":3,"Name":"t_pkey","TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":4,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":1,"Kind":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":1,"Kind":2,"Ordinal":1,"TableID":104} + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":2,"TableID":104} + │ ├── MakeAddedPrimaryIndexPublic {"IndexID":3,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":4,"IndexID":2,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Ordinal":1,"TableID":104} + │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + ├── Stage 2 of 3 in PostCommitNonRevertiblePhase + │ ├── 1 element transitioning toward ABSENT + │ │ └── WRITE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── 3 Mutation operations + │ ├── MakeDroppedIndexDeleteOnly {"IndexID":1,"TableID":104} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104} + │ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── Stage 3 of 3 in PostCommitNonRevertiblePhase + ├── 10 elements transitioning toward ABSENT + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 3} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} + │ ├── PUBLIC → ABSENT ColumnDefaultExpression:{DescID: 104, ColumnID: 3} + │ ├── PUBLIC → ABSENT ColumnOnUpdateExpression:{DescID: 104, ColumnID: 3} + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 2} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 4} + │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ ├── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ └── DELETE_ONLY → ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + ├── 1 element transitioning toward TRANSIENT_ABSENT + │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + └── 14 Mutation operations + ├── CreateGcJobForIndex {"IndexID":4,"TableID":104} + ├── MakeIndexAbsent {"IndexID":4,"TableID":104} + ├── CreateGcJobForIndex {"IndexID":1,"TableID":104} + ├── MakeIndexAbsent {"IndexID":1,"TableID":104} + ├── LogEvent {"TargetStatus":1} + ├── CreateGcJobForIndex {"IndexID":2,"TableID":104} + ├── MakeIndexAbsent {"IndexID":2,"TableID":104} + ├── RemoveColumnDefaultExpression {"ColumnID":3,"TableID":104} + ├── RemoveColumnOnUpdateExpression {"ColumnID":3,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":2,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":4,"TableID":104} + ├── MakeColumnAbsent {"ColumnID":3,"TableID":104} + ├── RemoveJobStateFromDescriptor {"DescriptorID":104} + └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_basic b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_basic new file mode 100644 index 000000000000..3d48e69ccee3 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_basic @@ -0,0 +1,473 @@ +/* setup */ +create table t (i int primary key, j int); + +/* test */ +EXPLAIN (ddl, verbose) alter table t drop column j; +---- +• Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j›; +│ +├── • StatementPhase +│ │ +│ └── • Stage 1 of 1 in StatementPhase +│ │ +│ ├── • 2 elements transitioning toward ABSENT +│ │ │ +│ │ ├── • Column:{DescID: 104, ColumnID: 2} +│ │ │ PUBLIC → WRITE_ONLY +│ │ │ +│ │ └── • ColumnName:{DescID: 104, Name: j, ColumnID: 2} +│ │ │ PUBLIC → ABSENT +│ │ │ +│ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} +│ │ rule: "column dependents removed after column no longer public" +│ │ +│ ├── • 3 elements transitioning toward PUBLIC +│ │ │ +│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ rule: "index-column added to index after index exists" +│ │ │ +│ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ ABSENT → BACKFILL_ONLY +│ │ │ +│ │ └── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ ABSENT → PUBLIC +│ │ │ +│ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} +│ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ rule: "index-column added to index after temp index exists" +│ │ +│ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ +│ │ └── • TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} +│ │ ABSENT → DELETE_ONLY +│ │ +│ └── • 7 Mutation operations +│ │ +│ ├── • MakeDroppedColumnDeleteAndWriteOnly +│ │ ColumnID: 2 +│ │ TableID: 104 +│ │ +│ ├── • LogEvent +│ │ Element: +│ │ Column: +│ │ columnId: 2 +│ │ pgAttributeNum: 2 +│ │ tableId: 104 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› +│ │ StatementTag: ALTER TABLE +│ │ TargetMetadata: +│ │ SourceElementID: 1 +│ │ SubWorkID: 1 +│ │ TargetStatus: 1 +│ │ +│ ├── • SetColumnName +│ │ ColumnID: 2 +│ │ Name: crdb_internal_column_2_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeAddedIndexBackfilling +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 2 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ TemporaryIndexID: 3 +│ │ +│ ├── • MakeAddedTempIndexDeleteOnly +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 3 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 1 +│ │ IndexID: 3 +│ │ TableID: 104 +│ │ +│ └── • AddColumnToIndex +│ ColumnID: 1 +│ IndexID: 2 +│ TableID: 104 +│ +├── • PreCommitPhase +│ │ +│ └── • Stage 1 of 1 in PreCommitPhase +│ │ +│ └── • 2 Mutation operations +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 104 +│ │ Initialize: true +│ │ +│ └── • CreateSchemaChangerJob +│ Authorization: +│ UserName: root +│ DescriptorIDs: +│ - 104 +│ JobID: 1 +│ RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending +│ Statements: +│ - statement: ALTER TABLE t DROP COLUMN j +│ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› +│ statementtag: ALTER TABLE +│ +├── • PostCommitPhase +│ │ +│ ├── • Stage 1 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ │ +│ │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} +│ │ │ │ DELETE_ONLY → WRITE_ONLY +│ │ │ │ +│ │ │ └── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 2 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ │ BACKFILL_ONLY → BACKFILLED +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} +│ │ │ rule: "temp index is WRITE_ONLY before backfill" +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • BackfillIndex +│ │ IndexID: 2 +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • Stage 3 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ BACKFILLED → DELETE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfillingIndexDeleteOnly +│ │ │ IndexID: 2 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending +│ │ +│ ├── • Stage 4 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ DELETE_ONLY → MERGE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfilledIndexMerging +│ │ │ IndexID: 2 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 5 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ MERGE_ONLY → MERGED +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • MergeIndex +│ │ BackfilledIndexID: 2 +│ │ TableID: 104 +│ │ TemporaryIndexID: 3 +│ │ +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 2 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase +│ │ +│ ├── • 1 element transitioning toward PUBLIC +│ │ │ +│ │ └── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} +│ │ WRITE_ONLY → VALIDATED +│ │ +│ └── • 1 Validation operation +│ │ +│ └── • ValidateUniqueIndex +│ IndexID: 2 +│ TableID: 104 +│ +└── • PostCommitNonRevertiblePhase + │ + ├── • Stage 1 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 5 elements transitioning toward ABSENT + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ PUBLIC → WRITE_ONLY + │ │ │ + │ │ └── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ rule: "index no longer public before dependents removed" + │ │ + │ ├── • 2 elements transitioning toward PUBLIC + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ │ │ VALIDATED → PUBLIC + │ │ │ │ + │ │ │ ├── • SameStagePrecedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ │ rule: "primary index swap" + │ │ │ │ + │ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 2} + │ │ │ rule: "index named right before index becomes public" + │ │ │ + │ │ └── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 2} + │ │ │ ABSENT → PUBLIC + │ │ │ + │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1} + │ │ rule: "index existence precedes index name and comment" + │ │ + │ ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ + │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} + │ │ WRITE_ONLY → TRANSIENT_DELETE_ONLY + │ │ + │ └── • 10 Mutation operations + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedPrimaryIndexDeleteAndWriteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 1 + │ │ Name: crdb_internal_index_1_name_placeholder + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 2 + │ │ Name: t_pkey + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 3 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 2 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeAddedPrimaryIndexPublic + │ │ EventBase: + │ │ Authorization: + │ │ UserName: root + │ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + │ │ StatementTag: ALTER TABLE + │ │ TargetMetadata: + │ │ SourceElementID: 1 + │ │ SubWorkID: 1 + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending + │ + ├── • Stage 2 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 1 element transitioning toward ABSENT + │ │ │ + │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ WRITE_ONLY → DELETE_ONLY + │ │ + │ └── • 3 Mutation operations + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 3 of 3 with 5 MutationType ops pending + │ + └── • Stage 3 of 3 in PostCommitNonRevertiblePhase + │ + ├── • 3 elements transitioning toward ABSENT + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ └── • Precedence dependency from ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ rule: "indexes containing columns reach absent before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ └── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ DELETE_ONLY → ABSENT + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ rule: "dependents removed before index" + │ │ + │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} + │ rule: "temp indexes reach absent at the same time as other indexes" + │ + ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ + │ └── • TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1} + │ TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT + │ + └── • 7 Mutation operations + │ + ├── • CreateGcJobForIndex + │ IndexID: 3 + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 3 + │ TableID: 104 + │ + ├── • CreateGcJobForIndex + │ IndexID: 1 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ IndexID: 1 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 2 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 104 + │ JobID: 1 + │ + └── • UpdateSchemaChangerJob + IsNonCancelable: true + JobID: 1 + RunningStatus: all stages completed diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_computed_index b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_computed_index new file mode 100644 index 000000000000..7d9223976b67 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_computed_index @@ -0,0 +1,642 @@ +/* setup */ +create table t (i int primary key, j int, index((j+1))); + +/* test */ +EXPLAIN (ddl, verbose) alter table t drop column j cascade; +---- +• Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE; +│ +├── • StatementPhase +│ │ +│ └── • Stage 1 of 1 in StatementPhase +│ │ +│ ├── • 6 elements transitioning toward ABSENT +│ │ │ +│ │ ├── • Column:{DescID: 104, ColumnID: 2} +│ │ │ PUBLIC → WRITE_ONLY +│ │ │ +│ │ ├── • ColumnName:{DescID: 104, Name: j, ColumnID: 2} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} +│ │ │ rule: "column dependents removed after column no longer public" +│ │ │ +│ │ ├── • Column:{DescID: 104, ColumnID: 3} +│ │ │ PUBLIC → WRITE_ONLY +│ │ │ +│ │ ├── • ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 3} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 3} +│ │ │ rule: "column dependents removed after column no longer public" +│ │ │ +│ │ ├── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} +│ │ │ PUBLIC → VALIDATED +│ │ │ +│ │ └── • IndexName:{DescID: 104, Name: t_expr_idx, IndexID: 2} +│ │ │ PUBLIC → ABSENT +│ │ │ +│ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} +│ │ rule: "index no longer public before dependents removed" +│ │ +│ ├── • 3 elements transitioning toward PUBLIC +│ │ │ +│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ rule: "index-column added to index after index exists" +│ │ │ +│ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ ABSENT → BACKFILL_ONLY +│ │ │ +│ │ └── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} +│ │ │ ABSENT → PUBLIC +│ │ │ +│ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ rule: "index-column added to index after temp index exists" +│ │ +│ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ +│ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ ABSENT → DELETE_ONLY +│ │ +│ └── • 12 Mutation operations +│ │ +│ ├── • MakeDroppedColumnDeleteAndWriteOnly +│ │ ColumnID: 2 +│ │ TableID: 104 +│ │ +│ ├── • LogEvent +│ │ Element: +│ │ Column: +│ │ columnId: 2 +│ │ pgAttributeNum: 2 +│ │ tableId: 104 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ │ StatementTag: ALTER TABLE +│ │ TargetMetadata: +│ │ SourceElementID: 1 +│ │ SubWorkID: 1 +│ │ TargetStatus: 1 +│ │ +│ ├── • SetColumnName +│ │ ColumnID: 2 +│ │ Name: crdb_internal_column_2_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeDroppedColumnDeleteAndWriteOnly +│ │ ColumnID: 3 +│ │ TableID: 104 +│ │ +│ ├── • LogEvent +│ │ Element: +│ │ Column: +│ │ columnId: 3 +│ │ isInaccessible: true +│ │ pgAttributeNum: 3 +│ │ tableId: 104 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ │ StatementTag: ALTER TABLE +│ │ TargetMetadata: +│ │ SourceElementID: 1 +│ │ SubWorkID: 1 +│ │ TargetStatus: 1 +│ │ +│ ├── • SetColumnName +│ │ ColumnID: 3 +│ │ Name: crdb_internal_column_3_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeDroppedNonPrimaryIndexDeleteAndWriteOnly +│ │ IndexID: 2 +│ │ TableID: 104 +│ │ +│ ├── • SetIndexName +│ │ IndexID: 2 +│ │ Name: crdb_internal_index_2_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeAddedIndexBackfilling +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 3 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ TemporaryIndexID: 4 +│ │ +│ ├── • MakeAddedTempIndexDeleteOnly +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 4 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 1 +│ │ IndexID: 4 +│ │ TableID: 104 +│ │ +│ └── • AddColumnToIndex +│ ColumnID: 1 +│ IndexID: 3 +│ TableID: 104 +│ +├── • PreCommitPhase +│ │ +│ └── • Stage 1 of 1 in PreCommitPhase +│ │ +│ └── • 2 Mutation operations +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 104 +│ │ Initialize: true +│ │ +│ └── • CreateSchemaChangerJob +│ Authorization: +│ UserName: root +│ DescriptorIDs: +│ - 104 +│ JobID: 1 +│ RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending +│ Statements: +│ - statement: ALTER TABLE t DROP COLUMN j CASCADE +│ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ statementtag: ALTER TABLE +│ +├── • PostCommitPhase +│ │ +│ ├── • Stage 1 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ │ +│ │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ │ DELETE_ONLY → WRITE_ONLY +│ │ │ │ +│ │ │ └── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} +│ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ │ IndexID: 4 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 2 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ │ BACKFILL_ONLY → BACKFILLED +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ rule: "temp index is WRITE_ONLY before backfill" +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • BackfillIndex +│ │ IndexID: 3 +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • Stage 3 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ BACKFILLED → DELETE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfillingIndexDeleteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending +│ │ +│ ├── • Stage 4 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ DELETE_ONLY → MERGE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfilledIndexMerging +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 5 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGE_ONLY → MERGED +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • MergeIndex +│ │ BackfilledIndexID: 3 +│ │ TableID: 104 +│ │ TemporaryIndexID: 4 +│ │ +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase +│ │ +│ ├── • 1 element transitioning toward PUBLIC +│ │ │ +│ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ WRITE_ONLY → VALIDATED +│ │ +│ └── • 1 Validation operation +│ │ +│ └── • ValidateUniqueIndex +│ IndexID: 3 +│ TableID: 104 +│ +└── • PostCommitNonRevertiblePhase + │ + ├── • Stage 1 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 9 elements transitioning toward ABSENT + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 3} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ PUBLIC → WRITE_ONLY + │ │ │ + │ │ ├── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ VALIDATED → DELETE_ONLY + │ │ + │ ├── • 2 elements transitioning toward PUBLIC + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ │ │ VALIDATED → PUBLIC + │ │ │ │ + │ │ │ ├── • SameStagePrecedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ │ rule: "primary index swap" + │ │ │ │ + │ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ rule: "index named right before index becomes public" + │ │ │ + │ │ └── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ ABSENT → PUBLIC + │ │ │ + │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ rule: "index existence precedes index name and comment" + │ │ + │ ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ + │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ WRITE_ONLY → TRANSIENT_DELETE_ONLY + │ │ + │ └── • 14 Mutation operations + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 3 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedPrimaryIndexDeleteAndWriteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 1 + │ │ Name: crdb_internal_index_1_name_placeholder + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 3 + │ │ Name: t_pkey + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 4 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 2 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeAddedPrimaryIndexPublic + │ │ EventBase: + │ │ Authorization: + │ │ UserName: root + │ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ │ StatementTag: ALTER TABLE + │ │ TargetMetadata: + │ │ SourceElementID: 1 + │ │ SubWorkID: 1 + │ │ IndexID: 3 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 2 + │ │ Kind: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending + │ + ├── • Stage 2 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 1 element transitioning toward ABSENT + │ │ │ + │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ WRITE_ONLY → DELETE_ONLY + │ │ + │ └── • 3 Mutation operations + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 3 of 3 with 9 MutationType ops pending + │ + └── • Stage 3 of 3 in PostCommitNonRevertiblePhase + │ + ├── • 6 elements transitioning toward ABSENT + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ └── • Precedence dependency from ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ rule: "indexes containing columns reach absent before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 3} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 3} + │ │ │ rule: "dependents removed before column" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ └── • Precedence dependency from ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ rule: "indexes containing columns reach absent before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 3} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ rule: "temp indexes reach absent at the same time as other indexes" + │ │ + │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ DELETE_ONLY → ABSENT + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_expr_idx, IndexID: 2} + │ │ rule: "dependents removed before index" + │ │ + │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ rule: "temp indexes reach absent at the same time as other indexes" + │ + ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ + │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT + │ + └── • 11 Mutation operations + │ + ├── • CreateGcJobForIndex + │ IndexID: 4 + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 4 + │ TableID: 104 + │ + ├── • CreateGcJobForIndex + │ IndexID: 1 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ IndexID: 1 + │ TableID: 104 + │ + ├── • LogEvent + │ Element: + │ SecondaryIndex: + │ indexId: 2 + │ tableId: 104 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TargetStatus: 1 + │ + ├── • CreateGcJobForIndex + │ IndexID: 2 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 2 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 2 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 3 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 104 + │ JobID: 1 + │ + └── • UpdateSchemaChangerJob + IsNonCancelable: true + JobID: 1 + RunningStatus: all stages completed diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_create_index_separate_statements.0 b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_create_index_separate_statements.0 new file mode 100644 index 000000000000..e5680981ea52 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_create_index_separate_statements.0 @@ -0,0 +1,708 @@ +/* setup */ +create table t (i int primary key, j int, k int default 32 on update 42, index((j+1), k)); + +/* test */ +EXPLAIN (ddl, verbose) alter table t drop column j cascade; +---- +• Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE; +│ +├── • StatementPhase +│ │ +│ └── • Stage 1 of 1 in StatementPhase +│ │ +│ ├── • 6 elements transitioning toward ABSENT +│ │ │ +│ │ ├── • Column:{DescID: 104, ColumnID: 2} +│ │ │ PUBLIC → WRITE_ONLY +│ │ │ +│ │ ├── • ColumnName:{DescID: 104, Name: j, ColumnID: 2} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} +│ │ │ rule: "column dependents removed after column no longer public" +│ │ │ +│ │ ├── • Column:{DescID: 104, ColumnID: 4} +│ │ │ PUBLIC → WRITE_ONLY +│ │ │ +│ │ ├── • ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 4} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 4} +│ │ │ rule: "column dependents removed after column no longer public" +│ │ │ +│ │ ├── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} +│ │ │ PUBLIC → VALIDATED +│ │ │ +│ │ └── • IndexName:{DescID: 104, Name: t_expr_k_idx, IndexID: 2} +│ │ │ PUBLIC → ABSENT +│ │ │ +│ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} +│ │ rule: "index no longer public before dependents removed" +│ │ +│ ├── • 5 elements transitioning toward PUBLIC +│ │ │ +│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ rule: "index-column added to index after index exists" +│ │ │ +│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ rule: "index-column added to index after index exists" +│ │ │ +│ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ ABSENT → BACKFILL_ONLY +│ │ │ +│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ │ rule: "index-column added to index after temp index exists" +│ │ │ +│ │ └── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4} +│ │ │ ABSENT → PUBLIC +│ │ │ +│ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ rule: "index-column added to index after temp index exists" +│ │ +│ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ +│ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ ABSENT → DELETE_ONLY +│ │ +│ └── • 14 Mutation operations +│ │ +│ ├── • MakeDroppedColumnDeleteAndWriteOnly +│ │ ColumnID: 2 +│ │ TableID: 104 +│ │ +│ ├── • LogEvent +│ │ Element: +│ │ Column: +│ │ columnId: 2 +│ │ pgAttributeNum: 2 +│ │ tableId: 104 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ │ StatementTag: ALTER TABLE +│ │ TargetMetadata: +│ │ SourceElementID: 1 +│ │ SubWorkID: 1 +│ │ TargetStatus: 1 +│ │ +│ ├── • SetColumnName +│ │ ColumnID: 2 +│ │ Name: crdb_internal_column_2_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeDroppedColumnDeleteAndWriteOnly +│ │ ColumnID: 4 +│ │ TableID: 104 +│ │ +│ ├── • LogEvent +│ │ Element: +│ │ Column: +│ │ columnId: 4 +│ │ isInaccessible: true +│ │ pgAttributeNum: 4 +│ │ tableId: 104 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ │ StatementTag: ALTER TABLE +│ │ TargetMetadata: +│ │ SourceElementID: 1 +│ │ SubWorkID: 1 +│ │ TargetStatus: 1 +│ │ +│ ├── • SetColumnName +│ │ ColumnID: 4 +│ │ Name: crdb_internal_column_4_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeDroppedNonPrimaryIndexDeleteAndWriteOnly +│ │ IndexID: 2 +│ │ TableID: 104 +│ │ +│ ├── • SetIndexName +│ │ IndexID: 2 +│ │ Name: crdb_internal_index_2_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeAddedIndexBackfilling +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 3 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ TemporaryIndexID: 4 +│ │ +│ ├── • MakeAddedTempIndexDeleteOnly +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 4 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 1 +│ │ IndexID: 4 +│ │ TableID: 104 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 3 +│ │ IndexID: 4 +│ │ Kind: 2 +│ │ TableID: 104 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 1 +│ │ IndexID: 3 +│ │ TableID: 104 +│ │ +│ └── • AddColumnToIndex +│ ColumnID: 3 +│ IndexID: 3 +│ Kind: 2 +│ TableID: 104 +│ +├── • PreCommitPhase +│ │ +│ └── • Stage 1 of 1 in PreCommitPhase +│ │ +│ └── • 2 Mutation operations +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 104 +│ │ Initialize: true +│ │ +│ └── • CreateSchemaChangerJob +│ Authorization: +│ UserName: root +│ DescriptorIDs: +│ - 104 +│ JobID: 1 +│ RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending +│ Statements: +│ - statement: ALTER TABLE t DROP COLUMN j CASCADE +│ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ statementtag: ALTER TABLE +│ +├── • PostCommitPhase +│ │ +│ ├── • Stage 1 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ │ +│ │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ │ DELETE_ONLY → WRITE_ONLY +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} +│ │ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ │ +│ │ │ └── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4} +│ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ │ IndexID: 4 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 2 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ │ BACKFILL_ONLY → BACKFILLED +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ rule: "temp index is WRITE_ONLY before backfill" +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • BackfillIndex +│ │ IndexID: 3 +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • Stage 3 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ BACKFILLED → DELETE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfillingIndexDeleteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending +│ │ +│ ├── • Stage 4 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ DELETE_ONLY → MERGE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfilledIndexMerging +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 5 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGE_ONLY → MERGED +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • MergeIndex +│ │ BackfilledIndexID: 3 +│ │ TableID: 104 +│ │ TemporaryIndexID: 4 +│ │ +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase +│ │ +│ ├── • 1 element transitioning toward PUBLIC +│ │ │ +│ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ WRITE_ONLY → VALIDATED +│ │ +│ └── • 1 Validation operation +│ │ +│ └── • ValidateUniqueIndex +│ IndexID: 3 +│ TableID: 104 +│ +└── • PostCommitNonRevertiblePhase + │ + ├── • Stage 1 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 11 elements transitioning toward ABSENT + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 4} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ PUBLIC → WRITE_ONLY + │ │ │ + │ │ ├── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ VALIDATED → DELETE_ONLY + │ │ + │ ├── • 2 elements transitioning toward PUBLIC + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ │ │ VALIDATED → PUBLIC + │ │ │ │ + │ │ │ ├── • SameStagePrecedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ │ rule: "primary index swap" + │ │ │ │ + │ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ rule: "index named right before index becomes public" + │ │ │ + │ │ └── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ ABSENT → PUBLIC + │ │ │ + │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ rule: "index existence precedes index name and comment" + │ │ + │ ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ + │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ WRITE_ONLY → TRANSIENT_DELETE_ONLY + │ │ + │ └── • 16 Mutation operations + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 4 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedPrimaryIndexDeleteAndWriteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 1 + │ │ Name: crdb_internal_index_1_name_placeholder + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 3 + │ │ Name: t_pkey + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 4 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 2 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ Ordinal: 1 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeAddedPrimaryIndexPublic + │ │ EventBase: + │ │ Authorization: + │ │ UserName: root + │ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ │ StatementTag: ALTER TABLE + │ │ TargetMetadata: + │ │ SourceElementID: 1 + │ │ SubWorkID: 1 + │ │ IndexID: 3 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 4 + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 2 + │ │ Ordinal: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 2 + │ │ Kind: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending + │ + ├── • Stage 2 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 1 element transitioning toward ABSENT + │ │ │ + │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ WRITE_ONLY → DELETE_ONLY + │ │ + │ └── • 3 Mutation operations + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 3 of 3 with 9 MutationType ops pending + │ + └── • Stage 3 of 3 in PostCommitNonRevertiblePhase + │ + ├── • 6 elements transitioning toward ABSENT + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ └── • Precedence dependency from ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ rule: "indexes containing columns reach absent before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 4} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 4} + │ │ │ rule: "dependents removed before column" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ └── • Precedence dependency from ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ rule: "indexes containing columns reach absent before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 4} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ rule: "temp indexes reach absent at the same time as other indexes" + │ │ + │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ DELETE_ONLY → ABSENT + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_expr_k_idx, IndexID: 2} + │ │ rule: "dependents removed before index" + │ │ + │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ rule: "temp indexes reach absent at the same time as other indexes" + │ + ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ + │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT + │ + └── • 11 Mutation operations + │ + ├── • CreateGcJobForIndex + │ IndexID: 4 + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 4 + │ TableID: 104 + │ + ├── • CreateGcJobForIndex + │ IndexID: 1 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ IndexID: 1 + │ TableID: 104 + │ + ├── • LogEvent + │ Element: + │ SecondaryIndex: + │ indexId: 2 + │ tableId: 104 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TargetStatus: 1 + │ + ├── • CreateGcJobForIndex + │ IndexID: 2 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 2 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 2 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 4 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 104 + │ JobID: 1 + │ + └── • UpdateSchemaChangerJob + IsNonCancelable: true + JobID: 1 + RunningStatus: all stages completed diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_create_index_separate_statements.1 b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_create_index_separate_statements.1 new file mode 100644 index 000000000000..8e4a8d43d558 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_create_index_separate_statements.1 @@ -0,0 +1,804 @@ +/* setup */ +create table t (i int primary key, j int, k int default 32 on update 42, index((j+1), k)); + +/* test */ +alter table t drop column j cascade; +EXPLAIN (ddl, verbose) create unique index idx on t(k); +---- +• Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE; CREATE UNIQUE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹k›); +│ +├── • PreCommitPhase +│ │ +│ └── • Stage 1 of 1 in PreCommitPhase +│ │ +│ └── • 2 Mutation operations +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 104 +│ │ Initialize: true +│ │ +│ └── • CreateSchemaChangerJob +│ Authorization: +│ UserName: root +│ DescriptorIDs: +│ - 104 +│ JobID: 1 +│ RunningStatus: PostCommitPhase stage 1 of 15 with 1 MutationType op pending +│ Statements: +│ - statement: ALTER TABLE t DROP COLUMN j CASCADE +│ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ statementtag: ALTER TABLE +│ - statement: CREATE UNIQUE INDEX idx ON t (k) +│ redactedstatement: CREATE UNIQUE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹k›) +│ statementtag: CREATE INDEX +│ +├── • PostCommitPhase +│ │ +│ ├── • Stage 1 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ │ +│ │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ │ DELETE_ONLY → WRITE_ONLY +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} +│ │ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ │ +│ │ │ └── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4} +│ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ │ IndexID: 4 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 2 of 15 with 1 BackfillType op pending +│ │ +│ ├── • Stage 2 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ │ BACKFILL_ONLY → BACKFILLED +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ rule: "temp index is WRITE_ONLY before backfill" +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • BackfillIndex +│ │ IndexID: 3 +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • Stage 3 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ BACKFILLED → DELETE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfillingIndexDeleteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 4 of 15 with 1 MutationType op pending +│ │ +│ ├── • Stage 4 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ DELETE_ONLY → MERGE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfilledIndexMerging +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 5 of 15 with 1 BackfillType op pending +│ │ +│ ├── • Stage 5 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGE_ONLY → MERGED +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • MergeIndex +│ │ BackfilledIndexID: 3 +│ │ TableID: 104 +│ │ TemporaryIndexID: 4 +│ │ +│ ├── • Stage 6 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 15 with 1 ValidationType op pending +│ │ +│ ├── • Stage 7 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ WRITE_ONLY → VALIDATED +│ │ │ +│ │ └── • 1 Validation operation +│ │ │ +│ │ └── • ValidateUniqueIndex +│ │ IndexID: 3 +│ │ TableID: 104 +│ │ +│ ├── • Stage 8 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 2 elements transitioning toward ABSENT +│ │ │ │ +│ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} +│ │ │ │ PUBLIC → VALIDATED +│ │ │ │ +│ │ │ └── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} +│ │ │ rule: "index no longer public before dependents removed" +│ │ │ +│ │ ├── • 7 elements transitioning toward PUBLIC +│ │ │ │ +│ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ │ │ VALIDATED → PUBLIC +│ │ │ │ │ +│ │ │ │ ├── • SameStagePrecedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} +│ │ │ │ │ rule: "primary index swap" +│ │ │ │ │ +│ │ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} +│ │ │ │ rule: "index named right before index becomes public" +│ │ │ │ +│ │ │ ├── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} +│ │ │ │ │ ABSENT → PUBLIC +│ │ │ │ │ +│ │ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ │ rule: "index existence precedes index name and comment" +│ │ │ │ +│ │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 5} +│ │ │ │ │ ABSENT → PUBLIC +│ │ │ │ │ +│ │ │ │ └── • Precedence dependency from BACKFILL_ONLY SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} +│ │ │ │ rule: "index-column added to index after index exists" +│ │ │ │ +│ │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 5} +│ │ │ │ │ ABSENT → PUBLIC +│ │ │ │ │ +│ │ │ │ └── • Precedence dependency from BACKFILL_ONLY SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} +│ │ │ │ rule: "index-column added to index after index exists" +│ │ │ │ +│ │ │ ├── • SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} +│ │ │ │ │ ABSENT → BACKFILL_ONLY +│ │ │ │ │ +│ │ │ │ └── • Precedence dependency from PUBLIC PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ │ rule: "primary index with new columns should exist before secondary indexes" +│ │ │ │ +│ │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 6} +│ │ │ │ │ ABSENT → PUBLIC +│ │ │ │ │ +│ │ │ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} +│ │ │ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ │ │ rule: "index-column added to index after temp index exists" +│ │ │ │ +│ │ │ └── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 6} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} +│ │ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ │ rule: "index-column added to index after temp index exists" +│ │ │ +│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ │ +│ │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} +│ │ │ │ ABSENT → DELETE_ONLY +│ │ │ │ +│ │ │ └── • Precedence dependency from PUBLIC PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ rule: "primary index with new columns should exist before temp indexes" +│ │ │ +│ │ └── • 12 Mutation operations +│ │ │ +│ │ ├── • MakeDroppedPrimaryIndexDeleteAndWriteOnly +│ │ │ IndexID: 1 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetIndexName +│ │ │ IndexID: 1 +│ │ │ Name: crdb_internal_index_1_name_placeholder +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetIndexName +│ │ │ IndexID: 3 +│ │ │ Name: t_pkey +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • MakeAddedPrimaryIndexPublic +│ │ │ EventBase: +│ │ │ Authorization: +│ │ │ UserName: root +│ │ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ │ │ StatementTag: ALTER TABLE +│ │ │ TargetMetadata: +│ │ │ SourceElementID: 1 +│ │ │ SubWorkID: 1 +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • MakeAddedIndexBackfilling +│ │ │ Index: +│ │ │ IndexID: 5 +│ │ │ IsUnique: true +│ │ │ SourceIndexID: 3 +│ │ │ TableID: 104 +│ │ │ TemporaryIndexID: 6 +│ │ │ IsSecondaryIndex: true +│ │ │ +│ │ ├── • MakeAddedTempIndexDeleteOnly +│ │ │ Index: +│ │ │ IndexID: 6 +│ │ │ IsUnique: true +│ │ │ SourceIndexID: 3 +│ │ │ TableID: 104 +│ │ │ IsSecondaryIndex: true +│ │ │ +│ │ ├── • AddColumnToIndex +│ │ │ ColumnID: 3 +│ │ │ IndexID: 6 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • AddColumnToIndex +│ │ │ ColumnID: 1 +│ │ │ IndexID: 6 +│ │ │ Kind: 1 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • AddColumnToIndex +│ │ │ ColumnID: 3 +│ │ │ IndexID: 5 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • AddColumnToIndex +│ │ │ ColumnID: 1 +│ │ │ IndexID: 5 +│ │ │ Kind: 1 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 9 of 15 with 1 MutationType op pending +│ │ +│ ├── • Stage 9 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ │ +│ │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} +│ │ │ │ DELETE_ONLY → WRITE_ONLY +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 6} +│ │ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ │ +│ │ │ └── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 6} +│ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ │ IndexID: 6 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 10 of 15 with 1 BackfillType op pending +│ │ +│ ├── • Stage 10 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} +│ │ │ │ BACKFILL_ONLY → BACKFILLED +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 5} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 5} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} +│ │ │ rule: "temp index is WRITE_ONLY before backfill" +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • BackfillIndex +│ │ IndexID: 5 +│ │ SourceIndexID: 3 +│ │ TableID: 104 +│ │ +│ ├── • Stage 11 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} +│ │ │ BACKFILLED → DELETE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfillingIndexDeleteOnly +│ │ │ IndexID: 5 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 12 of 15 with 1 MutationType op pending +│ │ +│ ├── • Stage 12 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} +│ │ │ DELETE_ONLY → MERGE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfilledIndexMerging +│ │ │ IndexID: 5 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 13 of 15 with 1 BackfillType op pending +│ │ +│ ├── • Stage 13 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} +│ │ │ MERGE_ONLY → MERGED +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • MergeIndex +│ │ BackfilledIndexID: 5 +│ │ TableID: 104 +│ │ TemporaryIndexID: 6 +│ │ +│ ├── • Stage 14 of 15 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 5 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 15 of 15 with 1 ValidationType op pending +│ │ +│ └── • Stage 15 of 15 in PostCommitPhase +│ │ +│ ├── • 1 element transitioning toward PUBLIC +│ │ │ +│ │ └── • SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} +│ │ WRITE_ONLY → VALIDATED +│ │ +│ └── • 1 Validation operation +│ │ +│ └── • ValidateUniqueIndex +│ IndexID: 5 +│ TableID: 104 +│ +└── • PostCommitNonRevertiblePhase + │ + ├── • Stage 1 of 2 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 10 elements transitioning toward ABSENT + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 4} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ VALIDATED → DELETE_ONLY + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ VALIDATED → DELETE_ONLY + │ │ + │ ├── • 2 elements transitioning toward PUBLIC + │ │ │ + │ │ ├── • SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} + │ │ │ │ VALIDATED → PUBLIC + │ │ │ │ + │ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 104, Name: idx, IndexID: 5} + │ │ │ rule: "index named right before index becomes public" + │ │ │ + │ │ └── • IndexName:{DescID: 104, Name: idx, IndexID: 5} + │ │ │ ABSENT → PUBLIC + │ │ │ + │ │ └── • Precedence dependency from BACKFILL_ONLY SecondaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 0, TemporaryIndexID: 6, SourceIndexID: 3} + │ │ rule: "index existence precedes index name and comment" + │ │ + │ ├── • 2 elements transitioning toward TRANSIENT_ABSENT + │ │ │ + │ │ ├── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ │ WRITE_ONLY → TRANSIENT_DELETE_ONLY + │ │ │ + │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} + │ │ WRITE_ONLY → TRANSIENT_DELETE_ONLY + │ │ + │ └── • 16 Mutation operations + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 4 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 2 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ Ordinal: 1 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 4 + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 5 + │ │ Name: idx + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 6 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeAddedSecondaryIndexPublic + │ │ IndexID: 5 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 4 + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 2 + │ │ Ordinal: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 2 + │ │ Kind: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 2 of 2 with 11 MutationType ops + │ pending + │ + └── • Stage 2 of 2 in PostCommitNonRevertiblePhase + │ + ├── • 6 elements transitioning toward ABSENT + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "indexes containing columns reach absent before column" + │ │ │ + │ │ └── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ rule: "dependents removed before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 4} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "indexes containing columns reach absent before column" + │ │ │ + │ │ └── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 4} + │ │ rule: "dependents removed before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 4} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ │ rule: "temp indexes reach absent at the same time as other indexes" + │ │ │ + │ │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} + │ │ rule: "temp indexes reach absent at the same time as other indexes" + │ │ + │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ DELETE_ONLY → ABSENT + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_expr_k_idx, IndexID: 2} + │ │ rule: "dependents removed before index" + │ │ + │ ├── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ rule: "temp indexes reach absent at the same time as other indexes" + │ │ + │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} + │ rule: "temp indexes reach absent at the same time as other indexes" + │ + ├── • 2 elements transitioning toward TRANSIENT_ABSENT + │ │ + │ ├── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT + │ │ + │ └── • TemporaryIndex:{DescID: 104, IndexID: 6, SourceIndexID: 3} + │ TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT + │ + └── • 13 Mutation operations + │ + ├── • CreateGcJobForIndex + │ IndexID: 4 + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 4 + │ TableID: 104 + │ + ├── • CreateGcJobForIndex + │ IndexID: 6 + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 6 + │ TableID: 104 + │ + ├── • CreateGcJobForIndex + │ IndexID: 1 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ IndexID: 1 + │ TableID: 104 + │ + ├── • LogEvent + │ Element: + │ SecondaryIndex: + │ indexId: 2 + │ tableId: 104 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TargetStatus: 1 + │ + ├── • CreateGcJobForIndex + │ IndexID: 2 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 2 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 2 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 4 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 104 + │ JobID: 1 + │ + └── • UpdateSchemaChangerJob + IsNonCancelable: true + JobID: 1 + RunningStatus: all stages completed diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_unique_index b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_unique_index new file mode 100644 index 000000000000..22c510e63749 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_unique_index @@ -0,0 +1,582 @@ +/* setup */ +CREATE DATABASE t; +CREATE TABLE t.test (k INT PRIMARY KEY, v INT, pi DECIMAL DEFAULT (DECIMAL '3.14')); +CREATE UNIQUE INDEX vidx ON t.test (v); +ALTER TABLE t.test ADD COLUMN x DECIMAL DEFAULT (DECIMAL '1.4') CHECK (x >= 0); + +/* test */ +EXPLAIN (ddl, verbose) ALTER TABLE t.test DROP pi; +---- +• Schema change plan for ALTER TABLE ‹t›.‹public›.‹test› DROP COLUMN ‹pi›; +│ +├── • StatementPhase +│ │ +│ └── • Stage 1 of 1 in StatementPhase +│ │ +│ ├── • 2 elements transitioning toward ABSENT +│ │ │ +│ │ ├── • Column:{DescID: 106, ColumnID: 3} +│ │ │ PUBLIC → WRITE_ONLY +│ │ │ +│ │ └── • ColumnName:{DescID: 106, Name: pi, ColumnID: 3} +│ │ │ PUBLIC → ABSENT +│ │ │ +│ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 3} +│ │ rule: "column dependents removed after column no longer public" +│ │ +│ ├── • 7 elements transitioning toward PUBLIC +│ │ │ +│ │ ├── • IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 4} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} +│ │ │ rule: "index-column added to index after index exists" +│ │ │ +│ │ ├── • IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 4} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} +│ │ │ rule: "index-column added to index after index exists" +│ │ │ +│ │ ├── • IndexColumn:{DescID: 106, ColumnID: 4, IndexID: 4} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} +│ │ │ rule: "index-column added to index after index exists" +│ │ │ +│ │ ├── • PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} +│ │ │ ABSENT → BACKFILL_ONLY +│ │ │ +│ │ ├── • IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 5} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} +│ │ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ │ rule: "index-column added to index after temp index exists" +│ │ │ +│ │ ├── • IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 5} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} +│ │ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ │ rule: "index-column added to index after temp index exists" +│ │ │ +│ │ └── • IndexColumn:{DescID: 106, ColumnID: 4, IndexID: 5} +│ │ │ ABSENT → PUBLIC +│ │ │ +│ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} +│ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ rule: "index-column added to index after temp index exists" +│ │ +│ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ +│ │ └── • TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} +│ │ ABSENT → DELETE_ONLY +│ │ +│ └── • 11 Mutation operations +│ │ +│ ├── • MakeDroppedColumnDeleteAndWriteOnly +│ │ ColumnID: 3 +│ │ TableID: 106 +│ │ +│ ├── • LogEvent +│ │ Element: +│ │ Column: +│ │ columnId: 3 +│ │ pgAttributeNum: 3 +│ │ tableId: 106 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: ALTER TABLE ‹t›.‹public›.‹test› DROP COLUMN ‹pi› +│ │ StatementTag: ALTER TABLE +│ │ TargetMetadata: +│ │ SourceElementID: 1 +│ │ SubWorkID: 1 +│ │ TargetStatus: 1 +│ │ +│ ├── • SetColumnName +│ │ ColumnID: 3 +│ │ Name: crdb_internal_column_3_name_placeholder +│ │ TableID: 106 +│ │ +│ ├── • MakeAddedIndexBackfilling +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 4 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 106 +│ │ TemporaryIndexID: 5 +│ │ +│ ├── • MakeAddedTempIndexDeleteOnly +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 5 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 106 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 1 +│ │ IndexID: 5 +│ │ TableID: 106 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 2 +│ │ IndexID: 5 +│ │ Kind: 2 +│ │ TableID: 106 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 4 +│ │ IndexID: 5 +│ │ Kind: 2 +│ │ Ordinal: 1 +│ │ TableID: 106 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 1 +│ │ IndexID: 4 +│ │ TableID: 106 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 2 +│ │ IndexID: 4 +│ │ Kind: 2 +│ │ TableID: 106 +│ │ +│ └── • AddColumnToIndex +│ ColumnID: 4 +│ IndexID: 4 +│ Kind: 2 +│ Ordinal: 1 +│ TableID: 106 +│ +├── • PreCommitPhase +│ │ +│ └── • Stage 1 of 1 in PreCommitPhase +│ │ +│ └── • 2 Mutation operations +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 106 +│ │ Initialize: true +│ │ +│ └── • CreateSchemaChangerJob +│ Authorization: +│ UserName: root +│ DescriptorIDs: +│ - 106 +│ JobID: 1 +│ RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending +│ Statements: +│ - statement: ALTER TABLE t.test DROP COLUMN pi +│ redactedstatement: ALTER TABLE ‹t›.‹public›.‹test› DROP COLUMN ‹pi› +│ statementtag: ALTER TABLE +│ +├── • PostCommitPhase +│ │ +│ ├── • Stage 1 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ │ +│ │ │ └── • TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} +│ │ │ │ DELETE_ONLY → WRITE_ONLY +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 5} +│ │ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 5} +│ │ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ │ +│ │ │ └── • Precedence dependency from PUBLIC IndexColumn:{DescID: 106, ColumnID: 4, IndexID: 5} +│ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ │ IndexID: 5 +│ │ │ TableID: 106 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 106 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 2 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} +│ │ │ │ BACKFILL_ONLY → BACKFILLED +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 4} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 4} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 106, ColumnID: 4, IndexID: 4} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} +│ │ │ rule: "temp index is WRITE_ONLY before backfill" +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • BackfillIndex +│ │ IndexID: 4 +│ │ SourceIndexID: 1 +│ │ TableID: 106 +│ │ +│ ├── • Stage 3 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} +│ │ │ BACKFILLED → DELETE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfillingIndexDeleteOnly +│ │ │ IndexID: 4 +│ │ │ TableID: 106 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 106 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending +│ │ +│ ├── • Stage 4 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} +│ │ │ DELETE_ONLY → MERGE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfilledIndexMerging +│ │ │ IndexID: 4 +│ │ │ TableID: 106 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 106 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 5 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} +│ │ │ MERGE_ONLY → MERGED +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • MergeIndex +│ │ BackfilledIndexID: 4 +│ │ TableID: 106 +│ │ TemporaryIndexID: 5 +│ │ +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 4 +│ │ │ TableID: 106 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 106 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase +│ │ +│ ├── • 1 element transitioning toward PUBLIC +│ │ │ +│ │ └── • PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} +│ │ WRITE_ONLY → VALIDATED +│ │ +│ └── • 1 Validation operation +│ │ +│ └── • ValidateUniqueIndex +│ IndexID: 4 +│ TableID: 106 +│ +└── • PostCommitNonRevertiblePhase + │ + ├── • Stage 1 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 7 elements transitioning toward ABSENT + │ │ │ + │ │ ├── • Column:{DescID: 106, ColumnID: 3} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 106, ColumnID: 3, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 106, ColumnID: 4, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ │ PUBLIC → WRITE_ONLY + │ │ │ + │ │ └── • IndexName:{DescID: 106, Name: test_pkey, IndexID: 1} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ rule: "index no longer public before dependents removed" + │ │ + │ ├── • 2 elements transitioning toward PUBLIC + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} + │ │ │ │ VALIDATED → PUBLIC + │ │ │ │ + │ │ │ ├── • SameStagePrecedence dependency from VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ │ │ rule: "primary index swap" + │ │ │ │ + │ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 106, Name: test_pkey, IndexID: 4} + │ │ │ rule: "index named right before index becomes public" + │ │ │ + │ │ └── • IndexName:{DescID: 106, Name: test_pkey, IndexID: 4} + │ │ │ ABSENT → PUBLIC + │ │ │ + │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 106, IndexID: 4, ConstraintID: 1, TemporaryIndexID: 5, SourceIndexID: 1} + │ │ rule: "index existence precedes index name and comment" + │ │ + │ ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ + │ │ └── • TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} + │ │ WRITE_ONLY → TRANSIENT_DELETE_ONLY + │ │ + │ └── • 12 Mutation operations + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 3 + │ │ TableID: 106 + │ │ + │ ├── • MakeDroppedPrimaryIndexDeleteAndWriteOnly + │ │ IndexID: 1 + │ │ TableID: 106 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 1 + │ │ Name: crdb_internal_index_1_name_placeholder + │ │ TableID: 106 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 4 + │ │ Name: test_pkey + │ │ TableID: 106 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 5 + │ │ TableID: 106 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 1 + │ │ TableID: 106 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 2 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ TableID: 106 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ Ordinal: 1 + │ │ TableID: 106 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 4 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ Ordinal: 2 + │ │ TableID: 106 + │ │ + │ ├── • MakeAddedPrimaryIndexPublic + │ │ EventBase: + │ │ Authorization: + │ │ UserName: root + │ │ Statement: ALTER TABLE ‹t›.‹public›.‹test› DROP COLUMN ‹pi› + │ │ StatementTag: ALTER TABLE + │ │ TargetMetadata: + │ │ SourceElementID: 1 + │ │ SubWorkID: 1 + │ │ IndexID: 4 + │ │ TableID: 106 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 106 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending + │ + ├── • Stage 2 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 1 element transitioning toward ABSENT + │ │ │ + │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ WRITE_ONLY → DELETE_ONLY + │ │ + │ └── • 3 Mutation operations + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 1 + │ │ TableID: 106 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 106 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 3 of 3 with 6 MutationType ops pending + │ + └── • Stage 3 of 3 in PostCommitNonRevertiblePhase + │ + ├── • 4 elements transitioning toward ABSENT + │ │ + │ ├── • Column:{DescID: 106, ColumnID: 3} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 106, Name: pi, ColumnID: 3} + │ │ │ rule: "dependents removed before column" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 3} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ └── • Precedence dependency from ABSENT PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ rule: "indexes containing columns reach absent before column" + │ │ + │ ├── • ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 3} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 106, ColumnID: 3} + │ │ │ rule: "column dependents removed after column no longer public" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ColumnDefaultExpression:{DescID: 106, ColumnID: 3} + │ │ rule: "column type dependents removed right before column type" + │ │ + │ ├── • ColumnDefaultExpression:{DescID: 106, ColumnID: 3} + │ │ PUBLIC → ABSENT + │ │ + │ └── • PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} + │ │ DELETE_ONLY → ABSENT + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1} + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1} + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 106, ColumnID: 3, IndexID: 1} + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 106, ColumnID: 4, IndexID: 1} + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 106, Name: test_pkey, IndexID: 1} + │ │ rule: "dependents removed before index" + │ │ + │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} + │ rule: "temp indexes reach absent at the same time as other indexes" + │ + ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ + │ └── • TemporaryIndex:{DescID: 106, IndexID: 5, SourceIndexID: 1} + │ TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT + │ + └── • 8 Mutation operations + │ + ├── • CreateGcJobForIndex + │ IndexID: 5 + │ TableID: 106 + │ + ├── • MakeIndexAbsent + │ IndexID: 5 + │ TableID: 106 + │ + ├── • CreateGcJobForIndex + │ IndexID: 1 + │ StatementForDropJob: + │ Statement: ALTER TABLE t.public.test DROP COLUMN pi + │ TableID: 106 + │ + ├── • MakeIndexAbsent + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹t›.‹public›.‹test› DROP COLUMN ‹pi› + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ IndexID: 1 + │ TableID: 106 + │ + ├── • RemoveColumnDefaultExpression + │ ColumnID: 3 + │ TableID: 106 + │ + ├── • MakeColumnAbsent + │ ColumnID: 3 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹t›.‹public›.‹test› DROP COLUMN ‹pi› + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 106 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 106 + │ JobID: 1 + │ + └── • UpdateSchemaChangerJob + IsNonCancelable: true + JobID: 1 + RunningStatus: all stages completed diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_with_index b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_with_index new file mode 100644 index 000000000000..4f82afc2c8ae --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_column_with_index @@ -0,0 +1,572 @@ +/* setup */ +create table t (i int primary key, j int, index (j)); + +/* test */ +EXPLAIN (ddl, verbose) alter table t drop column j; +---- +• Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j›; +│ +├── • StatementPhase +│ │ +│ └── • Stage 1 of 1 in StatementPhase +│ │ +│ ├── • 4 elements transitioning toward ABSENT +│ │ │ +│ │ ├── • Column:{DescID: 104, ColumnID: 2} +│ │ │ PUBLIC → WRITE_ONLY +│ │ │ +│ │ ├── • ColumnName:{DescID: 104, Name: j, ColumnID: 2} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} +│ │ │ rule: "column dependents removed after column no longer public" +│ │ │ +│ │ ├── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} +│ │ │ PUBLIC → VALIDATED +│ │ │ +│ │ └── • IndexName:{DescID: 104, Name: t_j_idx, IndexID: 2} +│ │ │ PUBLIC → ABSENT +│ │ │ +│ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} +│ │ rule: "index no longer public before dependents removed" +│ │ +│ ├── • 3 elements transitioning toward PUBLIC +│ │ │ +│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ rule: "index-column added to index after index exists" +│ │ │ +│ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ ABSENT → BACKFILL_ONLY +│ │ │ +│ │ └── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} +│ │ │ ABSENT → PUBLIC +│ │ │ +│ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ rule: "index-column added to index after temp index exists" +│ │ +│ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ +│ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ ABSENT → DELETE_ONLY +│ │ +│ └── • 9 Mutation operations +│ │ +│ ├── • MakeDroppedColumnDeleteAndWriteOnly +│ │ ColumnID: 2 +│ │ TableID: 104 +│ │ +│ ├── • LogEvent +│ │ Element: +│ │ Column: +│ │ columnId: 2 +│ │ pgAttributeNum: 2 +│ │ tableId: 104 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› +│ │ StatementTag: ALTER TABLE +│ │ TargetMetadata: +│ │ SourceElementID: 1 +│ │ SubWorkID: 1 +│ │ TargetStatus: 1 +│ │ +│ ├── • SetColumnName +│ │ ColumnID: 2 +│ │ Name: crdb_internal_column_2_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeDroppedNonPrimaryIndexDeleteAndWriteOnly +│ │ IndexID: 2 +│ │ TableID: 104 +│ │ +│ ├── • SetIndexName +│ │ IndexID: 2 +│ │ Name: crdb_internal_index_2_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeAddedIndexBackfilling +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 3 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ TemporaryIndexID: 4 +│ │ +│ ├── • MakeAddedTempIndexDeleteOnly +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 4 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 1 +│ │ IndexID: 4 +│ │ TableID: 104 +│ │ +│ └── • AddColumnToIndex +│ ColumnID: 1 +│ IndexID: 3 +│ TableID: 104 +│ +├── • PreCommitPhase +│ │ +│ └── • Stage 1 of 1 in PreCommitPhase +│ │ +│ └── • 2 Mutation operations +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 104 +│ │ Initialize: true +│ │ +│ └── • CreateSchemaChangerJob +│ Authorization: +│ UserName: root +│ DescriptorIDs: +│ - 104 +│ JobID: 1 +│ RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending +│ Statements: +│ - statement: ALTER TABLE t DROP COLUMN j +│ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› +│ statementtag: ALTER TABLE +│ +├── • PostCommitPhase +│ │ +│ ├── • Stage 1 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ │ +│ │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ │ DELETE_ONLY → WRITE_ONLY +│ │ │ │ +│ │ │ └── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} +│ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ │ IndexID: 4 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 2 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ │ BACKFILL_ONLY → BACKFILLED +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ rule: "temp index is WRITE_ONLY before backfill" +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • BackfillIndex +│ │ IndexID: 3 +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • Stage 3 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ BACKFILLED → DELETE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfillingIndexDeleteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending +│ │ +│ ├── • Stage 4 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ DELETE_ONLY → MERGE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfilledIndexMerging +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 5 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGE_ONLY → MERGED +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • MergeIndex +│ │ BackfilledIndexID: 3 +│ │ TableID: 104 +│ │ TemporaryIndexID: 4 +│ │ +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase +│ │ +│ ├── • 1 element transitioning toward PUBLIC +│ │ │ +│ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ WRITE_ONLY → VALIDATED +│ │ +│ └── • 1 Validation operation +│ │ +│ └── • ValidateUniqueIndex +│ IndexID: 3 +│ TableID: 104 +│ +└── • PostCommitNonRevertiblePhase + │ + ├── • Stage 1 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 8 elements transitioning toward ABSENT + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ PUBLIC → WRITE_ONLY + │ │ │ + │ │ ├── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ VALIDATED → DELETE_ONLY + │ │ + │ ├── • 2 elements transitioning toward PUBLIC + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ │ │ VALIDATED → PUBLIC + │ │ │ │ + │ │ │ ├── • SameStagePrecedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ │ rule: "primary index swap" + │ │ │ │ + │ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ rule: "index named right before index becomes public" + │ │ │ + │ │ └── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ ABSENT → PUBLIC + │ │ │ + │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ rule: "index existence precedes index name and comment" + │ │ + │ ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ + │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ WRITE_ONLY → TRANSIENT_DELETE_ONLY + │ │ + │ └── • 13 Mutation operations + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedPrimaryIndexDeleteAndWriteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 1 + │ │ Name: crdb_internal_index_1_name_placeholder + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 3 + │ │ Name: t_pkey + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 4 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 2 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeAddedPrimaryIndexPublic + │ │ EventBase: + │ │ Authorization: + │ │ UserName: root + │ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + │ │ StatementTag: ALTER TABLE + │ │ TargetMetadata: + │ │ SourceElementID: 1 + │ │ SubWorkID: 1 + │ │ IndexID: 3 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 2 + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 2 + │ │ Kind: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending + │ + ├── • Stage 2 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 1 element transitioning toward ABSENT + │ │ │ + │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ WRITE_ONLY → DELETE_ONLY + │ │ + │ └── • 3 Mutation operations + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 3 of 3 with 8 MutationType ops pending + │ + └── • Stage 3 of 3 in PostCommitNonRevertiblePhase + │ + ├── • 4 elements transitioning toward ABSENT + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "indexes containing columns reach absent before column" + │ │ │ + │ │ └── • Precedence dependency from ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ rule: "indexes containing columns reach absent before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ rule: "temp indexes reach absent at the same time as other indexes" + │ │ + │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ DELETE_ONLY → ABSENT + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_j_idx, IndexID: 2} + │ │ rule: "dependents removed before index" + │ │ + │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ rule: "temp indexes reach absent at the same time as other indexes" + │ + ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ + │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT + │ + └── • 10 Mutation operations + │ + ├── • CreateGcJobForIndex + │ IndexID: 4 + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 4 + │ TableID: 104 + │ + ├── • CreateGcJobForIndex + │ IndexID: 1 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ IndexID: 1 + │ TableID: 104 + │ + ├── • LogEvent + │ Element: + │ SecondaryIndex: + │ indexId: 2 + │ tableId: 104 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TargetStatus: 1 + │ + ├── • CreateGcJobForIndex + │ IndexID: 2 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 2 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 2 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 104 + │ JobID: 1 + │ + └── • UpdateSchemaChangerJob + IsNonCancelable: true + JobID: 1 + RunningStatus: all stages completed diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_multiple_columns_separate_statements.0 b/pkg/sql/schemachanger/testdata/explain_verbose/drop_multiple_columns_separate_statements.0 new file mode 100644 index 000000000000..e5680981ea52 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_multiple_columns_separate_statements.0 @@ -0,0 +1,708 @@ +/* setup */ +create table t (i int primary key, j int, k int default 32 on update 42, index((j+1), k)); + +/* test */ +EXPLAIN (ddl, verbose) alter table t drop column j cascade; +---- +• Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE; +│ +├── • StatementPhase +│ │ +│ └── • Stage 1 of 1 in StatementPhase +│ │ +│ ├── • 6 elements transitioning toward ABSENT +│ │ │ +│ │ ├── • Column:{DescID: 104, ColumnID: 2} +│ │ │ PUBLIC → WRITE_ONLY +│ │ │ +│ │ ├── • ColumnName:{DescID: 104, Name: j, ColumnID: 2} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} +│ │ │ rule: "column dependents removed after column no longer public" +│ │ │ +│ │ ├── • Column:{DescID: 104, ColumnID: 4} +│ │ │ PUBLIC → WRITE_ONLY +│ │ │ +│ │ ├── • ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 4} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 4} +│ │ │ rule: "column dependents removed after column no longer public" +│ │ │ +│ │ ├── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} +│ │ │ PUBLIC → VALIDATED +│ │ │ +│ │ └── • IndexName:{DescID: 104, Name: t_expr_k_idx, IndexID: 2} +│ │ │ PUBLIC → ABSENT +│ │ │ +│ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} +│ │ rule: "index no longer public before dependents removed" +│ │ +│ ├── • 5 elements transitioning toward PUBLIC +│ │ │ +│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ rule: "index-column added to index after index exists" +│ │ │ +│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ rule: "index-column added to index after index exists" +│ │ │ +│ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ ABSENT → BACKFILL_ONLY +│ │ │ +│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ │ rule: "index-column added to index after temp index exists" +│ │ │ +│ │ └── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4} +│ │ │ ABSENT → PUBLIC +│ │ │ +│ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ rule: "temp index exists before columns, partitioning, and partial" +│ │ rule: "index-column added to index after temp index exists" +│ │ +│ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ +│ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ ABSENT → DELETE_ONLY +│ │ +│ └── • 14 Mutation operations +│ │ +│ ├── • MakeDroppedColumnDeleteAndWriteOnly +│ │ ColumnID: 2 +│ │ TableID: 104 +│ │ +│ ├── • LogEvent +│ │ Element: +│ │ Column: +│ │ columnId: 2 +│ │ pgAttributeNum: 2 +│ │ tableId: 104 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ │ StatementTag: ALTER TABLE +│ │ TargetMetadata: +│ │ SourceElementID: 1 +│ │ SubWorkID: 1 +│ │ TargetStatus: 1 +│ │ +│ ├── • SetColumnName +│ │ ColumnID: 2 +│ │ Name: crdb_internal_column_2_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeDroppedColumnDeleteAndWriteOnly +│ │ ColumnID: 4 +│ │ TableID: 104 +│ │ +│ ├── • LogEvent +│ │ Element: +│ │ Column: +│ │ columnId: 4 +│ │ isInaccessible: true +│ │ pgAttributeNum: 4 +│ │ tableId: 104 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ │ StatementTag: ALTER TABLE +│ │ TargetMetadata: +│ │ SourceElementID: 1 +│ │ SubWorkID: 1 +│ │ TargetStatus: 1 +│ │ +│ ├── • SetColumnName +│ │ ColumnID: 4 +│ │ Name: crdb_internal_column_4_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeDroppedNonPrimaryIndexDeleteAndWriteOnly +│ │ IndexID: 2 +│ │ TableID: 104 +│ │ +│ ├── • SetIndexName +│ │ IndexID: 2 +│ │ Name: crdb_internal_index_2_name_placeholder +│ │ TableID: 104 +│ │ +│ ├── • MakeAddedIndexBackfilling +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 3 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ TemporaryIndexID: 4 +│ │ +│ ├── • MakeAddedTempIndexDeleteOnly +│ │ Index: +│ │ ConstraintID: 1 +│ │ IndexID: 4 +│ │ IsUnique: true +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 1 +│ │ IndexID: 4 +│ │ TableID: 104 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 3 +│ │ IndexID: 4 +│ │ Kind: 2 +│ │ TableID: 104 +│ │ +│ ├── • AddColumnToIndex +│ │ ColumnID: 1 +│ │ IndexID: 3 +│ │ TableID: 104 +│ │ +│ └── • AddColumnToIndex +│ ColumnID: 3 +│ IndexID: 3 +│ Kind: 2 +│ TableID: 104 +│ +├── • PreCommitPhase +│ │ +│ └── • Stage 1 of 1 in PreCommitPhase +│ │ +│ └── • 2 Mutation operations +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 104 +│ │ Initialize: true +│ │ +│ └── • CreateSchemaChangerJob +│ Authorization: +│ UserName: root +│ DescriptorIDs: +│ - 104 +│ JobID: 1 +│ RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending +│ Statements: +│ - statement: ALTER TABLE t DROP COLUMN j CASCADE +│ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ statementtag: ALTER TABLE +│ +├── • PostCommitPhase +│ │ +│ ├── • Stage 1 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ │ +│ │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ │ DELETE_ONLY → WRITE_ONLY +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} +│ │ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ │ +│ │ │ └── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4} +│ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ │ IndexID: 4 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 2 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ │ BACKFILL_ONLY → BACKFILLED +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ rule: "temp index is WRITE_ONLY before backfill" +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • BackfillIndex +│ │ IndexID: 3 +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • Stage 3 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ BACKFILLED → DELETE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfillingIndexDeleteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending +│ │ +│ ├── • Stage 4 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ DELETE_ONLY → MERGE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfilledIndexMerging +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 5 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGE_ONLY → MERGED +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • MergeIndex +│ │ BackfilledIndexID: 3 +│ │ TableID: 104 +│ │ TemporaryIndexID: 4 +│ │ +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase +│ │ +│ ├── • 1 element transitioning toward PUBLIC +│ │ │ +│ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ WRITE_ONLY → VALIDATED +│ │ +│ └── • 1 Validation operation +│ │ +│ └── • ValidateUniqueIndex +│ IndexID: 3 +│ TableID: 104 +│ +└── • PostCommitNonRevertiblePhase + │ + ├── • Stage 1 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 11 elements transitioning toward ABSENT + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 4} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ PUBLIC → WRITE_ONLY + │ │ │ + │ │ ├── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ VALIDATED → DELETE_ONLY + │ │ + │ ├── • 2 elements transitioning toward PUBLIC + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ │ │ VALIDATED → PUBLIC + │ │ │ │ + │ │ │ ├── • SameStagePrecedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ │ rule: "primary index swap" + │ │ │ │ + │ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ rule: "index named right before index becomes public" + │ │ │ + │ │ └── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ ABSENT → PUBLIC + │ │ │ + │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ rule: "index existence precedes index name and comment" + │ │ + │ ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ + │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ WRITE_ONLY → TRANSIENT_DELETE_ONLY + │ │ + │ └── • 16 Mutation operations + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 4 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedPrimaryIndexDeleteAndWriteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 1 + │ │ Name: crdb_internal_index_1_name_placeholder + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 3 + │ │ Name: t_pkey + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 4 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 2 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ Ordinal: 1 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeAddedPrimaryIndexPublic + │ │ EventBase: + │ │ Authorization: + │ │ UserName: root + │ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ │ StatementTag: ALTER TABLE + │ │ TargetMetadata: + │ │ SourceElementID: 1 + │ │ SubWorkID: 1 + │ │ IndexID: 3 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 4 + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 2 + │ │ Ordinal: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 2 + │ │ Kind: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending + │ + ├── • Stage 2 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 1 element transitioning toward ABSENT + │ │ │ + │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ WRITE_ONLY → DELETE_ONLY + │ │ + │ └── • 3 Mutation operations + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 3 of 3 with 9 MutationType ops pending + │ + └── • Stage 3 of 3 in PostCommitNonRevertiblePhase + │ + ├── • 6 elements transitioning toward ABSENT + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ └── • Precedence dependency from ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ rule: "indexes containing columns reach absent before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 4} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 4} + │ │ │ rule: "dependents removed before column" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ └── • Precedence dependency from ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ rule: "indexes containing columns reach absent before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 4} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ rule: "temp indexes reach absent at the same time as other indexes" + │ │ + │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ DELETE_ONLY → ABSENT + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_expr_k_idx, IndexID: 2} + │ │ rule: "dependents removed before index" + │ │ + │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ rule: "temp indexes reach absent at the same time as other indexes" + │ + ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ + │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT + │ + └── • 11 Mutation operations + │ + ├── • CreateGcJobForIndex + │ IndexID: 4 + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 4 + │ TableID: 104 + │ + ├── • CreateGcJobForIndex + │ IndexID: 1 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ IndexID: 1 + │ TableID: 104 + │ + ├── • LogEvent + │ Element: + │ SecondaryIndex: + │ indexId: 2 + │ tableId: 104 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TargetStatus: 1 + │ + ├── • CreateGcJobForIndex + │ IndexID: 2 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 2 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 2 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 4 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 104 + │ JobID: 1 + │ + └── • UpdateSchemaChangerJob + IsNonCancelable: true + JobID: 1 + RunningStatus: all stages completed diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_multiple_columns_separate_statements.1 b/pkg/sql/schemachanger/testdata/explain_verbose/drop_multiple_columns_separate_statements.1 new file mode 100644 index 000000000000..152b7878543b --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_multiple_columns_separate_statements.1 @@ -0,0 +1,660 @@ +/* setup */ +create table t (i int primary key, j int, k int default 32 on update 42, index((j+1), k)); + +/* test */ +alter table t drop column j cascade; +EXPLAIN (ddl, verbose) alter table t drop column k cascade; +---- +• Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE; ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹k› CASCADE; +│ +├── • StatementPhase +│ │ +│ └── • Stage 1 of 1 in StatementPhase +│ │ +│ ├── • 2 elements transitioning toward ABSENT +│ │ │ +│ │ ├── • Column:{DescID: 104, ColumnID: 3} +│ │ │ PUBLIC → WRITE_ONLY +│ │ │ +│ │ └── • ColumnName:{DescID: 104, Name: k, ColumnID: 3} +│ │ │ PUBLIC → ABSENT +│ │ │ +│ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 3} +│ │ rule: "column dependents removed after column no longer public" +│ │ +│ └── • 3 Mutation operations +│ │ +│ ├── • MakeDroppedColumnDeleteAndWriteOnly +│ │ ColumnID: 3 +│ │ TableID: 104 +│ │ +│ ├── • LogEvent +│ │ Element: +│ │ Column: +│ │ columnId: 3 +│ │ pgAttributeNum: 3 +│ │ tableId: 104 +│ │ EventBase: +│ │ Authorization: +│ │ UserName: root +│ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹k› CASCADE +│ │ StatementTag: ALTER TABLE +│ │ TargetMetadata: +│ │ SourceElementID: 1 +│ │ StatementID: 1 +│ │ SubWorkID: 1 +│ │ TargetStatus: 1 +│ │ +│ └── • SetColumnName +│ ColumnID: 3 +│ Name: crdb_internal_column_3_name_placeholder +│ TableID: 104 +│ +├── • PreCommitPhase +│ │ +│ └── • Stage 1 of 1 in PreCommitPhase +│ │ +│ └── • 2 Mutation operations +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 104 +│ │ Initialize: true +│ │ +│ └── • CreateSchemaChangerJob +│ Authorization: +│ UserName: root +│ DescriptorIDs: +│ - 104 +│ JobID: 1 +│ RunningStatus: PostCommitPhase stage 1 of 7 with 1 MutationType op pending +│ Statements: +│ - statement: ALTER TABLE t DROP COLUMN j CASCADE +│ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE +│ statementtag: ALTER TABLE +│ - statement: ALTER TABLE t DROP COLUMN k CASCADE +│ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹k› CASCADE +│ statementtag: ALTER TABLE +│ +├── • PostCommitPhase +│ │ +│ ├── • Stage 1 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT +│ │ │ │ +│ │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ │ DELETE_ONLY → WRITE_ONLY +│ │ │ │ +│ │ │ └── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4} +│ │ │ rule: "index-column added to index before temp index receives writes" +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeAddedIndexDeleteAndWriteOnly +│ │ │ IndexID: 4 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 2 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ │ BACKFILL_ONLY → BACKFILLED +│ │ │ │ +│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} +│ │ │ │ rule: "index-column added to index before index is backfilled" +│ │ │ │ +│ │ │ └── • Precedence dependency from WRITE_ONLY TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} +│ │ │ rule: "temp index is WRITE_ONLY before backfill" +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • BackfillIndex +│ │ IndexID: 3 +│ │ SourceIndexID: 1 +│ │ TableID: 104 +│ │ +│ ├── • Stage 3 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ BACKFILLED → DELETE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfillingIndexDeleteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending +│ │ +│ ├── • Stage 4 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ DELETE_ONLY → MERGE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeBackfilledIndexMerging +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending +│ │ +│ ├── • Stage 5 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGE_ONLY → MERGED +│ │ │ +│ │ └── • 1 Backfill operation +│ │ │ +│ │ └── • MergeIndex +│ │ BackfilledIndexID: 3 +│ │ TableID: 104 +│ │ TemporaryIndexID: 4 +│ │ +│ ├── • Stage 6 of 7 in PostCommitPhase +│ │ │ +│ │ ├── • 1 element transitioning toward PUBLIC +│ │ │ │ +│ │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ │ MERGED → WRITE_ONLY +│ │ │ +│ │ └── • 3 Mutation operations +│ │ │ +│ │ ├── • MakeMergedIndexWriteOnly +│ │ │ IndexID: 3 +│ │ │ TableID: 104 +│ │ │ +│ │ ├── • SetJobStateOnDescriptor +│ │ │ DescriptorID: 104 +│ │ │ +│ │ └── • UpdateSchemaChangerJob +│ │ JobID: 1 +│ │ RunningStatus: PostCommitPhase stage 7 of 7 with 1 ValidationType op pending +│ │ +│ └── • Stage 7 of 7 in PostCommitPhase +│ │ +│ ├── • 1 element transitioning toward PUBLIC +│ │ │ +│ │ └── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} +│ │ WRITE_ONLY → VALIDATED +│ │ +│ └── • 1 Validation operation +│ │ +│ └── • ValidateUniqueIndex +│ IndexID: 3 +│ TableID: 104 +│ +└── • PostCommitNonRevertiblePhase + │ + ├── • Stage 1 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 14 elements transitioning toward ABSENT + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 3} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • Column:{DescID: 104, ColumnID: 4} + │ │ │ WRITE_ONLY → DELETE_ONLY + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ PUBLIC → WRITE_ONLY + │ │ │ + │ │ ├── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ ├── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ │ rule: "secondary index in DELETE_ONLY before removing columns" + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "index no longer public before dependents removed" + │ │ │ + │ │ ├── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ VALIDATED → DELETE_ONLY + │ │ │ + │ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4} + │ │ PUBLIC → ABSENT + │ │ + │ ├── • 2 elements transitioning toward PUBLIC + │ │ │ + │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ │ │ VALIDATED → PUBLIC + │ │ │ │ + │ │ │ ├── • SameStagePrecedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ │ rule: "primary index swap" + │ │ │ │ + │ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ rule: "index named right before index becomes public" + │ │ │ + │ │ └── • IndexName:{DescID: 104, Name: t_pkey, IndexID: 3} + │ │ │ ABSENT → PUBLIC + │ │ │ + │ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 1, TemporaryIndexID: 4, SourceIndexID: 1} + │ │ rule: "index existence precedes index name and comment" + │ │ + │ ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ │ + │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ WRITE_ONLY → TRANSIENT_DELETE_ONLY + │ │ + │ └── • 19 Mutation operations + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 3 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedColumnDeleteOnly + │ │ ColumnID: 4 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedPrimaryIndexDeleteAndWriteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 1 + │ │ Name: crdb_internal_index_1_name_placeholder + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 3 + │ │ Kind: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 4 + │ │ Kind: 2 + │ │ TableID: 104 + │ │ + │ ├── • SetIndexName + │ │ IndexID: 3 + │ │ Name: t_pkey + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 4 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 2 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 1 + │ │ Kind: 2 + │ │ Ordinal: 1 + │ │ TableID: 104 + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • MakeAddedPrimaryIndexPublic + │ │ EventBase: + │ │ Authorization: + │ │ UserName: root + │ │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ │ StatementTag: ALTER TABLE + │ │ TargetMetadata: + │ │ SourceElementID: 1 + │ │ SubWorkID: 1 + │ │ IndexID: 3 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 4 + │ │ IndexID: 2 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 3 + │ │ IndexID: 2 + │ │ Ordinal: 1 + │ │ TableID: 104 + │ │ + │ ├── • RemoveColumnFromIndex + │ │ ColumnID: 1 + │ │ IndexID: 2 + │ │ Kind: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 2 of 3 with 1 MutationType op pending + │ + ├── • Stage 2 of 3 in PostCommitNonRevertiblePhase + │ │ + │ ├── • 1 element transitioning toward ABSENT + │ │ │ + │ │ └── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ WRITE_ONLY → DELETE_ONLY + │ │ + │ └── • 3 Mutation operations + │ │ + │ ├── • MakeDroppedIndexDeleteOnly + │ │ IndexID: 1 + │ │ TableID: 104 + │ │ + │ ├── • SetJobStateOnDescriptor + │ │ DescriptorID: 104 + │ │ + │ └── • UpdateSchemaChangerJob + │ IsNonCancelable: true + │ JobID: 1 + │ RunningStatus: PostCommitNonRevertiblePhase stage 3 of 3 with 12 MutationType ops + │ pending + │ + └── • Stage 3 of 3 in PostCommitNonRevertiblePhase + │ + ├── • 10 elements transitioning toward ABSENT + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 3} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: k, ColumnID: 3} + │ │ │ rule: "dependents removed before column" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "indexes containing columns reach absent before column" + │ │ │ + │ │ └── • Precedence dependency from ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ rule: "indexes containing columns reach absent before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 3} + │ │ │ rule: "column dependents removed after column no longer public" + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnDefaultExpression:{DescID: 104, ColumnID: 3} + │ │ │ rule: "column type dependents removed right before column type" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ColumnOnUpdateExpression:{DescID: 104, ColumnID: 3} + │ │ rule: "column type dependents removed right before column type" + │ │ + │ ├── • ColumnDefaultExpression:{DescID: 104, ColumnID: 3} + │ │ PUBLIC → ABSENT + │ │ + │ ├── • ColumnOnUpdateExpression:{DescID: 104, ColumnID: 3} + │ │ PUBLIC → ABSENT + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 2} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ rule: "indexes containing columns reach absent before column" + │ │ │ + │ │ └── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: j, ColumnID: 2} + │ │ rule: "dependents removed before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 2} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • Column:{DescID: 104, ColumnID: 4} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • SameStagePrecedence dependency from ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ │ │ rule: "dependents removed before column" + │ │ │ rule: "column type removed right before column when not dropping relation" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ │ rule: "indexes containing columns reach absent before column" + │ │ │ + │ │ └── • Precedence dependency from ABSENT ColumnName:{DescID: 104, Name: crdb_internal_idx_expr, ColumnID: 4} + │ │ rule: "dependents removed before column" + │ │ + │ ├── • ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 4} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from WRITE_ONLY Column:{DescID: 104, ColumnID: 4} + │ │ rule: "column dependents removed after column no longer public" + │ │ + │ ├── • PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} + │ │ │ DELETE_ONLY → ABSENT + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} + │ │ │ rule: "dependents removed before index" + │ │ │ + │ │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ │ rule: "temp indexes reach absent at the same time as other indexes" + │ │ + │ └── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} + │ │ DELETE_ONLY → ABSENT + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} + │ │ rule: "secondary index columns removed before removing the index" + │ │ rule: "dependents removed before index" + │ │ + │ ├── • Precedence dependency from ABSENT IndexName:{DescID: 104, Name: t_expr_k_idx, IndexID: 2} + │ │ rule: "dependents removed before index" + │ │ + │ └── • SameStagePrecedence dependency from TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ rule: "temp indexes reach absent at the same time as other indexes" + │ + ├── • 1 element transitioning toward TRANSIENT_ABSENT + │ │ + │ └── • TemporaryIndex:{DescID: 104, IndexID: 4, SourceIndexID: 1} + │ TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT + │ + └── • 14 Mutation operations + │ + ├── • CreateGcJobForIndex + │ IndexID: 4 + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 4 + │ TableID: 104 + │ + ├── • CreateGcJobForIndex + │ IndexID: 1 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ IndexID: 1 + │ TableID: 104 + │ + ├── • LogEvent + │ Element: + │ SecondaryIndex: + │ indexId: 2 + │ tableId: 104 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TargetStatus: 1 + │ + ├── • CreateGcJobForIndex + │ IndexID: 2 + │ StatementForDropJob: + │ Statement: ALTER TABLE defaultdb.public.t DROP COLUMN j CASCADE + │ TableID: 104 + │ + ├── • MakeIndexAbsent + │ IndexID: 2 + │ TableID: 104 + │ + ├── • RemoveColumnDefaultExpression + │ ColumnID: 3 + │ TableID: 104 + │ + ├── • RemoveColumnOnUpdateExpression + │ ColumnID: 3 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 2 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 4 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹j› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • MakeColumnAbsent + │ ColumnID: 3 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COLUMN ‹k› CASCADE + │ StatementTag: ALTER TABLE + │ TargetMetadata: + │ SourceElementID: 1 + │ StatementID: 1 + │ SubWorkID: 1 + │ TableID: 104 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 104 + │ JobID: 1 + │ + └── • UpdateSchemaChangerJob + IsNonCancelable: true + JobID: 1 + RunningStatus: all stages completed