Skip to content

Commit

Permalink
explain plan instead
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cor committed Dec 5, 2024
1 parent 543d339 commit fa36dca
Show file tree
Hide file tree
Showing 5 changed files with 9,866 additions and 9,919 deletions.
7 changes: 6 additions & 1 deletion go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3936,6 +3936,7 @@ const (
// Explain represents an explain statement
type Explain struct {
Statement Statement
Plan bool
Analyze bool
ExplainFormat string
}
Expand All @@ -3950,7 +3951,11 @@ func (node *Explain) Format(buf *TrackedBuffer) {
if !node.Analyze && node.ExplainFormat != "" {
formatOpt = fmt.Sprintf("format = %s ", node.ExplainFormat)
}
buf.Myprintf("explain %s%s%v", analyzeOpt, formatOpt, node.Statement)
planOpt := ""
if node.Plan {
planOpt = "plan "
}
buf.Myprintf("explain %s%s%s%v", analyzeOpt, formatOpt, planOpt, node.Statement)
}

const (
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ var keywords = map[string]int{
"persist": PERSIST,
"persist_only": PERSIST_ONLY,
"persist_ro_variables_admin": PERSIST_RO_VARIABLES_ADMIN,
"plan": PLAN,
"plugins": PLUGINS,
"point": POINT,
"polygon": POLYGON,
Expand Down
48 changes: 40 additions & 8 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2459,22 +2459,54 @@ var (
}, {
input: "show columns from a for system_time as of 'foo'",
output: "show columns from a as of 'foo'",
}, {
},
{
input: "explain select * from foobar",
}, {
},
{
input: "explain format = tree select * from foobar",
}, {
},
{
input: "explain analyze select * from foobar",
}, {
},
{
input: "explain extended select * from foobar",
output: "explain select * from foobar",
}, {
},
{
input: "explain update foobar set foo = bar",
}, {
},
{
input: "explain delete from foobar where foo = bar",
}, {
},
{
input: "explain insert into foobar values (1, 2, 3)",
}, {
},

{
input: "explain plan select * from foobar",
},
{
input: "explain format = tree plan select * from foobar",
},
{
input: "explain analyze plan select * from foobar",
},
{
input: "explain extended plan select * from foobar",
output: "explain plan select * from foobar",
},
{
input: "explain plan update foobar set foo = bar",
},
{
input: "explain plan delete from foobar where foo = bar",
},
{
input: "explain plan insert into foobar values (1, 2, 3)",
},

{
input: "truncate table foo",
output: "truncate table foo",
}, {
Expand Down
Loading

0 comments on commit fa36dca

Please sign in to comment.