cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.16k stars 3.82k forks source link

catalog: optimize `schemaResolvers.LookupObject` #135916

Open tbg opened 7 hours ago

tbg commented 7 hours ago

6a7b1e20e70c0ba8e6bb7a42d52512d9437cd75b oltp_read_only on reference roachprod cluster.

The problem here is that we have to allocate because we're using interfaces. See also https://github.com/cockroachdb/cockroach/issues/135905 - hopefully some refactoring or use of generics or in the worst case pooling can remove these classes of allocations from the SQL foundations codebase entirely.

----------------------------------------------------------+-------------
                                           1237068   100% |   github.com/cockroachdb/cockroach/pkg/sql/catalog/resolver.ResolveExisting pkg/sql/catalog/resolver/resolver.go:375
   1237068  0.78% 16.21%    1237068  0.78%                | github.com/cockroachdb/cockroach/pkg/sql.(*schemaResolver).LookupObject pkg/sql/schema_resolver.go:165
----------------------------------------------------------+-------------

Source:

/pkg/sql/schema_resolver.go#L165-L173

    tn := tree.MakeQualifiedTypeName(dbName, scName, obName) // <-- this
    switch flags.DesiredObjectKind {
    case tree.TableObject:
        prefix, desc, err = descs.PrefixAndTable(ctx, g, &tn)
    case tree.TypeObject:
        prefix, desc, err = descs.PrefixAndType(ctx, g, &tn)
    case tree.AnyObject:
        prefix, desc, err = descs.PrefixAndTable(ctx, g, &tn)
        if err != nil {

This seems easily pooled.

Epic: CRDB-42584

Jira issue: CRDB-44788