Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinSHA1Si… (ping…
Browse files Browse the repository at this point in the history
  • Loading branch information
mmyj authored and XiaTianliang committed Dec 21, 2019
1 parent 1da46f1 commit 1c10857
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
31 changes: 29 additions & 2 deletions expression/builtin_encryption_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
package expression

import (
"crypto/sha1"
"fmt"

"github.com/pingcap/errors"
"github.com/pingcap/parser/auth"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -198,11 +201,35 @@ func (b *builtinPasswordSig) vecEvalString(input *chunk.Chunk, result *chunk.Col
}

func (b *builtinSHA1Sig) vectorized() bool {
return false
return true
}

func (b *builtinSHA1Sig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
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
}
result.ReserveString(n)
hasher := sha1.New()
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
continue
}
str := buf.GetBytes(i)
_, err = hasher.Write(str)
if err != nil {
return err
}
result.AppendString(fmt.Sprintf("%x", hasher.Sum(nil)))
hasher.Reset()
}
return nil
}

func (b *builtinUncompressSig) vectorized() bool {
Expand Down
17 changes: 10 additions & 7 deletions expression/builtin_encryption_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ import (
)

var vecBuiltinEncryptionCases = map[string][]vecExprBenchCase{
ast.AesEncrypt: {},
ast.Uncompress: {},
ast.AesDecrypt: {},
ast.Compress: {},
ast.MD5: {},
ast.SHA: {},
ast.AesEncrypt: {},
ast.Uncompress: {},
ast.AesDecrypt: {},
ast.Compress: {},
ast.MD5: {},
ast.SHA: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}}},
ast.RandomBytes: {},
ast.UncompressedLength: {},
ast.SHA1: {},
ast.SHA1: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}},
},
ast.PasswordFunc: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&randLenStrGener{10, 20}}},
},
Expand Down

0 comments on commit 1c10857

Please sign in to comment.