Skip to content

Commit

Permalink
Merge branch 'master' into builtinRoundWithFracRealSig
Browse files Browse the repository at this point in the history
  • Loading branch information
tsthght authored Sep 23, 2019
2 parents 84f0aa3 + 14df525 commit 131d85d
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 1 deletion.
25 changes: 25 additions & 0 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,28 @@ func (b *builtinCastIntAsRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.
func (b *builtinCastIntAsRealSig) vectorized() bool {
return true
}

func (b *builtinCastRealAsRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
}
n := input.NumRows()
f64s := result.Float64s()
conditionUnionAndUnsigned := b.inUnion && mysql.HasUnsignedFlag(b.tp.Flag)
if !conditionUnionAndUnsigned {
return nil
}
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
if f64s[i] < 0 {
f64s[i] = 0
}
}
return nil
}

func (b *builtinCastRealAsRealSig) vectorized() bool {
return true
}
1 change: 1 addition & 0 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
{types.ETInt, []types.EvalType{types.ETInt}, nil},
{types.ETReal, []types.EvalType{types.ETInt}, nil},
{types.ETDuration, []types.EvalType{types.ETInt}, []dataGenerator{new(randDurInt)}},
{types.ETReal, []types.EvalType{types.ETReal}, nil},
},
}

Expand Down
35 changes: 35 additions & 0 deletions expression/builtin_compare_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,38 @@ func (b *builtinLeastDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *chun
func (b *builtinLeastDecimalSig) vectorized() bool {
return true
}

func (b *builtinLeastIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETInt, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalInt(b.ctx, input, result); err != nil {
return err
}

i64s := result.Int64s()
for j := 1; j < len(b.args); j++ {
if err := b.args[j].VecEvalInt(b.ctx, input, buf); err != nil {
return err
}

result.MergeNulls(buf)
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
v := buf.GetInt64(i)
if v < i64s[i] {
i64s[i] = v
}
}
}
return nil
}

func (b *builtinLeastIntSig) vectorized() bool {
return true
}
1 change: 1 addition & 0 deletions expression/builtin_compare_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var vecBuiltinCompareCases = map[string][]vecExprBenchCase{
},
ast.Least: {
{types.ETDecimal, []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}, nil},
{types.ETInt, []types.EvalType{types.ETInt, types.ETInt, types.ETInt}, nil},
},
}

Expand Down
111 changes: 111 additions & 0 deletions expression/builtin_math_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ import (
"github.com/pingcap/tidb/util/chunk"
)

func (b *builtinLog1ArgSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
}
f64s := result.Float64s()
for i := 0; i < len(f64s); i++ {
if result.IsNull(i) {
continue
}
if f64s[i] <= 0 {
result.SetNull(i, true)
} else {
f64s[i] = math.Log(f64s[i])
}
}
return nil
}

func (b *builtinLog1ArgSig) vectorized() bool {
return true
}

func (b *builtinLog2Sig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
Expand Down Expand Up @@ -247,6 +269,49 @@ func (b *builtinDegreesSig) vectorized() bool {
return true
}

func (b *builtinExpSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
}
f64s := result.Float64s()
for i := 0; i < len(f64s); i++ {
if result.IsNull(i) {
continue
}
exp := math.Exp(f64s[i])
if math.IsInf(exp, 0) || math.IsNaN(exp) {
s := fmt.Sprintf("exp(%s)", b.args[0].String())
if err := types.ErrOverflow.GenWithStackByArgs("DOUBLE", s); err != nil {
return err
}
}
f64s[i] = exp
}
return nil
}

func (b *builtinExpSig) vectorized() bool {
return true
}

func (b *builtinRadiansSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
}
f64s := result.Float64s()
for i := 0; i < len(f64s); i++ {
if result.IsNull(i) {
continue
}
f64s[i] = f64s[i] * math.Pi / 180
}
return nil
}

func (b *builtinRadiansSig) vectorized() bool {
return true
}

func (b *builtinSinSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
Expand Down Expand Up @@ -392,6 +457,52 @@ func (b *builtinRoundWithFracRealSig) vecEvalReal(input *chunk.Chunk, result *ch
return nil
}

func (b *builtinAbsRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
}
f64s := result.Float64s()
for i := 0; i < len(f64s); i++ {
f64s[i] = math.Abs(f64s[i])
}
return nil
}

func (b *builtinAbsRealSig) vectorized() bool {
return true
}

func (b *builtinAbsIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalInt(b.ctx, input, result); err != nil {
return err
}
i64s := result.Int64s()
for i := 0; i < len(i64s); i++ {
if result.IsNull(i) {
continue
}
if i64s[i] == math.MinInt64 {
return types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("abs(%d)", i64s[i]))
}
if i64s[i] < 0 {
i64s[i] = -i64s[i]
}
}
return nil
}

func (b *builtinRoundWithFracRealSig) vectorized() bool {
return true
}

func (b *builtinAbsIntSig) vectorized() bool {
return true
}

func (b *builtinRoundIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return b.args[0].VecEvalInt(b.ctx, input, result)
}

func (b *builtinRoundIntSig) vectorized() bool {
return true
}
12 changes: 12 additions & 0 deletions expression/builtin_math_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
)

var vecBuiltinMathCases = map[string][]vecExprBenchCase{
ast.Log: {
{types.ETReal, []types.EvalType{types.ETReal}, nil},
},
ast.Log10: {
{types.ETReal, []types.EvalType{types.ETReal}, nil},
},
Expand All @@ -46,12 +49,18 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{
ast.Cos: {
{types.ETReal, []types.EvalType{types.ETReal}, nil},
},
ast.Exp: {
{types.ETReal, []types.EvalType{types.ETReal}, nil},
},
ast.Degrees: {
{types.ETReal, []types.EvalType{types.ETReal}, nil},
},
ast.Cot: {
{types.ETReal, []types.EvalType{types.ETReal}, nil},
},
ast.Radians: {
{types.ETReal, []types.EvalType{types.ETReal}, nil},
},
ast.Sin: {
{types.ETReal, []types.EvalType{types.ETReal}, nil},
},
Expand All @@ -60,10 +69,13 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{
},
ast.Abs: {
{types.ETDecimal, []types.EvalType{types.ETDecimal}, nil},
{types.ETReal, []types.EvalType{types.ETReal}, nil},
{types.ETInt, []types.EvalType{types.ETInt}, nil},
},
ast.Round: {
{types.ETDecimal, []types.EvalType{types.ETDecimal}, nil},
{types.ETReal, []types.EvalType{types.ETReal, types.ETInt}, []dataGenerator{nil, &rangeInt64Gener{-100, 100}}},
{types.ETInt, []types.EvalType{types.ETInt}, nil},
},
ast.Pow: {
{types.ETReal, []types.EvalType{types.ETReal, types.ETReal}, []dataGenerator{&rangeRealGener{0, 10, 0.5}, &rangeRealGener{0, 100, 0.5}}},
Expand Down
46 changes: 46 additions & 0 deletions expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,49 @@ Loop:
func (b *builtinUpperSig) vectorized() bool {
return true
}

func (b *builtinRightSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalString(b.ctx, input, buf); err != nil {
return err
}

buf2, err := b.bufAllocator.get(types.ETInt, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf2)
if err := b.args[1].VecEvalInt(b.ctx, input, buf2); err != nil {
return err
}

result.ReserveString(n)
nums := buf2.Int64s()
for i := 0; i < n; i++ {
if buf.IsNull(i) || buf2.IsNull(i) {
result.AppendNull()
continue
}

str := buf.GetString(i)
runes := []rune(str)
strLength, rightLength := len(runes), int(nums[i])
if rightLength > strLength {
rightLength = strLength
} else if rightLength < 0 {
rightLength = 0
}

result.AppendString(string(runes[strLength-rightLength:]))
}
return nil
}

func (b *builtinRightSig) vectorized() bool {
return true
}
3 changes: 3 additions & 0 deletions expression/builtin_string_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ var vecBuiltinStringCases = map[string][]vecExprBenchCase{
ast.Upper: {
{types.ETString, []types.EvalType{types.ETString}, nil},
},
ast.Right: {
{types.ETString, []types.EvalType{types.ETString, types.ETInt}, nil},
},
}

func (s *testEvaluatorSuite) TestVectorizedBuiltinStringEvalOneVec(c *C) {
Expand Down
8 changes: 7 additions & 1 deletion store/tikv/split_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/tidb/store/tikv/tikvrpc"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/stringutil"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -154,7 +155,12 @@ func (s *tikvStore) batchSendSingleRegion(bo *Backoffer, batch batch, scatter bo
logutil.BgLogger().Info("batch split regions complete",
zap.Uint64("batch region ID", batch.regionID.id),
zap.Stringer("first at", kv.Key(batch.keys[0])),
zap.Stringer("first new region left", logutil.Hex(spResp.Regions[0])),
zap.Stringer("first new region left", stringutil.MemoizeStr(func() string {
if len(spResp.Regions) == 0 {
return ""
}
return logutil.Hex(spResp.Regions[0]).String()
})),
zap.Int("new region count", len(spResp.Regions)))

if !scatter {
Expand Down

0 comments on commit 131d85d

Please sign in to comment.