From 43250d79111687a8590dd07ea2f00ee691dc28e9 Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Wed, 11 Dec 2019 10:19:20 +0800 Subject: [PATCH 01/14] tmp --- expression/bench_test.go | 6 ++ expression/builtin_miscellaneous_vec.go | 62 +++++++++++++++++++- expression/builtin_miscellaneous_vec_test.go | 19 +++++- 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/expression/bench_test.go b/expression/bench_test.go index 6c4f813634294..235f02cc7b8ac 100644 --- a/expression/bench_test.go +++ b/expression/bench_test.go @@ -1053,6 +1053,9 @@ func testVectorizedBuiltinFunc(c *C, vecExprCases vecExprBenchCases) { AuthUsername: "tidb", } } + if funcName == ast.Sleep { + ctx.GetSessionVars().StrictSQLMode = false + } if funcName == ast.GetParam { testTime := time.Now() ctx.GetSessionVars().PreparedParams = []types.Datum{ @@ -1273,6 +1276,9 @@ func benchmarkVectorizedBuiltinFunc(b *testing.B, vecExprCases vecExprBenchCases AuthUsername: "tidb", } } + if funcName == ast.Sleep { + ctx.GetSessionVars().StrictSQLMode = false + } if funcName == ast.GetParam { testTime := time.Now() ctx.GetSessionVars().PreparedParams = []types.Datum{ diff --git a/expression/builtin_miscellaneous_vec.go b/expression/builtin_miscellaneous_vec.go index 266033fab53a6..1ee94bdc8bbc8 100644 --- a/expression/builtin_miscellaneous_vec.go +++ b/expression/builtin_miscellaneous_vec.go @@ -20,6 +20,8 @@ import ( "math" "net" "strings" + "sync/atomic" + "time" "github.com/google/uuid" "github.com/pingcap/errors" @@ -272,11 +274,67 @@ func (b *builtinNameConstTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk. } func (b *builtinSleepSig) vectorized() bool { - return false + return true } +// evalInt evals a builtinSleepSig. +// See https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_sleep func (b *builtinSleepSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + buf, err := b.bufAllocator.get(types.ETReal, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf) + if err := b.args[0].VecEvalReal(b.ctx, input, buf); err != nil { + return err + } + + result.ResizeInt64(n, false) + result.MergeNulls(buf) + i64s := result.Int64s() + + y := buf.Float64s() + sessVars := b.ctx.GetSessionVars() + for i := 0; i < n; i++ { + if result.IsNull(i) { + if sessVars.StrictSQLMode { + return errIncorrectArgs.GenWithStackByArgs("sleep1") + } + continue + } + + if y[i] < 0 { + if sessVars.StrictSQLMode { + return errIncorrectArgs.GenWithStackByArgs("sleep2") + } + i64s[i] = 0 + continue + } + + if y[i] > math.MaxFloat64/float64(time.Second.Nanoseconds()) { + return errIncorrectArgs.GenWithStackByArgs("sleep3") + } + + dur := time.Duration(y[i] * float64(time.Second.Nanoseconds())) + ticker := time.NewTicker(10 * time.Millisecond) + defer ticker.Stop() + start := time.Now() + finish := false + for !finish { + select { + case now := <-ticker.C: + if now.Sub(start) > dur { + finish = true + } + default: + if atomic.CompareAndSwapUint32(&sessVars.Killed, 1, 0) { + i64s[i] = 1 + } + } + } + } + return nil } func (b *builtinIsIPv4MappedSig) vectorized() bool { diff --git a/expression/builtin_miscellaneous_vec_test.go b/expression/builtin_miscellaneous_vec_test.go index 9de7761cb388a..069618f5ea3bd 100644 --- a/expression/builtin_miscellaneous_vec_test.go +++ b/expression/builtin_miscellaneous_vec_test.go @@ -14,6 +14,8 @@ package expression import ( + "math" + "math/rand" "testing" . "github.com/pingcap/check" @@ -21,6 +23,17 @@ import ( "github.com/pingcap/tidb/types" ) +type sleepTimeGener struct { + nullRation float64 +} + +func (g *sleepTimeGener) gen() interface{} { + if rand.Float64() < g.nullRation { + return nil + } + return math.Floor(rand.Float64() * 100) +} + var vecBuiltinMiscellaneousCases = map[string][]vecExprBenchCase{ ast.Inet6Aton: { {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&ipv6StrGener{}}}, @@ -28,8 +41,10 @@ var vecBuiltinMiscellaneousCases = map[string][]vecExprBenchCase{ ast.IsIPv6: { {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString}}, }, - ast.Sleep: {}, - ast.UUID: {}, + ast.Sleep: { + {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETReal}, geners: []dataGenerator{&sleepTimeGener{0.2}}}, + }, + ast.UUID: {}, ast.Inet6Ntoa: { {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{ &selectStringGener{ From 98667e5a5d47e9105edd353d522a0e1cbb076f04 Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Mon, 16 Dec 2019 14:37:08 +0800 Subject: [PATCH 02/14] fix --- expression/builtin_miscellaneous_vec.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/expression/builtin_miscellaneous_vec.go b/expression/builtin_miscellaneous_vec.go index 9557eaf125163..a0d77ae8da3c8 100644 --- a/expression/builtin_miscellaneous_vec.go +++ b/expression/builtin_miscellaneous_vec.go @@ -24,7 +24,6 @@ import ( "time" "github.com/google/uuid" - "github.com/pingcap/errors" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" ) @@ -308,23 +307,24 @@ func (b *builtinSleepSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) e for i := 0; i < n; i++ { if result.IsNull(i) { if sessVars.StrictSQLMode { - return errIncorrectArgs.GenWithStackByArgs("sleep1") + return errIncorrectArgs.GenWithStackByArgs("sleep") } continue } if y[i] < 0 { if sessVars.StrictSQLMode { - return errIncorrectArgs.GenWithStackByArgs("sleep2") + return errIncorrectArgs.GenWithStackByArgs("sleep") } i64s[i] = 0 continue } if y[i] > math.MaxFloat64/float64(time.Second.Nanoseconds()) { - return errIncorrectArgs.GenWithStackByArgs("sleep3") + return errIncorrectArgs.GenWithStackByArgs("sleep") } + i64s[i] = 0 dur := time.Duration(y[i] * float64(time.Second.Nanoseconds())) ticker := time.NewTicker(10 * time.Millisecond) defer ticker.Stop() From 4acb2acb4d3dcf6465b4680c3c693313bf7573ec Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Mon, 16 Dec 2019 15:26:08 +0800 Subject: [PATCH 03/14] set chunksize to 1 --- expression/builtin_miscellaneous_vec_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/expression/builtin_miscellaneous_vec_test.go b/expression/builtin_miscellaneous_vec_test.go index 069618f5ea3bd..eaa8051f01739 100644 --- a/expression/builtin_miscellaneous_vec_test.go +++ b/expression/builtin_miscellaneous_vec_test.go @@ -42,7 +42,12 @@ var vecBuiltinMiscellaneousCases = map[string][]vecExprBenchCase{ {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString}}, }, ast.Sleep: { - {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETReal}, geners: []dataGenerator{&sleepTimeGener{0.2}}}, + { + retEvalType: types.ETInt, + childrenTypes: []types.EvalType{types.ETReal}, + geners: []dataGenerator{&sleepTimeGener{0.2}}, + chunkSize: 1, + }, }, ast.UUID: {}, ast.Inet6Ntoa: { From 49f024c49afa671fb061a7d54748283f9e8ae2b1 Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Mon, 16 Dec 2019 17:17:02 +0800 Subject: [PATCH 04/14] add return --- expression/builtin_miscellaneous_vec.go | 1 + 1 file changed, 1 insertion(+) diff --git a/expression/builtin_miscellaneous_vec.go b/expression/builtin_miscellaneous_vec.go index a0d77ae8da3c8..2a8ccaea23ca1 100644 --- a/expression/builtin_miscellaneous_vec.go +++ b/expression/builtin_miscellaneous_vec.go @@ -339,6 +339,7 @@ func (b *builtinSleepSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) e default: if atomic.CompareAndSwapUint32(&sessVars.Killed, 1, 0) { i64s[i] = 1 + return nil } } } From a1880d6ceef1c04fdb887e5bae78dc3296d6e674 Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Tue, 17 Dec 2019 22:47:50 +0800 Subject: [PATCH 05/14] refactor: move same code to a method --- expression/builtin_miscellaneous.go | 41 +++++++++++++++---------- expression/builtin_miscellaneous_vec.go | 23 +++----------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/expression/builtin_miscellaneous.go b/expression/builtin_miscellaneous.go index 13943339cf159..f96f6d14907fc 100644 --- a/expression/builtin_miscellaneous.go +++ b/expression/builtin_miscellaneous.go @@ -25,6 +25,7 @@ import ( "github.com/google/uuid" "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/sessionctx" + "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" @@ -108,6 +109,27 @@ func (b *builtinSleepSig) Clone() builtinFunc { return newSig } +func sleepDuration(sessVars *variable.SessionVars, val float64) bool { + dur := time.Duration(val * float64(time.Second.Nanoseconds())) + ticker := time.NewTicker(10 * time.Millisecond) + defer ticker.Stop() + start := time.Now() + finish := false + for !finish { + select { + case now := <-ticker.C: + if now.Sub(start) > dur { + finish = true + } + default: + if atomic.CompareAndSwapUint32(&sessVars.Killed, 1, 0) { + return true + } + } + } + return false +} + // evalInt evals a builtinSleepSig. // See https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_sleep func (b *builtinSleepSig) evalInt(row chunk.Row) (int64, bool, error) { @@ -135,22 +157,9 @@ func (b *builtinSleepSig) evalInt(row chunk.Row) (int64, bool, error) { return 0, false, errIncorrectArgs.GenWithStackByArgs("sleep") } - dur := time.Duration(val * float64(time.Second.Nanoseconds())) - ticker := time.NewTicker(10 * time.Millisecond) - defer ticker.Stop() - start := time.Now() - finish := false - for !finish { - select { - case now := <-ticker.C: - if now.Sub(start) > dur { - finish = true - } - default: - if atomic.CompareAndSwapUint32(&sessVars.Killed, 1, 0) { - return 1, false, nil - } - } + flag := sleepDuration(sessVars, val) + if flag { + return 1, false, nil } return 0, false, nil diff --git a/expression/builtin_miscellaneous_vec.go b/expression/builtin_miscellaneous_vec.go index 2a8ccaea23ca1..874bc49e99f59 100644 --- a/expression/builtin_miscellaneous_vec.go +++ b/expression/builtin_miscellaneous_vec.go @@ -20,7 +20,6 @@ import ( "math" "net" "strings" - "sync/atomic" "time" "github.com/google/uuid" @@ -325,23 +324,11 @@ func (b *builtinSleepSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) e } i64s[i] = 0 - dur := time.Duration(y[i] * float64(time.Second.Nanoseconds())) - ticker := time.NewTicker(10 * time.Millisecond) - defer ticker.Stop() - start := time.Now() - finish := false - for !finish { - select { - case now := <-ticker.C: - if now.Sub(start) > dur { - finish = true - } - default: - if atomic.CompareAndSwapUint32(&sessVars.Killed, 1, 0) { - i64s[i] = 1 - return nil - } - } + + flag := sleepDuration(sessVars, y[i]) + if flag { + i64s[i] = 1 + return nil } } return nil From 542431b52f1c7d2092753598837eb6afa5d67b4c Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Wed, 18 Dec 2019 11:16:03 +0800 Subject: [PATCH 06/14] add TestSleepVec --- expression/builtin_vectorized_test.go | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/expression/builtin_vectorized_test.go b/expression/builtin_vectorized_test.go index 552fbce052a5d..2e9ca97470366 100644 --- a/expression/builtin_vectorized_test.go +++ b/expression/builtin_vectorized_test.go @@ -17,11 +17,13 @@ import ( "fmt" "math/rand" "sync" + "sync/atomic" "testing" "time" . "github.com/pingcap/check" "github.com/pingcap/errors" + "github.com/pingcap/parser/ast" "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" @@ -783,6 +785,36 @@ func (s *testEvaluatorSuite) TestFloat32ColVec(c *C) { c.Assert(col.VecEvalReal(ctx, chk, result), IsNil) } +func (s *testEvaluatorSuite) TestSleepVec(c *C) { + ctx := mock.NewContext() + sessVars := ctx.GetSessionVars() + + fc := funcs[ast.Sleep] + // non-strict model + sessVars.StrictSQLMode = false + d := make([]types.Datum, 1) + f, err := fc.getFunction(ctx, s.datumsToConstants(d)) + c.Assert(err, IsNil) + + start := time.Now() + go func() { + time.Sleep(1 * time.Second) + atomic.CompareAndSwapUint32(&ctx.GetSessionVars().Killed, 0, 1) + }() + + plus, input, buf := genMockVecPlusIntBuiltinFunc() + plus.enableAlloc = false + err = f.vecEvalInt(input, buf) + + c.Assert(f.vecEvalInt(input, buf), IsNil) + + sub := time.Since(start) + c.Assert(buf.IsNull(0), IsFalse) + c.Assert(buf.GetInt64(0), Equals, int64(1)) + c.Assert(sub.Nanoseconds(), LessEqual, int64(2*1e9)) + c.Assert(sub.Nanoseconds(), GreaterEqual, int64(1*1e9)) +} + func BenchmarkFloat32ColRow(b *testing.B) { col, chk, _ := genFloat32Col() ctx := mock.NewContext() From c73fcd8280f4e0940c43de29387ca715e7739afe Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Wed, 18 Dec 2019 12:10:51 +0800 Subject: [PATCH 07/14] fix --- expression/builtin_vectorized_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/expression/builtin_vectorized_test.go b/expression/builtin_vectorized_test.go index 2e9ca97470366..208c9158bd185 100644 --- a/expression/builtin_vectorized_test.go +++ b/expression/builtin_vectorized_test.go @@ -802,9 +802,10 @@ func (s *testEvaluatorSuite) TestSleepVec(c *C) { atomic.CompareAndSwapUint32(&ctx.GetSessionVars().Killed, 0, 1) }() - plus, input, buf := genMockVecPlusIntBuiltinFunc() - plus.enableAlloc = false - err = f.vecEvalInt(input, buf) + tp := types.NewFieldType(mysql.TypeDecimal) + input := chunk.New([]*types.FieldType{tp}, 1, 1) + buf := chunk.NewColumn(types.NewFieldType(mysql.TypeLonglong), 1) + input.AppendFloat64(0, float64(10)) c.Assert(f.vecEvalInt(input, buf), IsNil) From a7f8e2da0d8a50fab026e38ce3adc549931eb6bb Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Wed, 18 Dec 2019 14:29:52 +0800 Subject: [PATCH 08/14] fix --- expression/builtin_vectorized_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/expression/builtin_vectorized_test.go b/expression/builtin_vectorized_test.go index 208c9158bd185..a1fb8bfc63c7e 100644 --- a/expression/builtin_vectorized_test.go +++ b/expression/builtin_vectorized_test.go @@ -802,10 +802,14 @@ func (s *testEvaluatorSuite) TestSleepVec(c *C) { atomic.CompareAndSwapUint32(&ctx.GetSessionVars().Killed, 0, 1) }() - tp := types.NewFieldType(mysql.TypeDecimal) + a := float64(10.0) + tp := new(types.FieldType) + types.DefaultTypeForValue(a, tp) input := chunk.New([]*types.FieldType{tp}, 1, 1) buf := chunk.NewColumn(types.NewFieldType(mysql.TypeLonglong), 1) - input.AppendFloat64(0, float64(10)) + da := types.Datum{} + da.SetValue(a) + input.AppendDatum(0, &da) c.Assert(f.vecEvalInt(input, buf), IsNil) From e880ec82163163b4724569eb3f6f0bf1c290ed87 Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Wed, 18 Dec 2019 18:15:26 +0800 Subject: [PATCH 09/14] fix https://github.com/pingcap/tidb/pull/14070#discussion_r359170828 --- expression/builtin_miscellaneous.go | 17 +++++++---------- expression/builtin_miscellaneous_vec_test.go | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/expression/builtin_miscellaneous.go b/expression/builtin_miscellaneous.go index f96f6d14907fc..61112b8aa2089 100644 --- a/expression/builtin_miscellaneous.go +++ b/expression/builtin_miscellaneous.go @@ -109,22 +109,19 @@ func (b *builtinSleepSig) Clone() builtinFunc { return newSig } -func sleepDuration(sessVars *variable.SessionVars, val float64) bool { +func sleepDuration(sessVars *variable.SessionVars, val float64) (killed bool) { dur := time.Duration(val * float64(time.Second.Nanoseconds())) ticker := time.NewTicker(10 * time.Millisecond) defer ticker.Stop() start := time.Now() finish := false for !finish { - select { - case now := <-ticker.C: - if now.Sub(start) > dur { - finish = true - } - default: - if atomic.CompareAndSwapUint32(&sessVars.Killed, 1, 0) { - return true - } + now := <-ticker.C + if now.Sub(start) > dur { + finish = true + } + if atomic.CompareAndSwapUint32(&sessVars.Killed, 1, 0) { + return true } } return false diff --git a/expression/builtin_miscellaneous_vec_test.go b/expression/builtin_miscellaneous_vec_test.go index eaa8051f01739..e815b17da0e3a 100644 --- a/expression/builtin_miscellaneous_vec_test.go +++ b/expression/builtin_miscellaneous_vec_test.go @@ -31,7 +31,7 @@ func (g *sleepTimeGener) gen() interface{} { if rand.Float64() < g.nullRation { return nil } - return math.Floor(rand.Float64() * 100) + return math.Floor(rand.Float64() * 10) } var vecBuiltinMiscellaneousCases = map[string][]vecExprBenchCase{ From bc49dd4e17ae78637c9c15b08528631a792475b2 Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Mon, 23 Dec 2019 15:08:00 +0800 Subject: [PATCH 10/14] tmp --- expression/builtin_vectorized_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expression/builtin_vectorized_test.go b/expression/builtin_vectorized_test.go index a1fb8bfc63c7e..5e8f2ef3bc16f 100644 --- a/expression/builtin_vectorized_test.go +++ b/expression/builtin_vectorized_test.go @@ -802,7 +802,7 @@ func (s *testEvaluatorSuite) TestSleepVec(c *C) { atomic.CompareAndSwapUint32(&ctx.GetSessionVars().Killed, 0, 1) }() - a := float64(10.0) + a := float64(3) tp := new(types.FieldType) types.DefaultTypeForValue(a, tp) input := chunk.New([]*types.FieldType{tp}, 1, 1) From 69b0fe3201d8ee1181c9494d46b9dcde443acda9 Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Mon, 23 Dec 2019 20:22:04 +0800 Subject: [PATCH 11/14] maker sleep time shorter --- expression/builtin_miscellaneous_vec_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expression/builtin_miscellaneous_vec_test.go b/expression/builtin_miscellaneous_vec_test.go index e815b17da0e3a..82cc9c837d44b 100644 --- a/expression/builtin_miscellaneous_vec_test.go +++ b/expression/builtin_miscellaneous_vec_test.go @@ -31,7 +31,7 @@ func (g *sleepTimeGener) gen() interface{} { if rand.Float64() < g.nullRation { return nil } - return math.Floor(rand.Float64() * 10) + return math.Floor(rand.Float64()) } var vecBuiltinMiscellaneousCases = map[string][]vecExprBenchCase{ From 6f2837fd00b2d2ea5d8d415b7721875af1ace339 Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Mon, 23 Dec 2019 20:59:04 +0800 Subject: [PATCH 12/14] add more test case --- expression/builtin_vectorized_test.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/expression/builtin_vectorized_test.go b/expression/builtin_vectorized_test.go index 5e8f2ef3bc16f..e4fc3628ec127 100644 --- a/expression/builtin_vectorized_test.go +++ b/expression/builtin_vectorized_test.go @@ -798,19 +798,19 @@ func (s *testEvaluatorSuite) TestSleepVec(c *C) { start := time.Now() go func() { - time.Sleep(1 * time.Second) + time.Sleep(7 * time.Second) atomic.CompareAndSwapUint32(&ctx.GetSessionVars().Killed, 0, 1) }() a := float64(3) + da := types.Datum{} + da.SetValue(a) + tp := new(types.FieldType) types.DefaultTypeForValue(a, tp) input := chunk.New([]*types.FieldType{tp}, 1, 1) buf := chunk.NewColumn(types.NewFieldType(mysql.TypeLonglong), 1) - da := types.Datum{} - da.SetValue(a) input.AppendDatum(0, &da) - c.Assert(f.vecEvalInt(input, buf), IsNil) sub := time.Since(start) @@ -818,6 +818,23 @@ func (s *testEvaluatorSuite) TestSleepVec(c *C) { c.Assert(buf.GetInt64(0), Equals, int64(1)) c.Assert(sub.Nanoseconds(), LessEqual, int64(2*1e9)) c.Assert(sub.Nanoseconds(), GreaterEqual, int64(1*1e9)) + + start = time.Now() + n := 3 + input = chunk.New([]*types.FieldType{tp}, n, n) + buf = chunk.NewColumn(types.NewFieldType(mysql.TypeLonglong), n) + for i := 0; i < n; i++ { + input.AppendDatum(0, &da) + } + c.Assert(f.vecEvalInt(input, buf), IsNil) + + sub = time.Since(start) + for i := 0; i < n; i++ { + c.Assert(buf.IsNull(i), IsFalse) + c.Assert(buf.GetInt64(i), Equals, int64(1)) + } + c.Assert(sub.Nanoseconds(), LessEqual, int64(4*1e9)) + c.Assert(sub.Nanoseconds(), GreaterEqual, int64(3*1e9)) } func BenchmarkFloat32ColRow(b *testing.B) { From cd9d2fbd480189bdb100a53a6ac445a4126537b5 Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Tue, 24 Dec 2019 17:14:56 +0800 Subject: [PATCH 13/14] fix --- expression/builtin_miscellaneous_vec_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/expression/builtin_miscellaneous_vec_test.go b/expression/builtin_miscellaneous_vec_test.go index 82cc9c837d44b..5b63e6bcbec07 100644 --- a/expression/builtin_miscellaneous_vec_test.go +++ b/expression/builtin_miscellaneous_vec_test.go @@ -14,7 +14,6 @@ package expression import ( - "math" "math/rand" "testing" @@ -31,7 +30,10 @@ func (g *sleepTimeGener) gen() interface{} { if rand.Float64() < g.nullRation { return nil } - return math.Floor(rand.Float64()) + if rand.Float64() < 0.5 { + return 0 + } + return 0.1 } var vecBuiltinMiscellaneousCases = map[string][]vecExprBenchCase{ From 902c237be62ad368e53a649fae8e96cc829da32a Mon Sep 17 00:00:00 2001 From: shihongzhi Date: Thu, 26 Dec 2019 09:51:56 +0800 Subject: [PATCH 14/14] tmp --- expression/builtin_vectorized_test.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/expression/builtin_vectorized_test.go b/expression/builtin_vectorized_test.go index e4fc3628ec127..9d11d07b64ede 100644 --- a/expression/builtin_vectorized_test.go +++ b/expression/builtin_vectorized_test.go @@ -796,12 +796,6 @@ func (s *testEvaluatorSuite) TestSleepVec(c *C) { f, err := fc.getFunction(ctx, s.datumsToConstants(d)) c.Assert(err, IsNil) - start := time.Now() - go func() { - time.Sleep(7 * time.Second) - atomic.CompareAndSwapUint32(&ctx.GetSessionVars().Killed, 0, 1) - }() - a := float64(3) da := types.Datum{} da.SetValue(a) @@ -811,21 +805,31 @@ func (s *testEvaluatorSuite) TestSleepVec(c *C) { input := chunk.New([]*types.FieldType{tp}, 1, 1) buf := chunk.NewColumn(types.NewFieldType(mysql.TypeLonglong), 1) input.AppendDatum(0, &da) + + start := time.Now() + go func() { + time.Sleep(1 * time.Second) + atomic.CompareAndSwapUint32(&ctx.GetSessionVars().Killed, 0, 1) + }() c.Assert(f.vecEvalInt(input, buf), IsNil) sub := time.Since(start) - c.Assert(buf.IsNull(0), IsFalse) + c.Assert(buf.IsNull(0), IsTrue) c.Assert(buf.GetInt64(0), Equals, int64(1)) c.Assert(sub.Nanoseconds(), LessEqual, int64(2*1e9)) c.Assert(sub.Nanoseconds(), GreaterEqual, int64(1*1e9)) - start = time.Now() n := 3 input = chunk.New([]*types.FieldType{tp}, n, n) buf = chunk.NewColumn(types.NewFieldType(mysql.TypeLonglong), n) for i := 0; i < n; i++ { input.AppendDatum(0, &da) } + start = time.Now() + go func() { + time.Sleep(3 * time.Second) + atomic.CompareAndSwapUint32(&ctx.GetSessionVars().Killed, 0, 1) + }() c.Assert(f.vecEvalInt(input, buf), IsNil) sub = time.Since(start)