Skip to content

Commit

Permalink
scplan: make EXPLAIN target output stable
Browse files Browse the repository at this point in the history
This commit does not make any functional changes. It merely ensures that
the diagrams generated by an EXPLAIN (DDL) statement list the schema
change targets in a predefined order: first the to-public targets, then
the transient targets, and finally the to-absent targets.

This helps readability and makes the declarative schema changer
data-driven test output more stable.

Release justification: low-impact, test-only change
Release note: None
  • Loading branch information
Marius Posta committed Aug 17, 2022
1 parent 5f45e42 commit 2b7c666
Show file tree
Hide file tree
Showing 187 changed files with 3,751 additions and 3,748 deletions.
9 changes: 6 additions & 3 deletions pkg/sql/schemachanger/scplan/plan_explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ func (p Plan) explainTargets(s scstage.Stage, sn treeprinter.Node, style treepri
// Generate format string for printing element status transition.
fmtCompactTransition := fmt.Sprintf("%%-%ds → %%-%ds %%s", beforeMaxLen, afterMaxLen)
// Go over each target grouping.
targetTypeMap.ForEach(func(key, numTransitions int) {
ts := scpb.TargetStatus(key)
for _, ts := range []scpb.TargetStatus{scpb.ToPublic, scpb.Transient, scpb.ToAbsent} {
numTransitions := targetTypeMap.GetDefault(int(ts))
if numTransitions == 0 {
continue
}
plural := "s"
if numTransitions == 1 {
plural = ""
Expand Down Expand Up @@ -233,7 +236,7 @@ func (p Plan) explainTargets(s scstage.Stage, sn treeprinter.Node, style treepri
}
}
}
})
}
return nil
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/schemachanger/testdata/explain/add_column
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN
│ └── ValidateUniqueIndex {"IndexID":2,"TableID":106}
└── PostCommitNonRevertiblePhase
├── Stage 1 of 3 in PostCommitNonRevertiblePhase
│ ├── 3 elements transitioning toward ABSENT
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1}
│ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 106, Name: tbl_pkey, IndexID: 1}
│ ├── 3 elements transitioning toward PUBLIC
│ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 106, ColumnID: 2}
│ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 2, TemporaryIndexID: 3, SourceIndexID: 1}
Expand All @@ -99,6 +95,10 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN
│ │ ├── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 106, IndexID: 3, ConstraintID: 3, SourceIndexID: 1}
│ │ ├── PUBLIC → TRANSIENT_ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 3}
│ │ └── PUBLIC → TRANSIENT_ABSENT IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 3}
│ ├── 3 elements transitioning toward ABSENT
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1}
│ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 106, Name: tbl_pkey, IndexID: 1}
│ └── 9 Mutation operations
│ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":106}
│ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":106}
Expand All @@ -110,10 +110,10 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN
│ ├── 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}
│ ├── 1 element transitioning toward TRANSIENT_ABSENT
│ │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 106, IndexID: 3, ConstraintID: 3, SourceIndexID: 1}
│ ├── 1 element transitioning toward ABSENT
│ │ └── WRITE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}
│ └── 5 Mutation operations
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":1,"TableID":106}
│ ├── CreateGcJobForIndex {"IndexID":3,"TableID":106}
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/schemachanger/testdata/explain/add_column_default_seq
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN
│ └── ValidateUniqueIndex {"IndexID":2,"TableID":106}
└── PostCommitNonRevertiblePhase
├── Stage 1 of 3 in PostCommitNonRevertiblePhase
│ ├── 3 elements transitioning toward ABSENT
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1}
│ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 106, Name: tbl_pkey, IndexID: 1}
│ ├── 3 elements transitioning toward PUBLIC
│ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 106, ColumnID: 2}
│ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 2, TemporaryIndexID: 3, SourceIndexID: 1}
Expand All @@ -105,6 +101,10 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN
│ │ ├── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 106, IndexID: 3, ConstraintID: 3, SourceIndexID: 1}
│ │ ├── PUBLIC → TRANSIENT_ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 3}
│ │ └── PUBLIC → TRANSIENT_ABSENT IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 3}
│ ├── 3 elements transitioning toward ABSENT
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1}
│ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 106, Name: tbl_pkey, IndexID: 1}
│ └── 10 Mutation operations
│ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":106}
│ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":106}
Expand All @@ -117,10 +117,10 @@ Schema change plan for ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN
│ ├── SetJobStateOnDescriptor {"DescriptorID":107}
│ └── 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}
│ ├── 1 element transitioning toward TRANSIENT_ABSENT
│ │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 106, IndexID: 3, ConstraintID: 3, SourceIndexID: 1}
│ ├── 1 element transitioning toward ABSENT
│ │ └── WRITE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}
│ └── 6 Mutation operations
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":1,"TableID":106}
│ ├── CreateGcJobForIndex {"IndexID":3,"TableID":106}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ EXPLAIN (ddl) alter table t add primary key (a);
Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD PRIMARY KEY (‹a›);
├── 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: rowid, ColumnID: 2}
│ ├── 2 elements transitioning toward PUBLIC
│ │ ├── ABSENT → BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 4, TemporaryIndexID: 5, SourceIndexID: 2}
│ │ └── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4}
Expand All @@ -20,6 +17,9 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD PRIM
│ │ ├── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 3, SourceIndexID: 1}
│ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}
│ │ └── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ ├── 2 elements transitioning toward ABSENT
│ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 2}
│ │ └── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: rowid, ColumnID: 2}
│ └── 11 Mutation operations
│ ├── MakeDroppedColumnDeleteAndWriteOnly {"ColumnID":2,"TableID":104}
│ ├── LogEvent {"TargetStatus":1}
Expand Down Expand Up @@ -82,14 +82,14 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD PRIM
│ │ └── 1 Validation operation
│ │ └── ValidateUniqueIndex {"IndexID":2,"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}
│ │ ├── 4 elements transitioning toward TRANSIENT_ABSENT
│ │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 2, TemporaryIndexID: 3, SourceIndexID: 1}
│ │ │ ├── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 2}
│ │ │ ├── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 5, SourceIndexID: 2}
│ │ │ └── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 5}
│ │ ├── 2 elements transitioning toward ABSENT
│ │ │ ├── PUBLIC → VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}
│ │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1}
│ │ └── 8 Mutation operations
│ │ ├── MakeDroppedPrimaryIndexDeleteAndWriteOnly {"IndexID":1,"TableID":104}
│ │ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":104}
Expand Down Expand Up @@ -144,17 +144,17 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD PRIM
│ └── ValidateUniqueIndex {"IndexID":4,"TableID":104}
└── PostCommitNonRevertiblePhase
├── Stage 1 of 4 in PostCommitNonRevertiblePhase
│ ├── 4 elements transitioning toward ABSENT
│ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 2}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1}
│ │ └── VALIDATED → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}
│ ├── 5 elements transitioning toward TRANSIENT_ABSENT
│ │ ├── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 3, SourceIndexID: 1}
│ │ ├── PUBLIC → TRANSIENT_ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}
│ │ ├── PUBLIC → TRANSIENT_ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ │ ├── WRITE_ONLY → TRANSIENT_DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 5, SourceIndexID: 2}
│ │ └── PUBLIC → TRANSIENT_ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 5}
│ ├── 4 elements transitioning toward ABSENT
│ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 2}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1}
│ │ └── VALIDATED → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}
│ └── 6 Mutation operations
│ ├── MakeDroppedColumnDeleteOnly {"ColumnID":2,"TableID":104}
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":3,"TableID":104}
Expand All @@ -163,8 +163,6 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD PRIM
│ ├── SetJobStateOnDescriptor {"DescriptorID":104}
│ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."}
├── Stage 2 of 4 in PostCommitNonRevertiblePhase
│ ├── 1 element transitioning toward ABSENT
│ │ └── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}
│ ├── 2 elements transitioning toward PUBLIC
│ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 4, TemporaryIndexID: 5, SourceIndexID: 2}
│ │ └── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 4}
Expand All @@ -175,6 +173,8 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD PRIM
│ │ ├── PUBLIC → TRANSIENT_ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}
│ │ ├── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 3, SourceIndexID: 1}
│ │ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT TemporaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 5, SourceIndexID: 2}
│ ├── 1 element transitioning toward ABSENT
│ │ └── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}
│ └── 12 Mutation operations
│ ├── CreateGcJobForIndex {"IndexID":1,"TableID":104}
│ ├── MakeIndexAbsent {"IndexID":1,"TableID":104}
Expand All @@ -196,12 +196,12 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD PRIM
│ ├── SetJobStateOnDescriptor {"DescriptorID":104}
│ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."}
└── Stage 4 of 4 in PostCommitNonRevertiblePhase
├── 1 element transitioning toward TRANSIENT_ABSENT
│ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 2, TemporaryIndexID: 3, SourceIndexID: 1}
├── 3 elements transitioning toward ABSENT
│ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 2}
│ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2}
│ └── PUBLIC → ABSENT ColumnDefaultExpression:{DescID: 104, ColumnID: 2}
├── 1 element transitioning toward TRANSIENT_ABSENT
│ └── TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 2, TemporaryIndexID: 3, SourceIndexID: 1}
└── 6 Mutation operations
├── CreateGcJobForIndex {"IndexID":2,"TableID":104}
├── MakeIndexAbsent {"IndexID":2,"TableID":104}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ EXPLAIN (ddl) rollback at post-commit stage 10 of 15;
Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ADD PRIMARY KEY (‹a›);
└── PostCommitNonRevertiblePhase
├── Stage 1 of 3 in PostCommitNonRevertiblePhase
│ ├── 4 elements transitioning toward PUBLIC
│ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 104, ColumnID: 2}
│ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 104, Name: rowid, ColumnID: 2}
│ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}
│ │ └── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 1}
│ ├── 11 elements transitioning toward ABSENT
│ │ ├── PUBLIC → WRITE_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 2, TemporaryIndexID: 3, SourceIndexID: 1}
│ │ ├── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 2}
Expand All @@ -20,11 +25,6 @@ Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› A
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 4}
│ │ ├── WRITE_ONLY → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 5, SourceIndexID: 2}
│ │ └── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 5}
│ ├── 4 elements transitioning toward PUBLIC
│ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 104, ColumnID: 2}
│ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 104, Name: rowid, ColumnID: 2}
│ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}
│ │ └── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 1}
│ └── 13 Mutation operations
│ ├── SetColumnName {"ColumnID":2,"Name":"rowid","TableID":104}
│ ├── SetIndexName {"IndexID":1,"Name":"t_pkey","TableID":104}
Expand Down
Loading

0 comments on commit 2b7c666

Please sign in to comment.