Skip to content

Commit

Permalink
vtgate executor: route "show create table" to the user-provided or vs…
Browse files Browse the repository at this point in the history
…chema-indicated keyspace

Previously the sql parser treated everything after `CREATE TABLE` as opaque.
This change updates the sql parser to look at the create table argument
to help direct queries to the appropriate keyspace.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>
  • Loading branch information
dweitzman committed Mar 18, 2019
1 parent 4d89945 commit 5ff205f
Show file tree
Hide file tree
Showing 6 changed files with 962 additions and 913 deletions.
10 changes: 10 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,7 @@ func (f *ForeignKeyDefinition) walkSubtree(visit Visit) error {
type Show struct {
Type string
OnTable TableName
Table TableName
ShowTablesOpt *ShowTablesOpt
Scope string
ShowCollationFilterOpt *Expr
Expand Down Expand Up @@ -1547,13 +1548,22 @@ func (node *Show) Format(buf *TrackedBuffer) {
if node.Type == "collation" && node.ShowCollationFilterOpt != nil {
buf.Myprintf(" where %v", *node.ShowCollationFilterOpt)
}
if node.HasTable() {
buf.Myprintf(" %v", node.Table)
}
}

// HasOnTable returns true if the show statement has an "on" clause
func (node *Show) HasOnTable() bool {
return node.OnTable.Name.v != ""
}

// HasTable returns true if the show statement has a parsed table name.
// Not all show statements parse table names.
func (node *Show) HasTable() bool {
return node.Table.Name.v != ""
}

func (node *Show) walkSubtree(visit Visit) error {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ var (
output: "show create procedure",
}, {
input: "show create table t",
output: "show create table",
output: "show create table t",
}, {
input: "show create trigger t",
output: "show create trigger",
Expand Down
Loading

0 comments on commit 5ff205f

Please sign in to comment.