-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Strip database qualifier from VIEW definitions in GetSchema #9655
Conversation
Signed-off-by: Matt Lord <mattalord@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please see inline notes
// so that the results for Views match: | ||
// 1. The SHOW CREATE VIEW output from MySQL | ||
// 2. The CREATE TABLE output in these results, which does not have the DB name qualifier | ||
norm = strings.Replace(norm, backtickDBName+".", "", -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wary of strings.Replace()
as means to manipulate queries. What happens if there's a column that has same name as the database? At the very least I'd say lets replace -1
with 1
:
norm = strings.Replace(norm, backtickDBName+".", "", -1) | |
norm = strings.Replace(norm, backtickDBName+".", "", 1) |
but then, when I experiment on my local machine:
master [localhost:21324] {msandbox} (test) > show create table `test`.`v` \G
*************************** 1. row ***************************
View: v
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`msandbox`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `t`.`id` AS `id`,`t`.`i` AS `i`,`t`.`tx` AS `tx` from `t`
character_set_client: utf8mb4
collation_connection: utf8mb4_0900_ai_ci
I don't see a database qualifier in the resulting CREATE VIEW
statement. therefore, should there be a column named test
, it will be wrongly replaced.
I realize the bug predates this PR. But then, I also see no testing to this logic. Should we seize the opportunity to fix this? We can e.g. sqlparser.ParseStatement
into a CreateView
, then remove the schema qualifier, then export back via sqlparser.String()
.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is about the vtctl GetSchema
results and the RPC it uses. You can see an example if you exapand Here's a demonstration:
in the description.
I had similar concerns about the potential for problems, but since we already had that issue in this code I set it aside. I can explore alternatives though, I'm going to move this back to draft anyway as I'm adding a new e2e test for GetSchema
in vitess.io/vitess/go/test/endtoend/tabletmanager
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it. I actually missed the Here's a demonstration:
section.
I agree that the solution in this PR is better than already existing code.
Signed-off-by: Matt Lord <mattalord@gmail.com>
@rohit-nayak-ps, @deepthi, and @shlomi-noach so I don't think we want to go this route after sleeping on it. The reasons being:
So if we wanted to ignore/remove the token output from this RPC, I think it should be on the caller side. Any thoughts? |
Closing this as it's not 100% safe to do within Vitess and it will instead be done at higher layers on the caller side when it's known to be safe. I moved the new test to its own PR: #9658 |
Description
The TabletManager
GetSchema
RPC call results for SQL Views have the database name replaced by the template notation{{.DatabaseName}}
when what we should do instead is remove the database name qualifier so thatCREATE VIEW
clauses matchCREATE TABLE
clauses in the results — meaning that they do not have the database name qualifier.You can see a demonstration here...
Here's the basic structures created and viewed from a
vtgate
:Here's what we see in the Vitess schema:
Before:
After:
Related Issue(s)
Checklist