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

[release-18.0] fix: remove keyspace from column during query builder (#15514) #15516

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions go/vt/vtgate/planbuilder/operators/SQL_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,7 @@ func buildHorizon(op *Horizon, qb *queryBuilder) error {
if err != nil {
return err
}
_ = sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) {
if aliasedExpr, ok := node.(sqlparser.SelectExpr); ok {
removeKeyspaceFromSelectExpr(aliasedExpr)
}
return true, nil
}, qb.stmt)
sqlparser.RemoveKeyspace(qb.stmt)
return nil
}

Expand Down
104 changes: 104 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/filter_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4426,5 +4426,109 @@
"user.user_extra"
]
}
},
{
"comment": "order by with filter removing the keyspace from order by",
"query": "select col from user.user where id = 1 order by user.user.user_id",
"plan": {
"QueryType": "SELECT",
"Original": "select col from user.user where id = 1 order by user.user.user_id",
"Instructions": {
"OperatorType": "Route",
"Variant": "EqualUnique",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select col from `user` where 1 != 1",
"Query": "select col from `user` where id = 1 order by `user`.user_id asc",
"Table": "`user`",
"Values": [
"INT64(1)"
],
"Vindex": "user_index"
},
"TablesUsed": [
"user.user"
]
}
},
{
"comment": "group by with filter removing the keyspace from order by",
"query": "select col from user.user where id = 1 group by user.user.user_id",
"plan": {
"QueryType": "SELECT",
"Original": "select col from user.user where id = 1 group by user.user.user_id",
"Instructions": {
"OperatorType": "Route",
"Variant": "EqualUnique",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select col from `user` where 1 != 1 group by `user`.user_id",
"Query": "select col from `user` where id = 1 group by `user`.user_id",
"Table": "`user`",
"Values": [
"INT64(1)"
],
"Vindex": "user_index"
},
"TablesUsed": [
"user.user"
]
}
},
{
"comment": "order with authoritative table - removing keyspace from group by",
"query": "select * from user.authoritative where user_id = 5 order by user_id",
"plan": {
"QueryType": "SELECT",
"Original": "select * from user.authoritative where user_id = 5 order by user_id",
"Instructions": {
"OperatorType": "Route",
"Variant": "EqualUnique",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select user_id, col1, col2 from authoritative where 1 != 1",
"Query": "select user_id, col1, col2 from authoritative where user_id = 5 order by authoritative.user_id asc",
"Table": "authoritative",
"Values": [
"INT64(5)"
],
"Vindex": "user_index"
},
"TablesUsed": [
"user.authoritative"
]
}
},
{
"comment": "group by and having with authoritative table - removing keyspace from having",
"query": "select * from user.authoritative where user_id = 5 group by user_id having count(user_id) = 6 order by user_id",
"plan": {
"QueryType": "SELECT",
"Original": "select * from user.authoritative where user_id = 5 group by user_id having count(user_id) = 6 order by user_id",
"Instructions": {
"OperatorType": "Route",
"Variant": "EqualUnique",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select user_id, col1, col2 from authoritative where 1 != 1 group by user_id",
"Query": "select user_id, col1, col2 from authoritative where user_id = 5 group by user_id having count(user_id) = 6 order by authoritative.user_id asc",
"Table": "authoritative",
"Values": [
"INT64(5)"
],
"Vindex": "user_index"
},
"TablesUsed": [
"user.authoritative"
]
}
}
]
Loading