Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request vitessio#6807 from GuptaManan100/mysql-show
Browse files Browse the repository at this point in the history
Added support for SHOW TABLE STATUS queries.
  • Loading branch information
harshit-gangal authored Oct 7, 2020
2 parents 58f8fbb + da1174b commit 0988455
Show file tree
Hide file tree
Showing 14 changed files with 1,795 additions and 1,597 deletions.
2 changes: 2 additions & 0 deletions go/vt/sqlparser/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func ASTToStatementType(stmt Statement) StatementType {
return StmtSRollback
case *Release:
return StmtRelease
case *ShowTableStatus:
return StmtShow
default:
return StmtUnknown
}
Expand Down
17 changes: 17 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ type (
ShowCollationFilterOpt Expr
}

// ShowTableStatus is a struct for SHOW TABLE STATUS queries.
ShowTableStatus struct {
DatabaseName string
Filter *ShowFilter
}

// Use represents a use statement.
Use struct {
DBName TableIdent
Expand Down Expand Up @@ -333,6 +339,7 @@ func (*OtherAdmin) iStatement() {}
func (*Select) iSelectStatement() {}
func (*Union) iSelectStatement() {}
func (*ParenSelect) iSelectStatement() {}
func (*ShowTableStatus) iStatement() {}

// ParenSelect can actually not be a top level statement,
// but we have to allow it because it's a requirement
Expand Down Expand Up @@ -2056,3 +2063,13 @@ func (node AccessMode) Format(buf *TrackedBuffer) {
buf.WriteString(TxReadWrite)
}
}

// Format formats the node.
func (node *ShowTableStatus) Format(buf *TrackedBuffer) {
buf.WriteString("show table status")
if node.DatabaseName != "" {
buf.WriteString(" from ")
buf.WriteString(node.DatabaseName)
}
buf.astPrintf(node, "%v", node.Filter)
}
7 changes: 7 additions & 0 deletions go/vt/sqlparser/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,10 @@ func TestDefaultStatus(t *testing.T) {
String(&Default{ColName: "status"}),
"default(`status`)")
}

func TestShowTableStatus(t *testing.T) {
query := "Show Table Status FROM customer"
tree, err := Parse(query)
require.NoError(t, err)
require.NotNil(t, tree)
}
14 changes: 12 additions & 2 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,18 @@ var (
input: "show session status",
output: "show session status",
}, {
input: "show table status",
output: "show table",
input: "show table status",
}, {
input: "show table status from dbname",
}, {
input: "show table status in dbname",
output: "show table status from dbname",
}, {
input: "show table status in dbname LIKE '%' ",
output: "show table status from dbname like '%'",
}, {
input: "show table status from dbname Where col=42 ",
output: "show table status from dbname where col = 42",
}, {
input: "show tables",
}, {
Expand Down
7 changes: 7 additions & 0 deletions go/vt/sqlparser/rewriter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0988455

Please sign in to comment.