From fdc1c8847b6c4e2c42159a19cbc66601f84f54dc Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Mon, 15 Nov 2021 00:50:23 -0500 Subject: [PATCH] sql/catalog/descs,nstree: fix another perf problem Release note: None --- pkg/sql/catalog/descs/uncommitted_descriptors.go | 4 ++++ pkg/sql/catalog/nstree/set.go | 5 +++++ 2 files changed, 9 insertions(+) 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