ResolveExisting performs name resolution for an object name when the target object is expected to exist already. It does not mutate the input name. It additionally returns the resolved prefix qualification for the object. For example, if the unresolved name was "a.b" and the name was resolved to "a.
( ctx context.Context, u *UnresolvedObjectName, r ObjectNameExistingResolver, lookupFlags ObjectLookupFlags, curDb string, searchPath sessiondata.SearchPath, )
| 287 | // name was "a.b" and the name was resolved to "a.public.b", the |
| 288 | // prefix "a.public" is returned. |
| 289 | func ResolveExisting( |
| 290 | ctx context.Context, |
| 291 | u *UnresolvedObjectName, |
| 292 | r ObjectNameExistingResolver, |
| 293 | lookupFlags ObjectLookupFlags, |
| 294 | curDb string, |
| 295 | searchPath sessiondata.SearchPath, |
| 296 | ) (bool, ObjectNamePrefix, NameResolutionResult, error) { |
| 297 | namePrefix := ObjectNamePrefix{ |
| 298 | SchemaName: Name(u.Schema()), |
| 299 | ExplicitSchema: u.HasExplicitSchema(), |
| 300 | CatalogName: Name(u.Catalog()), |
| 301 | ExplicitCatalog: u.HasExplicitCatalog(), |
| 302 | } |
| 303 | if u.HasExplicitSchema() { |
| 304 | // pg_temp can be used as an alias for the current sessions temporary schema. |
| 305 | // We must perform this resolution before looking up the object. This |
| 306 | // resolution only succeeds if the session already has a temporary schema. |
| 307 | scName, err := searchPath.MaybeResolveTemporarySchema(u.Schema()) |
| 308 | if err != nil { |
| 309 | return false, namePrefix, nil, err |
| 310 | } |
| 311 | if u.HasExplicitCatalog() { |
| 312 | // Already 3 parts: nothing to search. Delegate to the resolver. |
| 313 | namePrefix.CatalogName = Name(u.Catalog()) |
| 314 | namePrefix.SchemaName = Name(scName) |
| 315 | found, result, err := r.LookupObject(ctx, lookupFlags, u.Catalog(), scName, u.Object()) |
| 316 | return found, namePrefix, result, err |
| 317 | } |
| 318 | // Two parts: D.T. |
| 319 | // Try to use the current database, and be satisfied if it's sufficient to find the object. |
| 320 | // |
| 321 | // Note: we test this even if curDb == "", because CockroachDB |
| 322 | // supports querying virtual schemas even when the current |
| 323 | // database is not set. For example, `select * from |
| 324 | // pg_catalog.pg_tables` is meant to show all tables across all |
| 325 | // databases when there is no current database set. |
| 326 | |
| 327 | if found, objMeta, err := r.LookupObject(ctx, lookupFlags, curDb, scName, u.Object()); found || err != nil { |
| 328 | if err == nil { |
| 329 | namePrefix.CatalogName = Name(curDb) |
| 330 | namePrefix.SchemaName = Name(scName) |
| 331 | } |
| 332 | return found, namePrefix, objMeta, err |
| 333 | } |
| 334 | // No luck so far. Compatibility with CockroachDB v1.1: try D.public.T instead. |
| 335 | if found, objMeta, err := r.LookupObject(ctx, lookupFlags, u.Schema(), PublicSchema, u.Object()); found || err != nil { |
| 336 | if err == nil { |
| 337 | namePrefix.CatalogName = Name(u.Schema()) |
| 338 | namePrefix.SchemaName = PublicSchemaName |
| 339 | namePrefix.ExplicitCatalog = true |
| 340 | } |
| 341 | return found, namePrefix, objMeta, err |
| 342 | } |
| 343 | // Welp, really haven't found anything. |
| 344 | return false, namePrefix, nil, nil |
| 345 | } |
| 346 |
nothing calls this directly
no test coverage detected