Skip to content

Commit

Permalink
add ANALYZE statement support (#141)
Browse files Browse the repository at this point in the history
* add ANALYZE statement support

* Added ; to align with other command descriptions
  • Loading branch information
michity15169 authored Sep 25, 2022
1 parent d65f4b6 commit 0ec9c18
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ and `{}` for a mutually exclusive keyword.
| Show DML Execution Plan | `EXPLAIN {INSERT\|UPDATE\|DELETE} ...;` | |
| Show Query Execution Plan with Stats | `EXPLAIN ANALYZE SELECT ...;` | |
| Show DML Execution Plan with Stats | `EXPLAIN ANALYZE {INSERT\|UPDATE\|DELETE} ...;` | |
| Start a new query optimizer statistics package construction | `ANALYZE;` | |
| Start Read-Write Transaction | `BEGIN [RW] [PRIORITY {HIGH\|MEDIUM\|LOW}] [TAG <tag>];` | See [Request Priority](#request-priority) for details on the priority. The tag you set is used as both transaction tag and request tag. See also [Transaction Tags and Request Tags](#transaction-tags-and-request-tags).|
| Commit Read-Write Transaction | `COMMIT;` | |
| Rollback Read-Write Transaction | `ROLLBACK;` | |
Expand Down
3 changes: 3 additions & 0 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ var (
revokeRe = regexp.MustCompile(`(?is)^REVOKE\s.+$`)
alterRe = regexp.MustCompile(`(?is)^ALTER\s.+$`)
truncateTableRe = regexp.MustCompile(`(?is)^TRUNCATE\s+TABLE\s+(.+)$`)
analyzeRe = regexp.MustCompile(`(?is)^ANALYZE$`)

// DML
dmlRe = regexp.MustCompile(`(?is)^(INSERT|UPDATE|DELETE)\s+.+$`)
Expand Down Expand Up @@ -152,6 +153,8 @@ func BuildStatement(input string) (Statement, error) {
case truncateTableRe.MatchString(input):
matched := truncateTableRe.FindStringSubmatch(input)
return &TruncateTableStatement{Table: unquoteIdentifier(matched[1])}, nil
case analyzeRe.MatchString(input):
return &DdlStatement{Ddl: input}, nil
case showDatabasesRe.MatchString(input):
return &ShowDatabasesStatement{}, nil
case showCreateTableRe.MatchString(input):
Expand Down
5 changes: 5 additions & 0 deletions statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ func TestBuildStatement(t *testing.T) {
input: "ALTER STATISTICS package SET OPTIONS (allow_gc = false)",
want: &DdlStatement{Ddl: "ALTER STATISTICS package SET OPTIONS (allow_gc = false)"},
},
{
desc: "ANALYZE statement",
input: "ANALYZE",
want: &DdlStatement{Ddl: "ANALYZE"},
},
{
desc: "INSERT statement",
input: "INSERT INTO t1 (id, name) VALUES (1, 'yuki')",
Expand Down

0 comments on commit 0ec9c18

Please sign in to comment.