Skip to content

Commit 6e3609e

Browse files
fix: analyze statement parsing and planning
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
1 parent 8d7b507 commit 6e3609e

23 files changed

+167
-123
lines changed

go/vt/sqlparser/analyzer.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const (
4444
StmtShow
4545
StmtUse
4646
StmtOther
47+
StmtAnalyze
4748
StmtUnknown
4849
StmtComment
4950
StmtPriv
@@ -88,8 +89,10 @@ func ASTToStatementType(stmt Statement) StatementType {
8889
return StmtShowMigrationLogs
8990
case *Use:
9091
return StmtUse
91-
case *OtherRead, *OtherAdmin, *Load:
92+
case *OtherAdmin, *Load:
9293
return StmtOther
94+
case *Analyze:
95+
return StmtAnalyze
9396
case Explain, *VExplainStmt:
9497
return StmtExplain
9598
case *Begin:
@@ -245,8 +248,10 @@ func Preview(sql string) StatementType {
245248
return StmtUse
246249
case "describe", "desc", "explain":
247250
return StmtExplain
248-
case "analyze", "repair", "optimize":
251+
case "repair", "optimize":
249252
return StmtOther
253+
case "analyze":
254+
return StmtAnalyze
250255
case "grant", "revoke":
251256
return StmtPriv
252257
case "release":
@@ -293,6 +298,8 @@ func (s StatementType) String() string {
293298
return "USE"
294299
case StmtOther:
295300
return "OTHER"
301+
case StmtAnalyze:
302+
return "ANALYZE"
296303
case StmtPriv:
297304
return "PRIV"
298305
case StmtExplain:

go/vt/sqlparser/analyzer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestPreview(t *testing.T) {
6262
{"set", StmtSet},
6363
{"show", StmtShow},
6464
{"use", StmtUse},
65-
{"analyze", StmtOther},
65+
{"analyze", StmtAnalyze},
6666
{"describe", StmtExplain},
6767
{"desc", StmtExplain},
6868
{"explain", StmtExplain},

go/vt/sqlparser/ast.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,10 @@ type (
682682
Name IdentifierCI
683683
}
684684

685-
// OtherRead represents a DESCRIBE, or EXPLAIN statement.
686-
// It should be used only as an indicator. It does not contain
687-
// the full AST for the statement.
688-
OtherRead struct{}
685+
// Analyze represents the Analyze statement.
686+
Analyze struct {
687+
Table TableName
688+
}
689689

690690
// OtherAdmin represents a misc statement that relies on ADMIN privileges,
691691
// such as REPAIR, OPTIMIZE, or TRUNCATE statement.
@@ -729,7 +729,7 @@ func (*Rollback) iStatement() {}
729729
func (*SRollback) iStatement() {}
730730
func (*Savepoint) iStatement() {}
731731
func (*Release) iStatement() {}
732-
func (*OtherRead) iStatement() {}
732+
func (*Analyze) iStatement() {}
733733
func (*OtherAdmin) iStatement() {}
734734
func (*CommentOnly) iStatement() {}
735735
func (*Select) iSelectStatement() {}

go/vt/sqlparser/ast_clone.go

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/vt/sqlparser/ast_copy_on_rewrite.go

Lines changed: 26 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/vt/sqlparser/ast_equals.go

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/vt/sqlparser/ast_format.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,8 @@ func (node *CallProc) Format(buf *TrackedBuffer) {
10681068
}
10691069

10701070
// Format formats the node.
1071-
func (node *OtherRead) Format(buf *TrackedBuffer) {
1072-
buf.literal("otherread")
1071+
func (node *Analyze) Format(buf *TrackedBuffer) {
1072+
buf.astPrintf(node, "analyze table %v", node.Table)
10731073
}
10741074

10751075
// Format formats the node.

go/vt/sqlparser/ast_format_fast.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)