Skip to content

Commit

Permalink
rewrite: Rewrite UniqueWithoutIndex on mutation slice during restore
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiang-Gu committed Dec 19, 2022
1 parent 06fb9aa commit 8a52702
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/sql/catalog/rewrite/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func TableDescs(
}
}

// Rewrite unique_without_index in both `UniqueWithoutIndexConstraints` and `Mutations` slice.
origUniqueWithoutIndexConstraints := table.UniqueWithoutIndexConstraints
table.UniqueWithoutIndexConstraints = nil
for _, unique := range origUniqueWithoutIndexConstraints {
Expand All @@ -186,6 +187,18 @@ func TableDescs(
"UniqueWithoutIndexConstraint %d was not found", table.Name, unique.TableID)
}
}
for idx := range table.Mutations {
if c := table.Mutations[idx].GetConstraint(); c != nil &&
c.ConstraintType == descpb.ConstraintToUpdate_UNIQUE_WITHOUT_INDEX {
uwi := &c.UniqueWithoutIndexConstraint
if rewrite, ok := descriptorRewrites[uwi.TableID]; ok {
uwi.TableID = rewrite.ID
} else {
return errors.AssertionFailedf("cannot restore %q because referenced table ID in "+
"UniqueWithoutIndexConstraint %d was not found", table.Name, uwi.TableID)
}
}
}

if table.IsSequence() && table.SequenceOpts.HasOwner() {
if ownerRewrite, ok := descriptorRewrites[table.SequenceOpts.SequenceOwner.OwnerTableID]; ok {
Expand Down

0 comments on commit 8a52702

Please sign in to comment.