Skip to content

Commit

Permalink
sql: remove dead code in SchemaChanger done() method
Browse files Browse the repository at this point in the history
Previously this method populated a couple of maps but didn't actually do
anything with them besides that.

Release note: None
  • Loading branch information
Marius Posta committed Feb 18, 2021
1 parent 9065522 commit bd0e202
Showing 1 changed file with 1 addition and 41 deletions.
42 changes: 1 addition & 41 deletions pkg/sql/schema_changer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,6 @@ func WaitToUpdateLeasesMultiple(
// It also kicks off GC jobs as needed.
func (sc *SchemaChanger) done(ctx context.Context) error {

// Get the other tables whose foreign key backreferences need to be removed.
// We also have to handle the situation to add Foreign Key backreferences.
var fksByBackrefTable map[descpb.ID][]*descpb.ConstraintToUpdate
var interleaveParents map[descpb.ID]struct{}
var referencedTypeIDs []descpb.ID
// Jobs (for GC, etc.) that need to be started immediately after the table
// descriptor updates are published.
var childJobs []*jobs.StartableJob
Expand All @@ -1051,8 +1046,6 @@ func (sc *SchemaChanger) done(ctx context.Context) error {
ctx context.Context, txn *kv.Txn, descsCol *descs.Collection,
) error {
childJobs = nil
fksByBackrefTable = make(map[descpb.ID][]*descpb.ConstraintToUpdate)
interleaveParents = make(map[descpb.ID]struct{})

scTable, err := descsCol.GetMutableTableVersionByID(ctx, sc.descID, txn)
if err != nil {
Expand All @@ -1068,7 +1061,7 @@ func (sc *SchemaChanger) done(ctx context.Context) error {
if err != nil {
return err
}
referencedTypeIDs, err = scTable.GetAllReferencedTypeIDs(dbDesc,
referencedTypeIDs, err := scTable.GetAllReferencedTypeIDs(dbDesc,
func(id descpb.ID) (catalog.TypeDescriptor, error) {
desc, err := descsCol.GetImmutableTypeByID(ctx, txn, id, tree.ObjectLookupFlags{})
if err != nil {
Expand All @@ -1080,39 +1073,6 @@ func (sc *SchemaChanger) done(ctx context.Context) error {
return err
}
b := txn.NewBatch()
for _, mutation := range scTable.Mutations {
if mutation.MutationID != sc.mutationID {
break
}
if constraint := mutation.GetConstraint(); constraint != nil &&
constraint.ConstraintType == descpb.ConstraintToUpdate_FOREIGN_KEY &&
mutation.Direction == descpb.DescriptorMutation_ADD &&
constraint.ForeignKey.Validity == descpb.ConstraintValidity_Unvalidated {
// Add backref table to referenced table with an unvalidated foreign key constraint
fk := &constraint.ForeignKey
if fk.ReferencedTableID != scTable.ID {
fksByBackrefTable[constraint.ForeignKey.ReferencedTableID] = append(fksByBackrefTable[constraint.ForeignKey.ReferencedTableID], constraint)
}
} else if swap := mutation.GetPrimaryKeySwap(); swap != nil {
// If any old indexes (including the old primary index) being rewritten are interleaved
// children, we will have to update their parents as well.
for _, idxID := range append([]descpb.IndexID{swap.OldPrimaryIndexId}, swap.OldIndexes...) {
oldIndex, err := scTable.FindIndexWithID(idxID)
if err != nil {
return err
}
if oldIndex.NumInterleaveAncestors() != 0 {
ancestor := oldIndex.GetInterleaveAncestor(oldIndex.NumInterleaveAncestors() - 1)
if ancestor.TableID != scTable.ID {
interleaveParents[ancestor.TableID] = struct{}{}
}
}
}
// Because we are not currently supporting primary key changes on tables/indexes
// that are interleaved parents, we don't check oldPrimaryIndex.InterleavedBy.
}
}

const kvTrace = true

var i int // set to determine whether there is a mutation
Expand Down

0 comments on commit bd0e202

Please sign in to comment.