Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'USE' doesn't return an error if a keyspace doesn't exist #3060

Closed
guidoiaquinti opened this issue Aug 14, 2017 · 14 comments · Fixed by #6157
Closed

'USE' doesn't return an error if a keyspace doesn't exist #3060

guidoiaquinti opened this issue Aug 14, 2017 · 14 comments · Fixed by #6157
Milestone

Comments

@guidoiaquinti
Copy link
Member

guidoiaquinti commented Aug 14, 2017

Right now if we execute a USE against a keyspace/db that doesn't exist, we don't return any error to the client (we only do that after failing a query):

mysql> use this_db_doesnt_exist;
Database changed

vtgate only logs an error: E0814 13:47:41.481496 24441 resilient_srv_topo_server.go:280] WatchSrvKeyspace failed for test/this_db_doesnt_exist: node doesn't exist

mysql> show tables;
ERROR 1105 (HY000): vtgate: http://vitess:15001/: keyspace this_db_doesnt_exist fetch error: node doesn't exist

My proposal is to align Vitess to what MySQL already offers:

mysql> use this_db_doesnt_exist;
ERROR 1049 (42000): Unknown database 'this_db_doesnt_exist'
@sougou
Copy link
Contributor

sougou commented Aug 14, 2017

This sounds good.

@guidoiaquinti
Copy link
Member Author

Adding a minor note here to support as well system schemas:

mysql> use information_schema;
Database changed

mysql> SHOW TABLES FROM `information_schema`;
ERROR 1105 (HY000): vtgate: http://vitess:15001/: keyspace information_schema fetch error: node doesn't exist

the last query works fine if use information_schema; is skipped

@sougou
Copy link
Contributor

sougou commented Sep 3, 2017

We could add support for use <sys-schema> construct, but there are not many use cases right now. I believe most use cases want to use <keyspace> and select ... from information_schema.<table>.

It will become very powerful if vitess could show a consolidated view. Then this will become a powerful feature. It's something we can keep in mind.

@morgo morgo added this to the v5.0 milestone Nov 4, 2019
@morgo
Copy link
Contributor

morgo commented Nov 4, 2019

I think this is important to fix, because in general Vitess is quite strict about how it handles edge-cases. This makes it easier to validate that it is working correctly (vs. MySQL's traditional behavior of parse but ignore etc.)

@morgo
Copy link
Contributor

morgo commented Nov 12, 2019

There is another use-case why this is important. In MySQL (depending on platform) the schema name may be case-insensitive. So when you move to vitess, you may get this error.. which won't make sense to you. The semantics are much clearer if the initial selecting of the database fails.

@llibdude
Copy link

I had commented on the wrong issue and have deleted the message. Please disregard :)

@morgo morgo modified the milestones: v5.0, v6.0 Feb 4, 2020
@saifalharthi
Copy link
Contributor

saifalharthi commented Mar 24, 2020

I was looking debugging this issue and looking at query logs , this query does not invoke handleUse in the executor. However, I think mysql client sends a com_init_db and at this time we don't process it.

@deepthi
Copy link
Member

deepthi commented Mar 25, 2020

@saifalharthi can you document the full list of commands generated by use?

@saifalharthi
Copy link
Contributor

These are the commands I logged

select @@version_comment limit 1
SELECT DATABASE()
show databases
show tables

@harshit-gangal
Copy link
Member

harshit-gangal commented Apr 28, 2020

Can this be closed?

@deepthi
Copy link
Member

deepthi commented Apr 28, 2020

Can this be closed?

do you know which PR fixed it? Then we can refer to it here and close it.

@harshit-gangal
Copy link
Member

harshit-gangal commented Apr 28, 2020

If someone issues use <target>. It exists.
It is not implemented for ComInitDB call from mysql driver.

@sougou
Copy link
Contributor

sougou commented Apr 28, 2020

I don't think it's fixed. We might even have a regression of some sort. From the local example:

mysql> show databases;
+-----------+
| Databases |
+-----------+
| commerce  |
+-----------+
1 row in set (0.00 sec)

mysql> use aaa
Database changed
mysql> select * from product;
Empty set (0.00 sec)

mysql> 

@deepthi
Copy link
Member

deepthi commented Apr 28, 2020

That is a regression, it used to error out on the select, now it silently uses a keyspace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants