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

Add SHOW INDEXES and EXTENDED #6006

Merged
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
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