Skip to content

Commit

Permalink
Merge pull request #7164 from planetscale/dual-rewrite
Browse files Browse the repository at this point in the history
Skip query rewriting for dual table
  • Loading branch information
systay authored Dec 15, 2020
2 parents 9592c0f + 1ccc304 commit 91b10d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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))
})
}
}

0 comments on commit 91b10d9

Please sign in to comment.