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

syntax support for custom explain plan #389

Merged
merged 1 commit into from
Dec 6, 2024
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
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