Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinEncodeSig (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
mmyj authored and sre-bot committed Oct 15, 2019
1 parent a4d8220 commit 7c3d1fa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
37 changes: 35 additions & 2 deletions expression/builtin_encryption_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ package expression

import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/encrypt"
)

func (b *builtinAesDecryptSig) vectorized() bool {
Expand Down Expand Up @@ -43,11 +45,42 @@ func (b *builtinDecodeSig) vecEvalString(input *chunk.Chunk, result *chunk.Colum
}

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

func (b *builtinEncodeSig) 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
}
buf1, err1 := b.bufAllocator.get(types.ETString, n)
if err1 != nil {
return err1
}
defer b.bufAllocator.put(buf1)
if err := b.args[1].VecEvalString(b.ctx, input, buf1); err != nil {
return err
}
result.ReserveString(n)
for i := 0; i < n; i++ {
if buf.IsNull(i) || buf1.IsNull(i) {
result.AppendNull()
continue
}
decodeStr := buf.GetString(i)
passwordStr := buf1.GetString(i)
dataStr, err := encrypt.SQLEncode(decodeStr, passwordStr)
if err != nil {
return err
}
result.AppendString(dataStr)
}
return nil
}

func (b *builtinAesDecryptIVSig) vectorized() bool {
Expand Down
4 changes: 4 additions & 0 deletions expression/builtin_encryption_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

. "github.com/pingcap/check"
"github.com/pingcap/parser/ast"
"github.com/pingcap/tidb/types"
)

var vecBuiltinEncryptionCases = map[string][]vecExprBenchCase{
Expand All @@ -32,6 +33,9 @@ var vecBuiltinEncryptionCases = map[string][]vecExprBenchCase{
ast.SHA1: {},
ast.PasswordFunc: {},
ast.SHA2: {},
ast.Encode: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}},
},
}

func (s *testEvaluatorSuite) TestVectorizedBuiltinEncryptionFunc(c *C) {
Expand Down

0 comments on commit 7c3d1fa

Please sign in to comment.