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

Bug Report: Specifying database name in a query after shard targetting fails #17502

Open
bluecrabs007 opened this issue Jan 9, 2025 · 0 comments · May be fixed by #17503
Open

Bug Report: Specifying database name in a query after shard targetting fails #17502

bluecrabs007 opened this issue Jan 9, 2025 · 0 comments · May be fixed by #17503
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)

Comments

@bluecrabs007
Copy link

Overview of the Issue

If you specify a specific shard in your USE statement, such as use commerce/-; and then issue a sql statement with the database name in the query, such as, select * from commerce.corder;, the query fails with an error

ERROR 1049 (42000): target: commerce.-.primary: vttablet: rpc error: code = InvalidArgument desc = Unknown database 'commerce' (errno 1049) (sqlstate 42000) (CallerID: user): Sql: "select * from commerce.corder", BindVars: {}

This makes sense as vtgate just passes through the sql statement to the shard and the underlying database name in the shard is prefexed with vt_ so this fails.
But should this fail? as from end user pov, the database/keyspace name is commerce, so selecting a shard and explicitly specifying the database name in the query should work.

To validate this theory, this query works.

mysql> use commerce/-;
Database changed
mysql> select * from vt_commerce.corder;
Empty set (0.00 sec)

VS

mysql> use commerce/-;
Database changed
mysql> select * from commerce.corder;
ERROR 1049 (42000): target: commerce.-.primary: vttablet: rpc error: code = InvalidArgument desc = Unknown database 'commerce' (errno 1049) (sqlstate 42000) (CallerID: user): Sql: "select * from commerce.corder", BindVars: {}

Reproduction Steps

Follow the steps in https://vitess.io/docs/22.0/get-started/operator/ to create a operator based vitess cluster on main branch.

Binary Version

vtgate --version
vtgate version Version: 22.0.0-SNAPSHOT (Git revision aabf1c9b907691f3c26eab3d75ca123b66735bcc branch 'main') built on Thu Jan  9 10:06:25 UTC 2025 by vitess@buildkitsandbox using go1.23.4 linux/amd64

Operating System and Environment details

ALL

Log Fragments

No response

@bluecrabs007 bluecrabs007 added Needs Triage This issue needs to be correctly labelled and triaged Type: Bug labels Jan 9, 2025
@harshit-gangal harshit-gangal added Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature) and removed Type: Bug Needs Triage This issue needs to be correctly labelled and triaged labels Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants