Skip to content

Commit

Permalink
executor: tiny clean up by removing unnecessary string creation (ping…
Browse files Browse the repository at this point in the history
…cap#10213)

* executor: clean up by remove unnecessary string creation
* check if id is nil
  • Loading branch information
ngaut authored Apr 22, 2019
1 parent e4aee76 commit 5fcc7e2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
3 changes: 1 addition & 2 deletions executor/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/stringutil"
)

var (
Expand Down Expand Up @@ -128,7 +127,7 @@ func (mds *mockDataSource) Next(ctx context.Context, req *chunk.RecordBatch) err
}

func buildMockDataSource(opt mockDataSourceParameters) *mockDataSource {
baseExec := newBaseExecutor(opt.ctx, opt.schema, stringutil.StringerStr(""))
baseExec := newBaseExecutor(opt.ctx, opt.schema, nil)
m := &mockDataSource{baseExec, opt, nil, nil, 0}
types := m.retTypes()
colData := make([][]interface{}, len(types))
Expand Down
4 changes: 3 additions & 1 deletion executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ func newBaseExecutor(ctx sessionctx.Context, schema *expression.Schema, id fmt.S
maxChunkSize: ctx.GetSessionVars().MaxChunkSize,
}
if ctx.GetSessionVars().StmtCtx.RuntimeStatsColl != nil {
e.runtimeStats = e.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl.GetRootStats(e.id.String())
if e.id != nil {
e.runtimeStats = e.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl.GetRootStats(e.id.String())
}
}
if schema != nil {
cols := schema.Columns
Expand Down
3 changes: 1 addition & 2 deletions executor/executor_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/ranger"
"github.com/pingcap/tidb/util/stringutil"
)

var _ = Suite(&testExecSuite{})
Expand Down Expand Up @@ -93,7 +92,7 @@ func (s *testExecSuite) TestShowProcessList(c *C) {

// Compose executor.
e := &ShowExec{
baseExecutor: newBaseExecutor(sctx, schema, stringutil.StringerStr("")),
baseExecutor: newBaseExecutor(sctx, schema, nil),
Tp: ast.ShowProcessList,
}

Expand Down
15 changes: 7 additions & 8 deletions executor/executor_required_rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/stringutil"
)

type requiredRowsDataSource struct {
Expand Down Expand Up @@ -63,7 +62,7 @@ func newRequiredRowsDataSource(ctx sessionctx.Context, totalRows int, expectedRo
cols[i] = &expression.Column{Index: i, RetType: retTypes[i]}
}
schema := expression.NewSchema(cols...)
baseExec := newBaseExecutor(ctx, schema, stringutil.StringerStr(""))
baseExec := newBaseExecutor(ctx, schema, nil)
return &requiredRowsDataSource{baseExec, totalRows, 0, ctx, expectedRowsRet, 0, defaultGenerator}
}

Expand Down Expand Up @@ -191,7 +190,7 @@ func (s *testExecSuite) TestLimitRequiredRows(c *C) {

func buildLimitExec(ctx sessionctx.Context, src Executor, offset, count int) Executor {
n := mathutil.Min(count, ctx.GetSessionVars().MaxChunkSize)
base := newBaseExecutor(ctx, src.Schema(), stringutil.StringerStr(""), src)
base := newBaseExecutor(ctx, src.Schema(), nil, src)
base.initCap = n
limitExec := &LimitExec{
baseExecutor: base,
Expand All @@ -206,7 +205,7 @@ func defaultCtx() sessionctx.Context {
ctx.GetSessionVars().InitChunkSize = variable.DefInitChunkSize
ctx.GetSessionVars().MaxChunkSize = variable.DefMaxChunkSize
ctx.GetSessionVars().MemQuotaSort = variable.DefTiDBMemQuotaSort
ctx.GetSessionVars().StmtCtx.MemTracker = memory.NewTracker(stringutil.StringerStr(""), ctx.GetSessionVars().MemQuotaQuery)
ctx.GetSessionVars().StmtCtx.MemTracker = memory.NewTracker(nil, ctx.GetSessionVars().MemQuotaQuery)
ctx.GetSessionVars().SnapshotTS = uint64(1)
return ctx
}
Expand Down Expand Up @@ -274,7 +273,7 @@ func (s *testExecSuite) TestSortRequiredRows(c *C) {

func buildSortExec(sctx sessionctx.Context, byItems []*plannercore.ByItems, src Executor) Executor {
sortExec := SortExec{
baseExecutor: newBaseExecutor(sctx, src.Schema(), stringutil.StringerStr(""), src),
baseExecutor: newBaseExecutor(sctx, src.Schema(), nil, src),
ByItems: byItems,
schema: src.Schema(),
}
Expand Down Expand Up @@ -381,7 +380,7 @@ func (s *testExecSuite) TestTopNRequiredRows(c *C) {

func buildTopNExec(ctx sessionctx.Context, offset, count int, byItems []*plannercore.ByItems, src Executor) Executor {
sortExec := SortExec{
baseExecutor: newBaseExecutor(ctx, src.Schema(), stringutil.StringerStr(""), src),
baseExecutor: newBaseExecutor(ctx, src.Schema(), nil, src),
ByItems: byItems,
schema: src.Schema(),
}
Expand Down Expand Up @@ -474,7 +473,7 @@ func (s *testExecSuite) TestSelectionRequiredRows(c *C) {

func buildSelectionExec(ctx sessionctx.Context, filters []expression.Expression, src Executor) Executor {
return &SelectionExec{
baseExecutor: newBaseExecutor(ctx, src.Schema(), stringutil.StringerStr(""), src),
baseExecutor: newBaseExecutor(ctx, src.Schema(), nil, src),
filters: filters,
}
}
Expand Down Expand Up @@ -592,7 +591,7 @@ func (s *testExecSuite) TestProjectionParallelRequiredRows(c *C) {

func buildProjectionExec(ctx sessionctx.Context, exprs []expression.Expression, src Executor, numWorkers int) Executor {
return &ProjectionExec{
baseExecutor: newBaseExecutor(ctx, src.Schema(), stringutil.StringerStr(""), src),
baseExecutor: newBaseExecutor(ctx, src.Schema(), nil, src),
numWorkers: int64(numWorkers),
evaluatorSuit: expression.NewEvaluatorSuite(exprs, false),
}
Expand Down
8 changes: 4 additions & 4 deletions executor/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *pkgTestSuite) TestNestedLoopApply(c *C) {
con := &expression.Constant{Value: types.NewDatum(6), RetType: types.NewFieldType(mysql.TypeLong)}
outerSchema := expression.NewSchema(col0)
outerExec := &MockExec{
baseExecutor: newBaseExecutor(sctx, outerSchema, stringutil.StringerStr("")),
baseExecutor: newBaseExecutor(sctx, outerSchema, nil),
Rows: []chunk.MutRow{
chunk.MutRowFromDatums(types.MakeDatums(1)),
chunk.MutRowFromDatums(types.MakeDatums(2)),
Expand All @@ -75,7 +75,7 @@ func (s *pkgTestSuite) TestNestedLoopApply(c *C) {
}}
innerSchema := expression.NewSchema(col1)
innerExec := &MockExec{
baseExecutor: newBaseExecutor(sctx, innerSchema, stringutil.StringerStr("")),
baseExecutor: newBaseExecutor(sctx, innerSchema, nil),
Rows: []chunk.MutRow{
chunk.MutRowFromDatums(types.MakeDatums(1)),
chunk.MutRowFromDatums(types.MakeDatums(2)),
Expand All @@ -91,7 +91,7 @@ func (s *pkgTestSuite) TestNestedLoopApply(c *C) {
make([]types.Datum, innerExec.Schema().Len()), []expression.Expression{otherFilter}, outerExec.retTypes(), innerExec.retTypes())
joinSchema := expression.NewSchema(col0, col1)
join := &NestedLoopApplyExec{
baseExecutor: newBaseExecutor(sctx, joinSchema, stringutil.StringerStr("")),
baseExecutor: newBaseExecutor(sctx, joinSchema, nil),
outerExec: outerExec,
innerExec: innerExec,
outerFilter: []expression.Expression{outerFilter},
Expand Down Expand Up @@ -122,7 +122,7 @@ func prepareOneColChildExec(sctx sessionctx.Context, rowCount int) Executor {
col0 := &expression.Column{Index: 0, RetType: types.NewFieldType(mysql.TypeLong)}
schema := expression.NewSchema(col0)
exec := &MockExec{
baseExecutor: newBaseExecutor(sctx, schema, stringutil.StringerStr("")),
baseExecutor: newBaseExecutor(sctx, schema, nil),
Rows: make([]chunk.MutRow, rowCount)}
for i := 0; i < len(exec.Rows); i++ {
exec.Rows[i] = chunk.MutRowFromDatums(types.MakeDatums(i % 10))
Expand Down
3 changes: 1 addition & 2 deletions executor/table_readers_required_rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/stringutil"
"github.com/pingcap/tipb/go-tipb"
)

Expand Down Expand Up @@ -143,7 +142,7 @@ func buildMockBaseExec(sctx sessionctx.Context) baseExecutor {
cols[i] = &expression.Column{Index: i, RetType: retTypes[i]}
}
schema := expression.NewSchema(cols...)
baseExec := newBaseExecutor(sctx, schema, stringutil.StringerStr(""))
baseExec := newBaseExecutor(sctx, schema, nil)
return baseExec
}

Expand Down

0 comments on commit 5fcc7e2

Please sign in to comment.