planner: fix explain analyze format="brief" fails (#36815)

close pingcap/tidb#35090
This commit is contained in:
ChenPeng2013
2022-08-03 15:52:06 +08:00
committed by GitHub
parent 97f66c3fec
commit 894591b84f
2 changed files with 25 additions and 2 deletions

View File

@ -631,7 +631,7 @@ func (e *Explain) prepareSchema() error {
e.Format = types.ExplainFormatROW
}
switch {
case (format == types.ExplainFormatROW && (!e.Analyze && e.RuntimeStatsColl == nil)) || (format == types.ExplainFormatBrief):
case (format == types.ExplainFormatROW || format == types.ExplainFormatBrief) && (!e.Analyze && e.RuntimeStatsColl == nil):
fieldNames = []string{"id", "estRows", "task", "access object", "operator info"}
case format == types.ExplainFormatVerbose || format == types.ExplainFormatTrueCardCost:
if e.Analyze || e.RuntimeStatsColl != nil {
@ -639,7 +639,7 @@ func (e *Explain) prepareSchema() error {
} else {
fieldNames = []string{"id", "estRows", "estCost", "task", "access object", "operator info"}
}
case format == types.ExplainFormatROW && (e.Analyze || e.RuntimeStatsColl != nil):
case (format == types.ExplainFormatROW || format == types.ExplainFormatBrief) && (e.Analyze || e.RuntimeStatsColl != nil):
fieldNames = []string{"id", "estRows", "actRows", "task", "access object", "execution info", "operator info", "memory", "disk"}
case format == types.ExplainFormatDOT:
fieldNames = []string{"dot contents"}

View File

@ -710,6 +710,29 @@ func BenchmarkEncodeFlatPlan(b *testing.B) {
}
}
func TestIssue35090(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists p, t;")
tk.MustExec("create table p (id int, c int, key i_id(id), key i_c(c));")
tk.MustExec("create table t (id int);")
tk.MustExec("insert into p values (3,3), (4,4), (6,6), (9,9);")
tk.MustExec("insert into t values (4), (9);")
tk.MustExec("select /*+ INL_JOIN(p) */ * from p, t where p.id = t.id;")
rows := [][]interface{}{
{"IndexJoin"},
{"├─TableReader(Build)"},
{"│ └─Selection"},
{"│ └─TableFullScan"},
{"└─IndexLookUp(Probe)"},
{" ├─Selection(Build)"},
{" │ └─IndexRangeScan"},
{" └─TableRowIDScan(Probe)"},
}
tk.MustQuery("explain analyze format='brief' select /*+ INL_JOIN(p) */ * from p, t where p.id = t.id;").CheckAt([]int{0}, rows)
}
// Close issue 25729
func TestIssue25729(t *testing.T) {
config.UpdateGlobal(func(conf *config.Config) {