github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/builtin_arithmetic_vec_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package memex 15 16 import ( 17 "math" 18 "testing" 19 20 . "github.com/whtcorpsinc/check" 21 "github.com/whtcorpsinc/BerolinaSQL/ast" 22 "github.com/whtcorpsinc/BerolinaSQL/allegrosql" 23 "github.com/whtcorpsinc/milevadb/types" 24 ) 25 26 var vecBuiltinArithmeticCases = map[string][]vecExprBenchCase{ 27 ast.LE: {}, 28 ast.Minus: { 29 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}}, 30 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}}, 31 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{newRangeInt64Gener(-100000, 100000), newRangeInt64Gener(-100000, 100000)}}, 32 }, 33 ast.Div: { 34 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}}, 35 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, newRangeRealGener(0, 0, 0)}}, 36 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}}, 37 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, newRangeDecimalGener(0, 0, 0.2)}}, 38 }, 39 ast.IntDiv: { 40 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}}, 41 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, newRangeDecimalGener(0, 0, 0.2)}}, 42 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, 43 childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeNewDecimal, Flag: allegrosql.UnsignedFlag}, nil}, 44 geners: []dataGenerator{newRangeDecimalGener(0, 10000, 0.2), newRangeDecimalGener(0, 10000, 0.2)}, 45 }, 46 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, 47 childrenFieldTypes: []*types.FieldType{nil, {Tp: allegrosql.TypeNewDecimal, Flag: allegrosql.UnsignedFlag}}, 48 geners: []dataGenerator{newRangeDecimalGener(0, 10000, 0.2), newRangeDecimalGener(0, 10000, 0.2)}, 49 }, 50 // when the final result is at (-1, 0], it should be return 0 instead of the error 51 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, 52 childrenFieldTypes: []*types.FieldType{nil, {Tp: allegrosql.TypeNewDecimal, Flag: allegrosql.UnsignedFlag}}, 53 geners: []dataGenerator{newRangeDecimalGener(-100, -1, 0.2), newRangeDecimalGener(1000, 2000, 0.2)}, 54 }, 55 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 56 geners: []dataGenerator{ 57 newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2), 58 newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2), 59 }, 60 }, 61 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 62 childrenFieldTypes: []*types.FieldType{ 63 {Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}, 64 {Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}}, 65 geners: []dataGenerator{ 66 newRangeInt64Gener(0, math.MaxInt64), 67 newRangeInt64Gener(0, math.MaxInt64), 68 }, 69 }, 70 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 71 childrenFieldTypes: []*types.FieldType{ 72 {Tp: allegrosql.TypeLonglong}, 73 {Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}}, 74 geners: []dataGenerator{ 75 newRangeInt64Gener(0, math.MaxInt64), 76 newRangeInt64Gener(0, math.MaxInt64), 77 }, 78 }, 79 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 80 childrenFieldTypes: []*types.FieldType{ 81 {Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}, 82 {Tp: allegrosql.TypeLonglong}}, 83 geners: []dataGenerator{ 84 newRangeInt64Gener(0, math.MaxInt64), 85 newRangeInt64Gener(0, math.MaxInt64), 86 }, 87 }, 88 }, 89 ast.Mod: { 90 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}}, 91 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, newRangeRealGener(0, 0, 0)}}, 92 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{newRangeRealGener(0, 0, 0), nil}}, 93 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, newRangeRealGener(0, 0, 1)}}, 94 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}}, 95 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, newRangeDecimalGener(0, 0, 0)}}, 96 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{newRangeDecimalGener(0, 0, 0), nil}}, 97 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}, geners: []dataGenerator{nil, newRangeDecimalGener(0, 0, 1)}}, 98 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{nil, newRangeInt64Gener(0, 1)}}, 99 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{newRangeInt64Gener(0, 1), nil}}, 100 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 101 geners: []dataGenerator{ 102 newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2), 103 newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2), 104 }, 105 }, 106 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 107 childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}, 108 {Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}}, 109 geners: []dataGenerator{ 110 newRangeInt64Gener(0, math.MaxInt64), 111 newRangeInt64Gener(0, math.MaxInt64), 112 }, 113 }, 114 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 115 childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong}, 116 {Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}}, 117 geners: []dataGenerator{ 118 newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2), 119 newRangeInt64Gener(0, math.MaxInt64), 120 }, 121 }, 122 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 123 childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}, 124 {Tp: allegrosql.TypeLonglong}}, 125 geners: []dataGenerator{ 126 newRangeInt64Gener(0, math.MaxInt64), 127 newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2), 128 }, 129 }, 130 }, 131 ast.Or: {}, 132 ast.Mul: { 133 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}}, 134 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}}, 135 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{newRangeInt64Gener(-10000, 10000), newRangeInt64Gener(-10000, 10000)}}, 136 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeInt24, Flag: allegrosql.UnsignedFlag}, {Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}}, 137 geners: []dataGenerator{ 138 newRangeInt64Gener(0, 10000), 139 newRangeInt64Gener(0, 10000), 140 }, 141 }, 142 }, 143 ast.Round: {}, 144 ast.And: {}, 145 ast.Plus: { 146 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}}, 147 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal}}, 148 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 149 geners: []dataGenerator{ 150 newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2), 151 newRangeInt64Gener(math.MinInt64/2, math.MaxInt64/2), 152 }, 153 }, 154 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 155 childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}, 156 {Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}}, 157 geners: []dataGenerator{ 158 newRangeInt64Gener(0, math.MaxInt64), 159 newRangeInt64Gener(0, math.MaxInt64), 160 }, 161 }, 162 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 163 childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong}, 164 {Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}}, 165 geners: []dataGenerator{ 166 newRangeInt64Gener(0, math.MaxInt64), 167 newRangeInt64Gener(0, math.MaxInt64), 168 }, 169 }, 170 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, 171 childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}, 172 {Tp: allegrosql.TypeLonglong}}, 173 geners: []dataGenerator{ 174 newRangeInt64Gener(0, math.MaxInt64), 175 newRangeInt64Gener(0, math.MaxInt64), 176 }, 177 }, 178 }, 179 ast.NE: {}, 180 } 181 182 func (s *testEvaluatorSuite) TestVectorizedBuiltinArithmeticFunc(c *C) { 183 testVectorizedBuiltinFunc(c, vecBuiltinArithmeticCases) 184 } 185 186 func BenchmarkVectorizedBuiltinArithmeticFunc(b *testing.B) { 187 benchmarkVectorizedBuiltinFunc(b, vecBuiltinArithmeticCases) 188 }