diff --git a/pkg/sql/catalog/descs/uncommitted_descriptors.go b/pkg/sql/catalog/descs/uncommitted_descriptors.go index 8c54dc4493eb..337626774ad1 100644 --- a/pkg/sql/catalog/descs/uncommitted_descriptors.go +++ b/pkg/sql/catalog/descs/uncommitted_descriptors.go @@ -218,6 +218,10 @@ func (ud *uncommittedDescriptors) getByName( if got := ud.descs.GetByName(dbID, schemaID, name); got != nil { return false, got.(*uncommittedDescriptor).immutable } + // Check whether the set is empty to avoid allocating the NameInfo. + if ud.descNames.Empty() { + return false, nil + } return ud.descNames.Contains(descpb.NameInfo{ ParentID: dbID, ParentSchemaID: schemaID, diff --git a/pkg/sql/catalog/nstree/set.go b/pkg/sql/catalog/nstree/set.go index 06592e8e87b2..d0bab68ada65 100644 --- a/pkg/sql/catalog/nstree/set.go +++ b/pkg/sql/catalog/nstree/set.go @@ -47,6 +47,11 @@ func (s *Set) Clear() { *s = Set{} } +// Empty returns true if the set has no entries. +func (s *Set) Empty() bool { + return !s.initialized() || s.t.Len() == 0 +} + func (s *Set) maybeInitialize() { if s.initialized() { return