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

Gen4: Removing table name qualifiers to derived tables' column name expressions #8977

Merged
merged 1 commit into from
Oct 11, 2021
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
3 changes: 1 addition & 2 deletions go/vt/vtgate/planbuilder/testdata/systemtables_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,7 @@ Gen4 plan same as above
"Sharded": false
},
"FieldQuery": "select table_name from (select * from information_schema.`tables` where 1 != 1) as _subquery where 1 != 1",
"Query": "select table_name from (select * from information_schema.`tables` where table_schema = :__vtschemaname and _subquery.table_type = 'table_type' and _subquery.table_name = :_subquery_table_name) as _subquery",
"SysTableTableName": "[_subquery_table_name:VARBINARY(\"table_name\")]",
"Query": "select table_name from (select * from information_schema.`tables` where table_schema = :__vtschemaname and table_type = 'table_type' and table_name = 'table_name') as _subquery",
"SysTableTableSchema": "[VARBINARY(\"table_schema\")]",
"Table": "information_schema.`tables`"
}
Expand Down
10 changes: 7 additions & 3 deletions go/vt/vtgate/semantics/semantic_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,14 @@ func RewriteDerivedExpression(expr sqlparser.Expr, vt TableInfo) (sqlparser.Expr
switch node := cursor.Node().(type) {
case *sqlparser.ColName:
exp, err := vt.getExprFor(node.Name.String())
if err != nil {
return false
if err == nil {
cursor.Replace(exp)
} else {
// cloning the expression and removing the qualifier
col := *node
col.Qualifier = sqlparser.TableName{}
cursor.Replace(&col)
}
cursor.Replace(exp)
return false
}
return true
Expand Down