diff --git a/pkg/sql/catalog/descs/leased_descriptors.go b/pkg/sql/catalog/descs/leased_descriptors.go index d5759fb45d23..6f6b8c37b59e 100644 --- a/pkg/sql/catalog/descs/leased_descriptors.go +++ b/pkg/sql/catalog/descs/leased_descriptors.go @@ -98,12 +98,8 @@ func (ld *leasedDescriptors) getByName( return cached.(lease.LeasedDescriptor).Underlying(), false, nil } - for _, d := range systemschema.UnleasableSystemDescriptors { - if parentID == d.GetParentID() && - parentSchemaID == d.GetParentSchemaID() && - name == d.GetName() { - return nil, true, nil - } + if systemschema.IsUnleasableSystemDescriptorByName(parentID, parentSchemaID, name) { + return nil, true, nil } readTimestamp := txn.ReadTimestamp() @@ -128,7 +124,7 @@ func (ld *leasedDescriptors) getByID( return cached.(lease.LeasedDescriptor).Underlying(), false, nil } - if _, isUnleasable := systemschema.UnleasableSystemDescriptors[id]; isUnleasable { + if systemschema.IsUnleasableSystemDescriptorByID(id) { return nil, true, nil } diff --git a/pkg/sql/catalog/systemschema/system.go b/pkg/sql/catalog/systemschema/system.go index 0e064b3b435b..cf06a69c9a45 100644 --- a/pkg/sql/catalog/systemschema/system.go +++ b/pkg/sql/catalog/systemschema/system.go @@ -2291,23 +2291,66 @@ var ( }} }, ) +) - // UnleasableSystemDescriptors contains the system descriptors which cannot - // be leased. This includes the lease table itself, among others. - UnleasableSystemDescriptors = func(s []catalog.Descriptor) map[descpb.ID]catalog.Descriptor { - m := make(map[descpb.ID]catalog.Descriptor, len(s)) - for _, d := range s { - m[d.GetID()] = d - } - return m - }([]catalog.Descriptor{ +type descRefByName struct { + parentID descpb.ID + parentSchemaID descpb.ID + name string +} + +var ( + // UnleasableSystemDescriptors contains the system descriptors which + // cannot be leased. This includes the lease table itself, among others. + UnleasableSystemDescriptors = []catalog.Descriptor{ SystemDB, LeaseTable, DescriptorTable, NamespaceTable, RangeEventTable, - }) + } + + unleasableSystemDescriptorsByID = func(s []catalog.Descriptor) map[descpb.ID]struct{} { + m := make(map[descpb.ID]struct{}, len(s)) + for _, d := range s { + m[d.GetID()] = struct{}{} + } + return m + }(UnleasableSystemDescriptors) + + unleasableSystemDescriptorsByName = func(s []catalog.Descriptor) map[descRefByName]struct{} { + m := make(map[descRefByName]struct{}, len(s)) + for _, d := range s { + m[descRefByName{ + parentID: d.GetParentID(), + parentSchemaID: d.GetParentSchemaID(), + name: d.GetName(), + }] = struct{}{} + } + return m + }(UnleasableSystemDescriptors) ) +// IsUnleasableSystemDescriptorByID returns whether the specified descriptor is +// a member of the UnleasableSystemDescriptors set, given an ID. +func IsUnleasableSystemDescriptorByID(id descpb.ID) bool { + _, ok := unleasableSystemDescriptorsByID[id] + return ok +} + +// IsUnleasableSystemDescriptorByName returns whether the specified descriptor +// is a member of the UnleasableSystemDescriptors set, given a database, schema, +// and name. +func IsUnleasableSystemDescriptorByName( + parentID descpb.ID, parentSchemaID descpb.ID, name string, +) bool { + _, ok := unleasableSystemDescriptorsByName[descRefByName{ + parentID: parentID, + parentSchemaID: parentSchemaID, + name: name, + }] + return ok +} + // SpanConfigurationsTableName represents system.span_configurations. var SpanConfigurationsTableName = tree.NewTableNameWithSchema("system", tree.PublicSchemaName, tree.Name(catconstants.SpanConfigurationsTableName))