Skip to content

Commit

Permalink
sql/schemachanger: rename RemoveViewBackReferencesInRelations
Browse files Browse the repository at this point in the history
This should work for both view and function, so renaming it
to RemoveBackReferencesInRelations.

Release note: None
  • Loading branch information
chengxiong-ruan committed Jan 19, 2023
1 parent 1f300bd commit 9a0d8c3
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 65 deletions.
10 changes: 5 additions & 5 deletions pkg/sql/schemachanger/scexec/scmutationexec/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,19 @@ func updateBackReferencesInSequences(
return nil
}

func (m *visitor) RemoveViewBackReferencesInRelations(
ctx context.Context, op scop.RemoveViewBackReferencesInRelations,
func (m *visitor) RemoveBackReferencesInRelations(
ctx context.Context, op scop.RemoveBackReferencesInRelations,
) error {
for _, relationID := range op.RelationIDs {
if err := removeViewBackReferencesInRelation(ctx, m, relationID, op.BackReferencedViewID); err != nil {
if err := removeViewBackReferencesInRelation(ctx, m, relationID, op.BackReferencedID); err != nil {
return err
}
}
return nil
}

func removeViewBackReferencesInRelation(
ctx context.Context, m *visitor, relationID, viewID descpb.ID,
ctx context.Context, m *visitor, relationID, backReferencedID descpb.ID,
) error {
tbl, err := m.checkOutTable(ctx, relationID)
if err != nil || tbl.Dropped() {
Expand All @@ -311,7 +311,7 @@ func removeViewBackReferencesInRelation(
}
var newBackRefs []descpb.TableDescriptor_Reference
for _, by := range tbl.DependedOnBy {
if by.ID != viewID {
if by.ID != backReferencedID {
newBackRefs = append(newBackRefs, by)
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/schemachanger/scop/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,12 @@ type UpdateBackReferencesInSequences struct {
SequenceIDs []descpb.ID
}

// RemoveViewBackReferencesInRelations removes back references to a view in
// RemoveBackReferencesInRelations removes back references to a view in
// the specified tables, views or sequences.
type RemoveViewBackReferencesInRelations struct {
type RemoveBackReferencesInRelations struct {
mutationOp
BackReferencedViewID descpb.ID
RelationIDs []descpb.ID
BackReferencedID descpb.ID
RelationIDs []descpb.ID
}

// SetColumnName renames a column.
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/schemachanger/scop/mutation_visitor_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/sql/schemachanger/scplan/internal/opgen/opgen_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func init() {
TypeIDs: this.UsesTypeIDs,
}
}),
emit(func(this *scpb.View) *scop.RemoveViewBackReferencesInRelations {
emit(func(this *scpb.View) *scop.RemoveBackReferencesInRelations {
if len(this.UsesRelationIDs) == 0 {
return nil
}
return &scop.RemoveViewBackReferencesInRelations{
BackReferencedViewID: this.ViewID,
RelationIDs: this.UsesRelationIDs,
return &scop.RemoveBackReferencesInRelations{
BackReferencedID: this.ViewID,
RelationIDs: this.UsesRelationIDs,
}
}),
),
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ PostCommitNonRevertiblePhase stage 1 of 3 with 25 MutationType ops
BackReferencedDescriptorID: 108
TypeIDs:
- 104
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 108
*scop.RemoveBackReferencesInRelations
BackReferencedID: 108
RelationIDs:
- 107
*scop.RemoveDroppedColumnType
Expand Down Expand Up @@ -1229,8 +1229,8 @@ PostCommitNonRevertiblePhase stage 1 of 3 with 26 MutationType ops
BackReferencedDescriptorID: 108
TypeIDs:
- 104
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 108
*scop.RemoveBackReferencesInRelations
BackReferencedID: 108
RelationIDs:
- 107
*scop.RemoveDroppedColumnType
Expand Down
20 changes: 10 additions & 10 deletions pkg/sql/schemachanger/scplan/testdata/drop_database
Original file line number Diff line number Diff line change
Expand Up @@ -371,27 +371,27 @@ PreCommitPhase stage 1 of 1 with 91 MutationType ops
- 108
*scop.MarkDescriptorAsDropped
DescriptorID: 111
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 111
*scop.RemoveBackReferencesInRelations
BackReferencedID: 111
RelationIDs:
- 109
*scop.MarkDescriptorAsDropped
DescriptorID: 112
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 112
*scop.RemoveBackReferencesInRelations
BackReferencedID: 112
RelationIDs:
- 111
*scop.MarkDescriptorAsDropped
DescriptorID: 113
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 113
*scop.RemoveBackReferencesInRelations
BackReferencedID: 113
RelationIDs:
- 111
- 112
*scop.MarkDescriptorAsDropped
DescriptorID: 114
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 114
*scop.RemoveBackReferencesInRelations
BackReferencedID: 114
RelationIDs:
- 112
*scop.MarkDescriptorAsDropped
Expand All @@ -405,8 +405,8 @@ PreCommitPhase stage 1 of 1 with 91 MutationType ops
TypeIDs:
- 115
- 116
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 117
*scop.RemoveBackReferencesInRelations
BackReferencedID: 117
RelationIDs:
- 114
*scop.DrainDescriptorName
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/schemachanger/scplan/testdata/drop_index
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,8 @@ PreCommitPhase stage 1 of 1 with 10 MutationType ops
ops:
*scop.MarkDescriptorAsDropped
DescriptorID: 105
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 105
*scop.RemoveBackReferencesInRelations
BackReferencedID: 105
RelationIDs:
- 104
*scop.MakePublicSecondaryIndexWriteOnly
Expand Down Expand Up @@ -1026,8 +1026,8 @@ PreCommitPhase stage 1 of 1 with 12 MutationType ops
ops:
*scop.MarkDescriptorAsDropped
DescriptorID: 107
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 107
*scop.RemoveBackReferencesInRelations
BackReferencedID: 107
RelationIDs:
- 106
*scop.RemoveColumnDefaultExpression
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/schemachanger/scplan/testdata/drop_owned_by
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ PreCommitPhase stage 1 of 1 with 57 MutationType ops
- 107
*scop.MarkDescriptorAsDropped
DescriptorID: 110
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 110
*scop.RemoveBackReferencesInRelations
BackReferencedID: 110
RelationIDs:
- 108
*scop.MarkDescriptorAsDropped
Expand All @@ -246,8 +246,8 @@ PreCommitPhase stage 1 of 1 with 57 MutationType ops
TypeIDs:
- 111
- 112
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 113
*scop.RemoveBackReferencesInRelations
BackReferencedID: 113
RelationIDs:
- 110
*scop.DrainDescriptorName
Expand Down
20 changes: 10 additions & 10 deletions pkg/sql/schemachanger/scplan/testdata/drop_schema
Original file line number Diff line number Diff line change
Expand Up @@ -1314,27 +1314,27 @@ PreCommitPhase stage 1 of 1 with 69 MutationType ops
- 105
*scop.MarkDescriptorAsDropped
DescriptorID: 107
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 107
*scop.RemoveBackReferencesInRelations
BackReferencedID: 107
RelationIDs:
- 106
*scop.MarkDescriptorAsDropped
DescriptorID: 108
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 108
*scop.RemoveBackReferencesInRelations
BackReferencedID: 108
RelationIDs:
- 107
*scop.MarkDescriptorAsDropped
DescriptorID: 109
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 109
*scop.RemoveBackReferencesInRelations
BackReferencedID: 109
RelationIDs:
- 107
- 108
*scop.MarkDescriptorAsDropped
DescriptorID: 110
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 110
*scop.RemoveBackReferencesInRelations
BackReferencedID: 110
RelationIDs:
- 108
*scop.MarkDescriptorAsDropped
Expand All @@ -1348,8 +1348,8 @@ PreCommitPhase stage 1 of 1 with 69 MutationType ops
TypeIDs:
- 111
- 112
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 113
*scop.RemoveBackReferencesInRelations
BackReferencedID: 113
RelationIDs:
- 110
*scop.DrainDescriptorName
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/schemachanger/scplan/testdata/drop_table
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ PreCommitPhase stage 1 of 1 with 47 MutationType ops
DescriptorID: 110
*scop.MarkDescriptorAsDropped
DescriptorID: 111
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 111
*scop.RemoveBackReferencesInRelations
BackReferencedID: 111
RelationIDs:
- 109
*scop.DrainDescriptorName
Expand Down
24 changes: 12 additions & 12 deletions pkg/sql/schemachanger/scplan/testdata/drop_view
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ PreCommitPhase stage 1 of 1 with 9 MutationType ops
ops:
*scop.MarkDescriptorAsDropped
DescriptorID: 105
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 105
*scop.RemoveBackReferencesInRelations
BackReferencedID: 105
RelationIDs:
- 104
*scop.DrainDescriptorName
Expand Down Expand Up @@ -383,27 +383,27 @@ PreCommitPhase stage 1 of 1 with 45 MutationType ops
ops:
*scop.MarkDescriptorAsDropped
DescriptorID: 105
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 105
*scop.RemoveBackReferencesInRelations
BackReferencedID: 105
RelationIDs:
- 104
*scop.MarkDescriptorAsDropped
DescriptorID: 106
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 106
*scop.RemoveBackReferencesInRelations
BackReferencedID: 106
RelationIDs:
- 105
*scop.MarkDescriptorAsDropped
DescriptorID: 107
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 107
*scop.RemoveBackReferencesInRelations
BackReferencedID: 107
RelationIDs:
- 105
- 106
*scop.MarkDescriptorAsDropped
DescriptorID: 108
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 108
*scop.RemoveBackReferencesInRelations
BackReferencedID: 108
RelationIDs:
- 106
*scop.MarkDescriptorAsDropped
Expand All @@ -413,8 +413,8 @@ PreCommitPhase stage 1 of 1 with 45 MutationType ops
TypeIDs:
- 109
- 110
*scop.RemoveViewBackReferencesInRelations
BackReferencedViewID: 111
*scop.RemoveBackReferencesInRelations
BackReferencedID: 111
RelationIDs:
- 108
*scop.DrainDescriptorName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Schema change plan for DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 106, Name: v3_pkey, IndexID: 1}
│ └── 12 Mutation operations
│ ├── MarkDescriptorAsDropped {"DescriptorID":106}
│ ├── RemoveViewBackReferencesInRelations {"BackReferencedViewID":106}
│ ├── RemoveBackReferencesInRelations {"BackReferencedID":106}
│ ├── RemoveColumnDefaultExpression {"ColumnID":2,"TableID":106}
│ ├── MakePublicSecondaryIndexWriteOnly {"IndexID":2,"TableID":105}
│ ├── DrainDescriptorName {"Namespace":{"DatabaseID":100,"DescriptorID":106,"Name":"v3","SchemaID":101}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE;
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 106
│ │
│ ├── • RemoveViewBackReferencesInRelations
│ │ BackReferencedViewID: 106
│ ├── • RemoveBackReferencesInRelations
│ │ BackReferencedID: 106
│ │ RelationIDs:
│ │ - 105
│ │
Expand Down

0 comments on commit 9a0d8c3

Please sign in to comment.