diff --git a/pkg/sql/catalog/catalog.go b/pkg/sql/catalog/catalog.go index 689927d6baaa..30443454fee3 100644 --- a/pkg/sql/catalog/catalog.go +++ b/pkg/sql/catalog/catalog.go @@ -59,6 +59,7 @@ type VirtualSchemas interface { GetVirtualSchema(schemaName string) (VirtualSchema, bool) GetVirtualSchemaByID(id descpb.ID) (VirtualSchema, bool) GetVirtualObjectByID(id descpb.ID) (VirtualObject, bool) + Visit(func(desc Descriptor, comment string) error) error } // VirtualSchema represents a collection of VirtualObjects. diff --git a/pkg/sql/virtual_schema.go b/pkg/sql/virtual_schema.go index b26103e570e0..b7777db580dd 100644 --- a/pkg/sql/virtual_schema.go +++ b/pkg/sql/virtual_schema.go @@ -42,6 +42,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry" "github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" "github.com/cockroachdb/cockroach/pkg/util/hlc" + "github.com/cockroachdb/cockroach/pkg/util/iterutil" "github.com/cockroachdb/cockroach/pkg/util/stop" "github.com/cockroachdb/errors" ) @@ -397,6 +398,21 @@ func (vs *VirtualSchemaHolder) GetVirtualObjectByID(id descpb.ID) (catalog.Virtu return entry, true } +// Visit makes VirtualSchemaHolder implement catalog.VirtualSchemas. +func (vs *VirtualSchemaHolder) Visit(fn func(desc catalog.Descriptor, comment string) error) error { + for _, sc := range vs.schemasByID { + if err := fn(sc.desc, "" /* comment */); err != nil { + return iterutil.Map(err) + } + for _, def := range sc.defs { + if err := fn(def.desc, def.comment); err != nil { + return iterutil.Map(err) + } + } + } + return nil +} + var _ catalog.VirtualSchemas = (*VirtualSchemaHolder)(nil) type virtualSchemaEntry struct {