Skip to content

sql/resolver: error handling regression on master for database that does not exist #68060

@rafiss

Description

@rafiss

I noticed an unexpected change when I use the CLI. If I connect with a URL that includes a DB that doesn’t exist, the error message has changed.

It used to say error retrieving the database name: pq: database "db" does not exist.

Now it says error retrieving the database name: pq: relation "crdb_internal.session_variables" does not exist.

The new (undesired) error is coming from here:

return nil, prefix, sqlerrors.NewUndefinedObjectError(un, lookupFlags.DesiredObjectKind)

At this point lookupFlags.Required is set to false, so the error handling that would happen in getObjectByName to give the "good" error is not used:

if err != nil || desc != nil || !flags.Required {
return
}
if catalogName != "" && prefix.Database == nil {
err = sqlerrors.NewUndefinedDatabaseError(catalogName)

The message comes from the first time the CLI runs a SHOW DATABASE command, which delegates to crdb_internal.session_variables. Technically the new message is “correct” since that name is the thing that cannot be resolved, but it’s slightly less helpful. I think the change came in a40102a.

I see that in 21.1 the database does not exist error was coming from getPlanInfo so I guess that means name resolution is happening sooner now than it was before.

Epic: CRDB-2454

Metadata

Metadata

Assignees

Labels

A-sql-name-resolutionSQL name resolution rules and CTEs.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions