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

executor: fix issue of load data statement doesn't record into slow query and statements_summary #20713

Merged
merged 15 commits into from
Nov 4, 2020
Merged
Prev Previous commit
Next Next commit
update
Signed-off-by: crazycs520 <crazycs520@gmail.com>
  • Loading branch information
crazycs520 committed Oct 28, 2020
commit d8372568efdd849b9f90f5012a1464f1d2d85b80
5 changes: 4 additions & 1 deletion executor/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,10 @@ func (e *InsertRuntimeStat) String() string {
if e.Prefetch > 0 {
buf.WriteString(fmt.Sprintf("check_insert:{total_time:%v, mem_insert_time:%v, prefetch:%v", e.CheckInsertTime, e.CheckInsertTime-e.Prefetch, e.Prefetch))
if e.SnapshotRuntimeStats != nil {
buf.WriteString(fmt.Sprintf(", rpc:{%s}", e.SnapshotRuntimeStats.String()))
rpcStr := e.SnapshotRuntimeStats.String()
if len(rpcStr) > 0 {
buf.WriteString(fmt.Sprintf(", rpc:{%s}", rpcStr))
}
}
buf.WriteString("}")
} else {
Expand Down
21 changes: 10 additions & 11 deletions executor/load_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ type LoadDataExec struct {
loadDataInfo *LoadDataInfo
}

// NewLoadDataInfo returns a LoadDataInfo structure, and it's only used for tests now.
func NewLoadDataInfo(ctx sessionctx.Context, row []types.Datum, tbl table.Table, cols []*table.Column) *LoadDataInfo {
insertVal := &InsertValues{baseExecutor: newBaseExecutor(ctx, nil, 0), Table: tbl}
return &LoadDataInfo{
row: row,
InsertValues: insertVal,
Table: tbl,
Ctx: ctx,
}
}

// Next implements the Executor Next interface.
func (e *LoadDataExec) Next(ctx context.Context, req *chunk.Chunk) error {
req.GrowAndReset(e.maxChunkSize)
Expand Down Expand Up @@ -102,6 +91,8 @@ func (e *LoadDataExec) Open(ctx context.Context) error {
if e.loadDataInfo.insertColumns != nil {
e.loadDataInfo.initEvalBuffer()
}
// Init for runtime stats.
e.loadDataInfo.collectRuntimeStatsEnabled()
return nil
}

Expand Down Expand Up @@ -530,6 +521,14 @@ func (e *LoadDataInfo) InsertData(ctx context.Context, prevData, curData []byte)

// CheckAndInsertOneBatch is used to commit one transaction batch full filled data
func (e *LoadDataInfo) CheckAndInsertOneBatch(ctx context.Context, rows [][]types.Datum, cnt uint64) error {
if e.stats != nil && e.stats.BasicRuntimeStats != nil {
// Since this method will not call by executor Next,
// so we need record the basic executor runtime stats by myself.
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
start := time.Now()
defer func() {
e.stats.BasicRuntimeStats.Record(time.Since(start), 0)
}()
}
var err error
if cnt == 0 {
return err
Expand Down