-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql/resolver: error handling regression on master for database that does not exist #68060
Description
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:
cockroach/pkg/sql/catalog/descs/object.go
Lines 46 to 50 in 64c888f
| 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