From 9a0d8c39cc921ad339cf0d7ebb834c2b930e7f5a Mon Sep 17 00:00:00 2001 From: Chengxiong Ruan Date: Wed, 11 Jan 2023 20:47:07 -0500 Subject: [PATCH] sql/schemachanger: rename RemoveViewBackReferencesInRelations This should work for both view and function, so renaming it to RemoveBackReferencesInRelations. Release note: None --- .../scexec/scmutationexec/references.go | 10 ++++---- pkg/sql/schemachanger/scop/mutation.go | 8 +++---- .../scop/mutation_visitor_generated.go | 6 ++--- .../scplan/internal/opgen/opgen_view.go | 8 +++---- .../scplan/testdata/alter_table_drop_column | 8 +++---- .../scplan/testdata/drop_database | 20 ++++++++-------- .../schemachanger/scplan/testdata/drop_index | 8 +++---- .../scplan/testdata/drop_owned_by | 8 +++---- .../schemachanger/scplan/testdata/drop_schema | 20 ++++++++-------- .../schemachanger/scplan/testdata/drop_table | 4 ++-- .../schemachanger/scplan/testdata/drop_view | 24 +++++++++---------- .../drop_index_with_materialized_view_dep | 2 +- .../drop_index_with_materialized_view_dep | 4 ++-- 13 files changed, 65 insertions(+), 65 deletions(-) diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/references.go b/pkg/sql/schemachanger/scexec/scmutationexec/references.go index 68c73c304f55..6627ba596353 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/references.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/references.go @@ -290,11 +290,11 @@ 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 } } @@ -302,7 +302,7 @@ func (m *visitor) RemoveViewBackReferencesInRelations( } 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() { @@ -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) } } diff --git a/pkg/sql/schemachanger/scop/mutation.go b/pkg/sql/schemachanger/scop/mutation.go index cbc3ebe629aa..8a9ac0cc057e 100644 --- a/pkg/sql/schemachanger/scop/mutation.go +++ b/pkg/sql/schemachanger/scop/mutation.go @@ -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. diff --git a/pkg/sql/schemachanger/scop/mutation_visitor_generated.go b/pkg/sql/schemachanger/scop/mutation_visitor_generated.go index 178ffccfadcd..6a5a22ec930a 100644 --- a/pkg/sql/schemachanger/scop/mutation_visitor_generated.go +++ b/pkg/sql/schemachanger/scop/mutation_visitor_generated.go @@ -79,7 +79,7 @@ type MutationVisitor interface { UpdateTypeBackReferencesInTypes(context.Context, UpdateTypeBackReferencesInTypes) error RemoveBackReferenceInTypes(context.Context, RemoveBackReferenceInTypes) error UpdateBackReferencesInSequences(context.Context, UpdateBackReferencesInSequences) error - RemoveViewBackReferencesInRelations(context.Context, RemoveViewBackReferencesInRelations) error + RemoveBackReferencesInRelations(context.Context, RemoveBackReferencesInRelations) error SetColumnName(context.Context, SetColumnName) error SetIndexName(context.Context, SetIndexName) error SetConstraintName(context.Context, SetConstraintName) error @@ -394,8 +394,8 @@ func (op UpdateBackReferencesInSequences) Visit(ctx context.Context, v MutationV } // Visit is part of the MutationOp interface. -func (op RemoveViewBackReferencesInRelations) Visit(ctx context.Context, v MutationVisitor) error { - return v.RemoveViewBackReferencesInRelations(ctx, op) +func (op RemoveBackReferencesInRelations) Visit(ctx context.Context, v MutationVisitor) error { + return v.RemoveBackReferencesInRelations(ctx, op) } // Visit is part of the MutationOp interface. diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_view.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_view.go index d2a5cf41c761..8612aa53a586 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_view.go +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_view.go @@ -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, } }), ), diff --git a/pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column b/pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column index 7c12a009e910..2e771563c3d7 100644 --- a/pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column +++ b/pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column @@ -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 @@ -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 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_database b/pkg/sql/schemachanger/scplan/testdata/drop_database index da3822027322..41a40a3f39e7 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_database +++ b/pkg/sql/schemachanger/scplan/testdata/drop_database @@ -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 @@ -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 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_index b/pkg/sql/schemachanger/scplan/testdata/drop_index index ae688922df00..5bfdc90da279 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_index +++ b/pkg/sql/schemachanger/scplan/testdata/drop_index @@ -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 @@ -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 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_owned_by b/pkg/sql/schemachanger/scplan/testdata/drop_owned_by index 323244149fff..5a9c65764c5e 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_owned_by +++ b/pkg/sql/schemachanger/scplan/testdata/drop_owned_by @@ -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 @@ -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 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_schema b/pkg/sql/schemachanger/scplan/testdata/drop_schema index dbd89cd3b95f..801e26c30043 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_schema +++ b/pkg/sql/schemachanger/scplan/testdata/drop_schema @@ -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 @@ -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 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_table b/pkg/sql/schemachanger/scplan/testdata/drop_table index 5f9f738e3532..0df7f00756e6 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_table +++ b/pkg/sql/schemachanger/scplan/testdata/drop_table @@ -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 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_view b/pkg/sql/schemachanger/scplan/testdata/drop_view index d90576fc4a94..1bd8f4932c86 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_view +++ b/pkg/sql/schemachanger/scplan/testdata/drop_view @@ -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 @@ -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 @@ -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 diff --git a/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep b/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep index 92581c92d0b7..4b2b31e3ccc4 100644 --- a/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep +++ b/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep @@ -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}} diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep index 67e459fad44a..8e3c7852b9e2 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep @@ -363,8 +363,8 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ ├── • MarkDescriptorAsDropped │ │ DescriptorID: 106 │ │ -│ ├── • RemoveViewBackReferencesInRelations -│ │ BackReferencedViewID: 106 +│ ├── • RemoveBackReferencesInRelations +│ │ BackReferencedID: 106 │ │ RelationIDs: │ │ - 105 │ │