diff --git a/expression/builtin_encryption_vec.go b/expression/builtin_encryption_vec.go index 57d3693ee8..036545eae0 100644 --- a/expression/builtin_encryption_vec.go +++ b/expression/builtin_encryption_vec.go @@ -15,6 +15,7 @@ package expression import ( "github.com/pingcap/errors" + "github.com/pingcap/parser/auth" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/encrypt" @@ -163,11 +164,37 @@ func (b *builtinAesEncryptSig) vecEvalString(input *chunk.Chunk, result *chunk.C } func (b *builtinPasswordSig) vectorized() bool { - return false + return true } func (b *builtinPasswordSig) 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) + for i := 0; i < n; i++ { + if buf.IsNull(i) { + result.AppendString("") + continue + } + pass := buf.GetString(i) + if len(pass) == 0 { + result.AppendString("") + continue + } + // We should append a warning here because function "PASSWORD" is deprecated since MySQL 5.7.6. + // See https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_password + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errDeprecatedSyntaxNoReplacement.GenWithStackByArgs("PASSWORD")) + + result.AppendString(auth.EncodePassword(pass)) + } + return nil } func (b *builtinSHA1Sig) vectorized() bool { diff --git a/expression/builtin_encryption_vec_test.go b/expression/builtin_encryption_vec_test.go index dd94d88d94..3611337666 100644 --- a/expression/builtin_encryption_vec_test.go +++ b/expression/builtin_encryption_vec_test.go @@ -31,8 +31,10 @@ var vecBuiltinEncryptionCases = map[string][]vecExprBenchCase{ ast.RandomBytes: {}, ast.UncompressedLength: {}, ast.SHA1: {}, - ast.PasswordFunc: {}, - ast.SHA2: {}, + ast.PasswordFunc: { + {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&randLenStrGener{10, 20}}}, + }, + ast.SHA2: {}, ast.Encode: { {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}}, },