Skip to content

Commit

Permalink
Merge pull request #6006 from planetscale/sa-add-missing-show-index
Browse files Browse the repository at this point in the history
Add SHOW INDEXES and EXTENDED
  • Loading branch information
harshit-gangal authored Apr 5, 2020
2 parents a615275 + 0c167c1 commit b34fd31
Show file tree
Hide file tree
Showing 7 changed files with 3,379 additions and 3,221 deletions.
14 changes: 11 additions & 3 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ type (

// Show represents a show statement.
Show struct {
Extended string
Type string
OnTable TableName
Table TableName
Expand Down Expand Up @@ -1165,10 +1166,17 @@ func (f *ForeignKeyDefinition) Format(buf *TrackedBuffer) {
// Format formats the node.
func (node *Show) Format(buf *TrackedBuffer) {
nodeType := strings.ToLower(node.Type)
if (nodeType == "tables" || nodeType == "columns" || nodeType == "fields" || nodeType == "index" || nodeType == "keys") && node.ShowTablesOpt != nil {
if (nodeType == "tables" || nodeType == "columns" || nodeType == "fields" || nodeType == "index" || nodeType == "keys" || nodeType == "indexes") && node.ShowTablesOpt != nil {
opt := node.ShowTablesOpt
buf.astPrintf(node, "show %s%s", opt.Full, nodeType)
if (nodeType == "columns" || nodeType == "fields" || nodeType == "index" || nodeType == "keys") && node.HasOnTable() {
if node.Extended != "" {
buf.astPrintf(node, "show %s%s", node.Extended, nodeType)
} else {
buf.astPrintf(node, "show %s%s", opt.Full, nodeType)
}
if (nodeType == "columns" || nodeType == "fields") && node.HasOnTable() {
buf.astPrintf(node, " from %v", node.OnTable)
}
if (nodeType == "index" || nodeType == "keys" || nodeType == "indexes") && node.HasOnTable() {
buf.astPrintf(node, " from %v", node.OnTable)
}
if opt.DbName != "" {
Expand Down
25 changes: 21 additions & 4 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,8 +1232,7 @@ var (
}, {
input: "show index from t",
}, {
input: "show indexes from table",
output: "show indexes",
input: "show indexes from t",
}, {
input: "show keys from t",
}, {
Expand Down Expand Up @@ -1564,8 +1563,26 @@ var (
input: "SHOW FULL TABLES FROM `jiradb` LIKE '%'",
output: "show full tables from jiradb like '%'",
}, {
input: "SHOW INDEX FROM `AO_E8B6CC_PROJECT_MAPPING` FROM `jiradb`",
output: "show index from AO_E8B6CC_PROJECT_MAPPING from jiradb",
input: "SHOW EXTENDED INDEX FROM `AO_E8B6CC_PROJECT_MAPPING` FROM `jiradb`",
output: "show extended index from AO_E8B6CC_PROJECT_MAPPING from jiradb",
}, {
input: "SHOW EXTENDED KEYS FROM `AO_E8B6CC_ISSUE_MAPPING` FROM `jiradb`",
output: "show extended keys from AO_E8B6CC_ISSUE_MAPPING from jiradb",
}, {
input: "SHOW CREATE TABLE `jiradb`.`AO_E8B6CC_ISSUE_MAPPING`",
output: "show create table jiradb.AO_E8B6CC_ISSUE_MAPPING",
}, {
input: "SHOW INDEXES FROM `AO_E8B6CC_ISSUE_MAPPING` FROM `jiradb`",
output: "show indexes from AO_E8B6CC_ISSUE_MAPPING from jiradb",
}, {
input: "SHOW FULL TABLES FROM `jiradb` LIKE '%'",
output: "show full tables from jiradb like '%'",
}, {
input: "SHOW EXTENDED INDEXES FROM `AO_E8B6CC_PROJECT_MAPPING` FROM `jiradb`",
output: "show extended indexes from AO_E8B6CC_PROJECT_MAPPING from jiradb",
}, {
input: "SHOW EXTENDED INDEXES IN `AO_E8B6CC_PROJECT_MAPPING` IN `jiradb`",
output: "show extended indexes from AO_E8B6CC_PROJECT_MAPPING from jiradb",
}}
)

Expand Down
Loading

0 comments on commit b34fd31

Please sign in to comment.