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

Skip query rewriting for dual table #7164

Merged
merged 1 commit into from
Dec 15, 2020
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
4 changes: 4 additions & 0 deletions go/vt/sqlparser/ast_rewriting.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ func (er *expressionRewriter) rewrite(cursor *Cursor) bool {
if !ok {
return true
}
// Qualifier should not be added to dual table
if aliasTableName.Name.String() == "dual" {
break
}
if er.keyspace != "" && aliasTableName.Qualifier.IsEmpty() {
aliasTableName.Qualifier = NewTableIdent(er.keyspace)
node.Expr = aliasTableName
Expand Down
10 changes: 7 additions & 3 deletions go/vt/sqlparser/ast_rewriting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ func TestRewritesWithDefaultKeyspace(in *testing.T) {
}, {
in: "SELECT 1 from test where exists (select 2 from test)",
expected: "SELECT 1 from sys.test where exists (select 2 from sys.test)",
}, {
in: "SELECT 1 from dual",
expected: "SELECT 1 from dual",
}, {
in: "SELECT (select 2 from dual) from DUAL",
expected: "SELECT 2 as `(select 2 from dual)` from DUAL",
}}

for _, tc := range tests {
Expand All @@ -239,9 +245,7 @@ func TestRewritesWithDefaultKeyspace(in *testing.T) {
expected, err := Parse(tc.expected)
require.NoError(err, "test expectation does not parse [%s]", tc.expected)

s := String(expected)
assert := assert.New(t)
assert.Equal(s, String(result.AST))
assert.Equal(t, String(expected), String(result.AST))
})
}
}