Skip to content

Commit

Permalink
expression: optimize unit test (pingcap#14503)
Browse files Browse the repository at this point in the history
  • Loading branch information
glorv authored and SunRunAway committed Jan 17, 2020
1 parent 00ef8b6 commit a7076a5
Show file tree
Hide file tree
Showing 27 changed files with 1,940 additions and 1,781 deletions.
340 changes: 235 additions & 105 deletions expression/bench_test.go

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions expression/builtin_arithmetic_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,82 +28,82 @@ var vecBuiltinArithmeticCases = map[string][]vecExprBenchCase{
ast.Minus: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{&rangeInt64Gener{-100000, 100000}, &rangeInt64Gener{-100000, 100000}}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{newRangeInt64Gener(-100000, 100000), newRangeInt64Gener(-100000, 100000)}},
},
ast.Div: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, &rangeRealGener{0, 0, 0}}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, newRangeRealGener(0, 0, 0)}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, &rangeDecimalGener{0, 0, 0.2}}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, newRangeDecimalGener(0, 0, 0.2)}},
},
ast.IntDiv: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, &rangeDecimalGener{0, 0, 0.2}}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, newRangeDecimalGener(0, 0, 0.2)}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal},
childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeNewDecimal, Flag: mysql.UnsignedFlag}, nil},
geners: []dataGenerator{&rangeDecimalGener{0, 10000, 0.2}, &rangeDecimalGener{0, 10000, 0.2}},
geners: []dataGenerator{newRangeDecimalGener(0, 10000, 0.2), newRangeDecimalGener(0, 10000, 0.2)},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal},
childrenFieldTypes: []*types.FieldType{nil, {Tp: mysql.TypeNewDecimal, Flag: mysql.UnsignedFlag}},
geners: []dataGenerator{&rangeDecimalGener{0, 10000, 0.2}, &rangeDecimalGener{0, 10000, 0.2}},
geners: []dataGenerator{newRangeDecimalGener(0, 10000, 0.2), newRangeDecimalGener(0, 10000, 0.2)},
},
// when the final result is at (-1, 0], it should be return 0 instead of the error
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal},
childrenFieldTypes: []*types.FieldType{nil, {Tp: mysql.TypeNewDecimal, Flag: mysql.UnsignedFlag}},
geners: []dataGenerator{&rangeDecimalGener{-100, -1, 0.2}, &rangeDecimalGener{1000, 2000, 0.2}},
geners: []dataGenerator{newRangeDecimalGener(-100, -1, 0.2), newRangeDecimalGener(1000, 2000, 0.2)},
},
},
ast.Mod: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, &rangeRealGener{0, 0, 0}}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{&rangeRealGener{0, 0, 0}, nil}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, &rangeRealGener{0, 0, 1}}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, newRangeRealGener(0, 0, 0)}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{newRangeRealGener(0, 0, 0), nil}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, newRangeRealGener(0, 0, 1)}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, &rangeDecimalGener{0, 0, 0}}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{&rangeDecimalGener{0, 0, 0}, nil}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, &rangeDecimalGener{0, 0, 1}}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{nil, &rangeInt64Gener{0, 1}}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{&rangeInt64Gener{0, 1}, nil}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, newRangeDecimalGener(0, 0, 0)}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{newRangeDecimalGener(0, 0, 0), nil}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, newRangeDecimalGener(0, 0, 1)}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{nil, newRangeInt64Gener(0, 1)}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{newRangeInt64Gener(0, 1), nil}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
geners: []dataGenerator{
&rangeInt64Gener{begin: math.MinInt64 / 2, end: math.MaxInt64 / 2},
&rangeInt64Gener{begin: math.MinInt64 / 2, end: math.MaxInt64 / 2},
newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2),
newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2),
},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag},
{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}},
geners: []dataGenerator{
&rangeInt64Gener{begin: 0, end: math.MaxInt64},
&rangeInt64Gener{begin: 0, end: math.MaxInt64},
newRangeInt64Gener(0, math.MaxInt64),
newRangeInt64Gener(0, math.MaxInt64),
},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong},
{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}},
geners: []dataGenerator{
&rangeInt64Gener{begin: math.MinInt64 / 2, end: math.MaxInt64 / 2},
&rangeInt64Gener{begin: 0, end: math.MaxInt64},
newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2),
newRangeInt64Gener(0, math.MaxInt64),
},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag},
{Tp: mysql.TypeLonglong}},
geners: []dataGenerator{
&rangeInt64Gener{begin: 0, end: math.MaxInt64},
&rangeInt64Gener{begin: math.MinInt64 / 2, end: math.MaxInt64 / 2},
newRangeInt64Gener(0, math.MaxInt64),
newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2),
},
},
},
ast.Or: {},
ast.Mul: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{&rangeInt64Gener{-10000, 10000}, &rangeInt64Gener{-10000, 10000}}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{newRangeInt64Gener(-10000, 10000), newRangeInt64Gener(-10000, 10000)}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeInt24, Flag: mysql.UnsignedFlag}, {Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}},
geners: []dataGenerator{
&rangeInt64Gener{begin: 0, end: 10000},
&rangeInt64Gener{begin: 0, end: 10000},
newRangeInt64Gener(0, 10000),
newRangeInt64Gener(0, 10000),
},
},
},
Expand All @@ -114,32 +114,32 @@ var vecBuiltinArithmeticCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
geners: []dataGenerator{
&rangeInt64Gener{begin: math.MinInt64 / 2, end: math.MaxInt64 / 2},
&rangeInt64Gener{begin: math.MinInt64 / 2, end: math.MaxInt64 / 2},
newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2),
newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2),
},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag},
{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}},
geners: []dataGenerator{
&rangeInt64Gener{begin: 0, end: math.MaxInt64},
&rangeInt64Gener{begin: 0, end: math.MaxInt64},
newRangeInt64Gener(0, math.MaxInt64),
newRangeInt64Gener(0, math.MaxInt64),
},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong},
{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}},
geners: []dataGenerator{
&rangeInt64Gener{begin: 0, end: math.MaxInt64},
&rangeInt64Gener{begin: 0, end: math.MaxInt64},
newRangeInt64Gener(0, math.MaxInt64),
newRangeInt64Gener(0, math.MaxInt64),
},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag},
{Tp: mysql.TypeLonglong}},
geners: []dataGenerator{
&rangeInt64Gener{begin: 0, end: math.MaxInt64},
&rangeInt64Gener{begin: 0, end: math.MaxInt64},
newRangeInt64Gener(0, math.MaxInt64),
newRangeInt64Gener(0, math.MaxInt64),
},
},
},
Expand Down
30 changes: 15 additions & 15 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

var vecBuiltinCastCases = map[string][]vecExprBenchCase{
ast.Cast: {
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETJson}, geners: []dataGenerator{&decimalJSONGener{}}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&decimalStringGener{}}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETJson}, geners: []dataGenerator{newDecimalJSONGener(0)}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{newDecimalStringGener()}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDuration}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}},
Expand All @@ -40,26 +40,26 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
{
retEvalType: types.ETInt,
childrenTypes: []types.EvalType{types.ETString},
geners: []dataGenerator{&numStrGener{rangeInt64Gener{math.MinInt64 + 1, 0}}},
geners: []dataGenerator{&numStrGener{*newRangeInt64Gener(math.MinInt64+1, 0)}},
},
{
retEvalType: types.ETInt,
childrenTypes: []types.EvalType{types.ETString},
geners: []dataGenerator{&numStrGener{rangeInt64Gener{0, math.MaxInt64}}},
geners: []dataGenerator{&numStrGener{*newRangeInt64Gener(0, math.MaxInt64)}},
},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETInt}},
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETInt}, geners: []dataGenerator{new(randDurInt)}},
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETReal}, geners: []dataGenerator{new(randDurReal)}},
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETDecimal}, geners: []dataGenerator{new(randDurDecimal)}},
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETInt}, geners: []dataGenerator{newRandDurInt()}},
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETReal}, geners: []dataGenerator{newRandDurReal()}},
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETDecimal}, geners: []dataGenerator{newRandDurDecimal()}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETJson}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETDecimal}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&realStringGener{}}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{newRealStringGener()}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETDatetime}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETDuration}, geners: []dataGenerator{&rangeDurationGener{nullRation: 0.5}}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETDuration}, geners: []dataGenerator{newRangeDurationGener(0.5)}},
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETDatetime},
geners: []dataGenerator{&dateTimeGenerWithFsp{
defaultGener: defaultGener{nullRation: 0.2, eType: types.ETDatetime},
defaultGener: *newDefaultGener(0.2, types.ETDatetime),
fsp: 1,
}},
},
Expand All @@ -79,24 +79,24 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETDuration}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETDatetime}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETJson}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&jsonStringGener{}}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{newJSONStringGener()}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETDecimal}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETJson}, geners: []dataGenerator{&datetimeJSONGener{}}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDecimal}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETInt}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETString},
geners: []dataGenerator{
&dateTimeStrGener{},
&dateStrGener{},
&timeStrGener{},
&dateTimeStrGener{randGen: newDefaultRandGen()},
&dateStrGener{randGen: newDefaultRandGen()},
&timeStrGener{randGen: newDefaultRandGen()},
}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDuration}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDatetime}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETTimestamp}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETJson},
geners: []dataGenerator{
&jsonTimeGener{},
newJSONTimeGener(),
}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETInt}},
Expand Down
42 changes: 21 additions & 21 deletions expression/builtin_compare_vec_generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a7076a5

Please sign in to comment.