Skip to content

Commit

Permalink
*: don't import golang.org/x/net/context as goctx alias (pingcap#5895)
Browse files Browse the repository at this point in the history
Now that there is no conflict with sessionctx.Context, this can be
import directly
  • Loading branch information
tiancaiamao authored Feb 24, 2018
1 parent 12c8792 commit e112181
Show file tree
Hide file tree
Showing 158 changed files with 1,594 additions and 1,595 deletions.
8 changes: 4 additions & 4 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
goctx "golang.org/x/net/context"
"golang.org/x/net/context"
)

// Node is the basic element of the AST.
Expand Down Expand Up @@ -138,10 +138,10 @@ type RecordSet interface {
Fields() []*ResultField

// Next returns the next row, nil row means there is no more to return.
Next(goCtx goctx.Context) (row types.Row, err error)
Next(ctx context.Context) (row types.Row, err error)

// NextChunk reads records into chunk.
NextChunk(goCtx goctx.Context, chk *chunk.Chunk) error
NextChunk(ctx context.Context, chk *chunk.Chunk) error

// NewChunk creates a new chunk with initial capacity.
NewChunk() *chunk.Chunk
Expand Down Expand Up @@ -186,7 +186,7 @@ type Statement interface {
OriginText() string

// Exec executes SQL and gets a Recordset.
Exec(goCtx goctx.Context) (RecordSet, error)
Exec(ctx context.Context) (RecordSet, error)

// IsPrepared returns whether this statement is prepared statement.
IsPrepared() bool
Expand Down
96 changes: 48 additions & 48 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/pingcap/tidb/ast"
"github.com/pingcap/tidb/store/mockstore"
log "github.com/sirupsen/logrus"
goctx "golang.org/x/net/context"
"golang.org/x/net/context"
)

var smallCount = 100
Expand Down Expand Up @@ -81,9 +81,9 @@ func prepareJoinBenchData(se Session, colType string, valueFormat string, valueC
mustExecute(se, "commit")
}

func readResult(goCtx goctx.Context, rs ast.RecordSet, count int) {
func readResult(ctx context.Context, rs ast.RecordSet, count int) {
for count > 0 {
x, err := rs.Next(goCtx)
x, err := rs.Next(ctx)
if err != nil {
log.Fatal(err)
}
Expand All @@ -96,181 +96,181 @@ func readResult(goCtx goctx.Context, rs ast.RecordSet, count int) {
}

func BenchmarkBasic(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select 1")
rs, err := se.Execute(ctx, "select 1")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], 1)
readResult(ctx, rs[0], 1)
}
}

func BenchmarkTableScan(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "int", "%v", smallCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t")
rs, err := se.Execute(ctx, "select * from t")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], smallCount)
readResult(ctx, rs[0], smallCount)
}
}

func BenchmarkExplainTableScan(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "int", "%v", 0)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "explain select * from t")
rs, err := se.Execute(ctx, "explain select * from t")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], 1)
readResult(ctx, rs[0], 1)
}
}

func BenchmarkTableLookup(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "int", "%d", smallCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t where pk = 64")
rs, err := se.Execute(ctx, "select * from t where pk = 64")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], 1)
readResult(ctx, rs[0], 1)
}
}

func BenchmarkExplainTableLookup(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "int", "%d", 0)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "explain select * from t where pk = 64")
rs, err := se.Execute(ctx, "explain select * from t where pk = 64")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], 1)
readResult(ctx, rs[0], 1)
}
}

func BenchmarkStringIndexScan(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "varchar(255)", "'hello %d'", smallCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t where col > 'hello'")
rs, err := se.Execute(ctx, "select * from t where col > 'hello'")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], smallCount)
readResult(ctx, rs[0], smallCount)
}
}

func BenchmarkExplainStringIndexScan(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "varchar(255)", "'hello %d'", 0)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "explain select * from t where col > 'hello'")
rs, err := se.Execute(ctx, "explain select * from t where col > 'hello'")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], 1)
readResult(ctx, rs[0], 1)
}
}

func BenchmarkStringIndexLookup(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "varchar(255)", "'hello %d'", smallCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t where col = 'hello 64'")
rs, err := se.Execute(ctx, "select * from t where col = 'hello 64'")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], 1)
readResult(ctx, rs[0], 1)
}
}

func BenchmarkIntegerIndexScan(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "int", "%v", smallCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t where col >= 0")
rs, err := se.Execute(ctx, "select * from t where col >= 0")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], smallCount)
readResult(ctx, rs[0], smallCount)
}
}

func BenchmarkIntegerIndexLookup(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "int", "%v", smallCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t where col = 64")
rs, err := se.Execute(ctx, "select * from t where col = 64")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], 1)
readResult(ctx, rs[0], 1)
}
}

func BenchmarkDecimalIndexScan(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "decimal(32,6)", "%v.1234", smallCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t where col >= 0")
rs, err := se.Execute(ctx, "select * from t where col >= 0")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], smallCount)
readResult(ctx, rs[0], smallCount)
}
}

func BenchmarkDecimalIndexLookup(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareBenchData(se, "decimal(32,6)", "%v.1234", smallCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t where col = 64.1234")
rs, err := se.Execute(ctx, "select * from t where col = 64.1234")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], 1)
readResult(ctx, rs[0], 1)
}
}

Expand All @@ -297,46 +297,46 @@ func BenchmarkInsertNoIndex(b *testing.B) {
}

func BenchmarkSort(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareSortBenchData(se, "int", "%v", bigCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t order by col limit 50")
rs, err := se.Execute(ctx, "select * from t order by col limit 50")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], 50)
readResult(ctx, rs[0], 50)
}
}

func BenchmarkJoin(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareJoinBenchData(se, "int", "%v", smallCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t a join t b on a.col = b.col")
rs, err := se.Execute(ctx, "select * from t a join t b on a.col = b.col")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], smallCount)
readResult(ctx, rs[0], smallCount)
}
}

func BenchmarkJoinLimit(b *testing.B) {
goCtx := goctx.Background()
ctx := context.Background()
b.StopTimer()
se := prepareBenchSession()
prepareJoinBenchData(se, "int", "%v", smallCount)
b.StartTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(goCtx, "select * from t a join t b on a.col = b.col limit 1")
rs, err := se.Execute(ctx, "select * from t a join t b on a.col = b.col limit 1")
if err != nil {
b.Fatal(err)
}
readResult(goCtx, rs[0], 1)
readResult(ctx, rs[0], 1)
}
}
Loading

0 comments on commit e112181

Please sign in to comment.