Skip to content

Commit

Permalink
executor: add runtime information for the batch-point-get executor (#…
Browse files Browse the repository at this point in the history
…18828) (#18892)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
  • Loading branch information
ti-srebot authored Aug 3, 2020
1 parent 64e2a23 commit 990fd2e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 17 additions & 0 deletions executor/batch_point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -59,6 +60,9 @@ type BatchPointGetExec struct {

// virtualColumnRetFieldTypes records the RetFieldTypes of virtual columns.
virtualColumnRetFieldTypes []*types.FieldType

snapshot kv.Snapshot
stats *pointGetRuntimeStats
}

// buildVirtualColumnInfo saves virtual column indices and sort them in definition order
Expand All @@ -79,6 +83,9 @@ func (e *BatchPointGetExec) Open(context.Context) error {

// Close implements the Executor interface.
func (e *BatchPointGetExec) Close() error {
if e.runtimeStats != nil && e.snapshot != nil {
e.snapshot.DelOption(kv.CollectRuntimeStats)
}
return nil
}

Expand Down Expand Up @@ -133,6 +140,16 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error {
return err
}
}
if e.runtimeStats != nil {
snapshotStats := &tikv.SnapshotRuntimeStats{}
e.stats = &pointGetRuntimeStats{
BasicRuntimeStats: e.runtimeStats,
SnapshotRuntimeStats: snapshotStats,
}
snapshot.SetOption(kv.CollectRuntimeStats, snapshotStats)
e.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl.RegisterStats(e.id.String(), e.stats)
e.snapshot = snapshot
}
if e.ctx.GetSessionVars().GetReplicaRead().IsFollowerRead() {
snapshot.SetOption(kv.ReplicaRead, kv.ReplicaReadFollower)
}
Expand Down
17 changes: 11 additions & 6 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,11 +1188,16 @@ func (s *testIntegrationSerialSuite) TestExplainAnalyzePointGet(c *C) {
tk.MustExec("insert into t values (1,1)")

res := tk.MustQuery("explain analyze select * from t where a=1;")
resBuff := bytes.NewBufferString("")
for _, row := range res.Rows() {
fmt.Fprintf(resBuff, "%s\n", row)
checkExplain := func(rpc string) {
resBuff := bytes.NewBufferString("")
for _, row := range res.Rows() {
fmt.Fprintf(resBuff, "%s\n", row)
}
explain := resBuff.String()
c.Assert(strings.Contains(explain, rpc+":{num_rpc:"), IsTrue, Commentf("%s", explain))
c.Assert(strings.Contains(explain, "total_time:"), IsTrue, Commentf("%s", explain))
}
explain := resBuff.String()
c.Assert(strings.Contains(explain, "Get:{num_rpc:"), IsTrue, Commentf("%s", explain))
c.Assert(strings.Contains(explain, "total_time:"), IsTrue, Commentf("%s", explain))
checkExplain("Get")
res = tk.MustQuery("explain analyze select * from t where a in (1,2,3);")
checkExplain("BatchGet")
}

0 comments on commit 990fd2e

Please sign in to comment.