Skip to content

Commit 9869b54

Browse files
authored
have explain format=tree,debug,estimates print an explain tree (#2856)
1 parent f785905 commit 9869b54

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

enginetest/queries/queries.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10160,6 +10160,34 @@ from typestable`,
1016010160
{false},
1016110161
},
1016210162
},
10163+
10164+
{
10165+
Query: "explain select 1",
10166+
SkipServerEngine: true,
10167+
Expected: []sql.Row{
10168+
{1, "SELECT", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", ""},
10169+
},
10170+
},
10171+
{
10172+
Query: "explain plan select 1",
10173+
SkipServerEngine: true,
10174+
Expected: []sql.Row{
10175+
{"Project"},
10176+
{" ├─ columns: [1]"},
10177+
{" └─ Table"},
10178+
{" └─ name: "},
10179+
},
10180+
},
10181+
{
10182+
Query: "explain format=tree select 1",
10183+
SkipServerEngine: true,
10184+
Expected: []sql.Row{
10185+
{"Project"},
10186+
{" ├─ columns: [1]"},
10187+
{" └─ Table"},
10188+
{" └─ name: "},
10189+
},
10190+
},
1016310191
}
1016410192

1016510193
var KeylessQueries = []QueryTest{

sql/planbuilder/explain.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ func (b *Builder) buildExplain(inScope *scope, n *sqlparser.Explain) (outScope *
3535
formatFlags := strings.Split(n.ExplainFormat, "_")
3636
for _, flag := range formatFlags {
3737
switch strings.ToLower(flag) {
38-
case "", sqlparser.TreeStr:
39-
// tree format, do nothing
38+
case "":
39+
// no-op
40+
case sqlparser.TreeStr:
41+
describeOptions.Plan = true
4042
case "debug":
43+
describeOptions.Plan = true
4144
describeOptions.Debug = true
4245
case "estimates":
46+
describeOptions.Plan = true
4347
describeOptions.Estimates = true
4448
default:
4549
err := errInvalidDescribeFormat.New(n.ExplainFormat, "tree")

0 commit comments

Comments
 (0)