diff --git a/go/vt/vtgate/planbuilder/testdata/systemtables_cases.txt b/go/vt/vtgate/planbuilder/testdata/systemtables_cases.txt index ad1c60c15c5..3dd81c4a036 100644 --- a/go/vt/vtgate/planbuilder/testdata/systemtables_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/systemtables_cases.txt @@ -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`" } diff --git a/go/vt/vtgate/semantics/semantic_state.go b/go/vt/vtgate/semantics/semantic_state.go index 235ca0a367d..b664c52b8ea 100644 --- a/go/vt/vtgate/semantics/semantic_state.go +++ b/go/vt/vtgate/semantics/semantic_state.go @@ -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