From f97cf8a1b3a27910c831d1bbb3b59665fbf37f3e Mon Sep 17 00:00:00 2001 From: Marius Posta Date: Tue, 4 May 2021 10:01:47 -0400 Subject: [PATCH] tabledesc: prevent panic when removing constraint from Checks slice Recently, a run of the TestRandomSyntaxSchemaChangeColumn test failed with a panic in tabledesc.MakeMutationComplete, see #63944. The panic was triggered by removing multiple elements from the Checks slice in the descriptor. While the underlying issue of _how_ this slice could possibly contain two constraints sharing the same name has not yet been resolved, deleting only the first constraint matching the target name will prevent future panics and perhaps help diagnose the underlying issue. Release note: None --- pkg/sql/catalog/tabledesc/structured.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/sql/catalog/tabledesc/structured.go b/pkg/sql/catalog/tabledesc/structured.go index 026b7a16e232..08b6cfddfd5f 100644 --- a/pkg/sql/catalog/tabledesc/structured.go +++ b/pkg/sql/catalog/tabledesc/structured.go @@ -1572,6 +1572,7 @@ func (desc *Mutable) MakeMutationComplete(m descpb.DescriptorMutation) error { for i, c := range desc.Checks { if c.Name == t.Constraint.Check.Name { desc.Checks = append(desc.Checks[:i], desc.Checks[i+1:]...) + break } } col, err := desc.FindColumnWithID(t.Constraint.NotNullColumn)