From cd36d28b77d439fd762a6795ca1fa90a4128d2d0 Mon Sep 17 00:00:00 2001 From: Brendan Gerrity Date: Wed, 29 Apr 2026 14:22:31 -0400 Subject: [PATCH] schemachanger: add error-on-fallthrough guards on vistors The issue in #169345 demonstrated the risk of switch statements on types if an unexpected type is passed to the vistor function. This change guards against future bugs by adding errors-on-default that trip on unexpected types. Epic: CRDB-31325 Informed by: #169345 Release note: None --- pkg/sql/schemachanger/scexec/scmutationexec/create.go | 6 ++++++ pkg/sql/schemachanger/scexec/scmutationexec/references.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/create.go b/pkg/sql/schemachanger/scexec/scmutationexec/create.go index 01d332664335..d82510fb5171 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/create.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/create.go @@ -65,6 +65,10 @@ func (i *immediateVisitor) AddDescriptorName(ctx context.Context, op scop.AddDes switch t := desc.(type) { case *tabledesc.Mutable: t.ParentID = op.Namespace.DatabaseID + case *dbdesc.Mutable, *schemadesc.Mutable, *typedesc.Mutable: + // These descriptor types have their parent IDs set through other ops. + default: + return errors.AssertionFailedf("unexpected descriptor type %T for AddDescriptorName", desc) } return nil @@ -90,6 +94,8 @@ func (i *immediateVisitor) SetNameInDescriptor( // functions do not have a namespace entry and their name field is handled // by FunctionName element. return errors.AssertionFailedf("Incorrect descriptor type %v", mut.DescriptorType()) + default: + return errors.AssertionFailedf("unexpected descriptor type %v for SetNameInDescriptor", mut.DescriptorType()) } return nil } diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/references.go b/pkg/sql/schemachanger/scexec/scmutationexec/references.go index 9d05104758a6..c8cf89a2b372 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/references.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/references.go @@ -644,6 +644,10 @@ func (i *immediateVisitor) RemoveObjectParent( return err } sc.RemoveFunction(obj.GetName(), obj.GetID()) + case catalog.Table, catalog.Type: + // Schemas don't maintain back-references to tables or types. + default: + return errors.AssertionFailedf("unexpected descriptor type %v for RemoveObjectParent", obj.DescriptorType()) } return nil }