Skip to content

Commit

Permalink
planner: print dynamic prune info in explain for connection (pingcap#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 authored Nov 18, 2024
1 parent 3232160 commit a22b842
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/executor/explainfor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"
"testing"

"github.com/pingcap/tidb/pkg/parser/auth"
Expand Down Expand Up @@ -850,3 +851,24 @@ func TestExplainForJSON(t *testing.T) {
tk2.MustExec(fmt.Sprintf("explain format = 'TIDB_JSON' for connection %d", tk1RootProcess.ID))
tk2.MustExec(fmt.Sprintf("explain format = TIDB_JSON for connection %d", tk1RootProcess.ID))
}

func TestIssue55669(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("create table t (a int, b int, primary key (a,b), key (b)) partition by range (b) (partition p0 values less than (1000000), partition pMax values less than (maxvalue))")
tk.MustQuery("select a,b from t where b between 1 and 10")
tkRootProcess := tk.Session().ShowProcess()
ps := []*util.ProcessInfo{tkRootProcess}
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})

rs := tk.MustQuery(fmt.Sprintf("explain for connection %d", tkRootProcess.ID)).Rows()
ok := false
for i := range rs {
if strings.HasSuffix(rs[i][4].(string), "partition:p0") {
ok = true
}
}
require.True(t, ok)
}
3 changes: 3 additions & 0 deletions pkg/planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ func GetExplainRowsForPlan(plan base.Plan) (rows [][]string) {
Format: types.ExplainFormatROW,
Analyze: false,
}
if plan != nil {
explain.SetSCtx(plan.SCtx())
}
if err := explain.RenderResult(); err != nil {
return rows
}
Expand Down

0 comments on commit a22b842

Please sign in to comment.