Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression,parser: Remove PASSWORD() function | tidb-test=pr/2459 #58346

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/executor/reload_expr_pushdown_blacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ var funcName2Alias = map[string]string{
"decode": ast.Decode,
"encode": ast.Encode,
"md5": ast.MD5,
"password": ast.PasswordFunc,
"random_bytes": ast.RandomBytes,
"sha1": ast.SHA1,
"sha": ast.SHA,
Expand Down
1 change: 0 additions & 1 deletion pkg/expression/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,6 @@ var funcs = map[string]functionClass{
ast.Decode: &decodeFunctionClass{baseFunctionClass{ast.Decode, 2, 2}},
ast.Encode: &encodeFunctionClass{baseFunctionClass{ast.Encode, 2, 2}},
ast.MD5: &md5FunctionClass{baseFunctionClass{ast.MD5, 1, 1}},
ast.PasswordFunc: &passwordFunctionClass{baseFunctionClass{ast.PasswordFunc, 1, 1}},
ast.RandomBytes: &randomBytesFunctionClass{baseFunctionClass{ast.RandomBytes, 1, 1}},
ast.SHA1: &sha1FunctionClass{baseFunctionClass{ast.SHA1, 1, 1}},
ast.SHA: &sha1FunctionClass{baseFunctionClass{ast.SHA, 1, 1}},
Expand Down
2 changes: 1 addition & 1 deletion pkg/expression/builtin_convert_charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ var convertActionMap = map[funcProp][]string{
/* result is binary-aware */
ast.ASCII, ast.BitLength, ast.Hex, ast.Length, ast.OctetLength, ast.ToBase64,
/* encrypt functions */
ast.AesDecrypt, ast.Decode, ast.Encode, ast.PasswordFunc, ast.MD5, ast.SHA, ast.SHA1,
ast.AesDecrypt, ast.Decode, ast.Encode, ast.MD5, ast.SHA, ast.SHA1,
ast.SHA2, ast.SM3, ast.Compress, ast.AesEncrypt,
},
funcPropAuto: {
Expand Down
53 changes: 0 additions & 53 deletions pkg/expression/builtin_encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ var (
_ functionClass = &decodeFunctionClass{}
_ functionClass = &encodeFunctionClass{}
_ functionClass = &md5FunctionClass{}
_ functionClass = &passwordFunctionClass{}
_ functionClass = &randomBytesFunctionClass{}
_ functionClass = &sha1FunctionClass{}
_ functionClass = &sha2FunctionClass{}
Expand All @@ -66,7 +65,6 @@ var (
_ builtinFunc = &builtinAesEncryptIVSig{}
_ builtinFunc = &builtinCompressSig{}
_ builtinFunc = &builtinMD5Sig{}
_ builtinFunc = &builtinPasswordSig{}
_ builtinFunc = &builtinRandomBytesSig{}
_ builtinFunc = &builtinSHA1Sig{}
_ builtinFunc = &builtinSHA2Sig{}
Expand Down Expand Up @@ -471,57 +469,6 @@ func (b *builtinEncodeSig) evalString(ctx EvalContext, row chunk.Row) (string, b
return dataStr, false, err
}

type passwordFunctionClass struct {
baseFunctionClass
}

func (c *passwordFunctionClass) getFunction(ctx BuildContext, args []Expression) (builtinFunc, error) {
if err := c.verifyArgs(args); err != nil {
return nil, err
}
bf, err := newBaseBuiltinFuncWithTp(ctx, c.funcName, args, types.ETString, types.ETString)
if err != nil {
return nil, err
}
bf.tp.SetFlen(mysql.PWDHashLen + 1)
sig := &builtinPasswordSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_Password)
return sig, nil
}

type builtinPasswordSig struct {
baseBuiltinFunc
// NOTE: Any new fields added here must be thread-safe or immutable during execution,
// as this expression may be shared across sessions.
// If a field does not meet these requirements, set SafeToShareAcrossSession to false.
}

func (b *builtinPasswordSig) Clone() builtinFunc {
newSig := &builtinPasswordSig{}
newSig.cloneFrom(&b.baseBuiltinFunc)
return newSig
}

// evalString evals a builtinPasswordSig.
// See https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_password
func (b *builtinPasswordSig) evalString(ctx EvalContext, row chunk.Row) (val string, isNull bool, err error) {
pass, isNull, err := b.args[0].EvalString(ctx, row)
if isNull || err != nil {
return "", isNull, err
}

if len(pass) == 0 {
return "", false, nil
}

// 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
tc := typeCtx(ctx)
tc.AppendWarning(errDeprecatedSyntaxNoReplacement.FastGenByArgs("PASSWORD", ""))

return auth.EncodePassword(pass), false, nil
}

type randomBytesFunctionClass struct {
baseFunctionClass
}
Expand Down
58 changes: 0 additions & 58 deletions pkg/expression/builtin_encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/pingcap/tidb/pkg/parser/auth"
"github.com/pingcap/tidb/pkg/parser/charset"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/parser/terror"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/chunk"
Expand Down Expand Up @@ -701,60 +700,3 @@ func TestValidatePasswordStrength(t *testing.T) {
require.Equalf(t, types.NewDatum(test.expect), out, "%v", test)
}
}

func TestPassword(t *testing.T) {
ctx := createContext(t)
cases := []struct {
args any
expected string
charset string
isNil bool
getErr bool
getWarn bool
}{
{nil, "", "", false, false, false},
{"", "", "", false, false, false},
{"abc", "*0D3CED9BEC10A777AEC23CCC353A8C08A633045E", "", false, false, true},
{"abc", "*0D3CED9BEC10A777AEC23CCC353A8C08A633045E", "gbk", false, false, true},
{123, "*23AE809DDACAF96AF0FD78ED04B6A265E05AA257", "", false, false, true},
{1.23, "*A589EEBA8D3F9E1A34A7EE518FAC4566BFAD5BB6", "", false, false, true},
{"一二三四", "*D207780722F22B23C254CAC0580D3B6738C19E18", "", false, false, true},
{"一二三四", "*48E0460AD45CF66AC6B8C18CB8B4BC8A403D935B", "gbk", false, false, true},
{"ㅂ123", "", "gbk", false, true, false},
{types.NewDecFromFloatForTest(123.123), "*B15B84262DB34BFB2C817A45A55C405DC7C52BB1", "", false, false, true},
}

warnCount := len(ctx.GetSessionVars().StmtCtx.GetWarnings())
for _, c := range cases {
err := ctx.GetSessionVars().SetSystemVarWithoutValidation(variable.CharacterSetConnection, c.charset)
require.NoError(t, err)
f, err := newFunctionForTest(ctx, ast.PasswordFunc, primitiveValsToConstants(ctx, []any{c.args})...)
require.NoError(t, err)
d, err := f.Eval(ctx, chunk.Row{})
if c.getErr {
require.Error(t, err)
continue
}
require.NoError(t, err)
if c.isNil {
require.Equal(t, types.KindNull, d.Kind())
} else {
require.Equal(t, c.expected, d.GetString())
}

warnings := ctx.GetSessionVars().StmtCtx.GetWarnings()
if c.getWarn {
require.Equal(t, warnCount+1, len(warnings))

lastWarn := warnings[len(warnings)-1]
require.Truef(t, terror.ErrorEqual(errDeprecatedSyntaxNoReplacement, lastWarn.Err), "err %v", lastWarn.Err)

warnCount = len(warnings)
} else {
require.Equal(t, warnCount, len(warnings))
}
}

_, err := funcs[ast.PasswordFunc].getFunction(ctx, []Expression{NewZero()})
require.NoError(t, err)
}
37 changes: 0 additions & 37 deletions pkg/expression/builtin_encryption_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,43 +707,6 @@ func (b *builtinAesEncryptSig) vecEvalString(ctx EvalContext, input *chunk.Chunk
return nil
}

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

func (b *builtinPasswordSig) vecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf, err := b.bufAllocator.get()
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalString(ctx, input, buf); err != nil {
return err
}
result.ReserveString(n)
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendString("")
continue
}

passBytes := buf.GetBytes(i)
if len(passBytes) == 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
tc := typeCtx(ctx)
tc.AppendWarning(errDeprecatedSyntaxNoReplacement.FastGenByArgs("PASSWORD", ""))

result.AppendString(auth.EncodePasswordBytes(passBytes))
}
return nil
}

func (b *builtinSHA1Sig) vectorized() bool {
return true
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/expression/builtin_encryption_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ var vecBuiltinEncryptionCases = map[string][]vecExprBenchCase{
ast.SHA1: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, aesModes: "aes-128-ecb"},
},
ast.PasswordFunc: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, aesModes: "aes-128-ecb", geners: []dataGenerator{newRandLenStrGener(10, 20)}},
},
ast.SHA2: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETInt}, aesModes: "aes-128-ecb", geners: []dataGenerator{newRandLenStrGener(10, 20), newRangeInt64Gener(SHA0, SHA0+1)}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETInt}, aesModes: "aes-128-ecb", geners: []dataGenerator{newRandLenStrGener(10, 20), newRangeInt64Gener(SHA224, SHA224+1)}},
Expand Down
5 changes: 0 additions & 5 deletions pkg/expression/builtin_threadsafe_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pkg/expression/distsql_builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,6 @@ func getSignatureByPB(ctx BuildContext, sigCode tipb.ScalarFuncSig, tp *tipb.Fie
f = &builtinCompressSig{base}
case tipb.ScalarFuncSig_MD5:
f = &builtinMD5Sig{base}
case tipb.ScalarFuncSig_Password:
f = &builtinPasswordSig{base}
Comment on lines -584 to -585
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we should clean up the protobuf/tikv/tiflash repos as well? Maybe just create deprecation issues in their repositories?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case tipb.ScalarFuncSig_RandomBytes:
f = &builtinRandomBytesSig{base}
case tipb.ScalarFuncSig_SHA1:
Expand Down
1 change: 0 additions & 1 deletion pkg/expression/function_traits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func TestIllegalFunctions4GeneratedColumns(t *testing.T) {
"octet_length",
"or",
"ord",
"password",
"period_add",
"period_diff",
"pi",
Expand Down
1 change: 0 additions & 1 deletion pkg/expression/typeinfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ func (s *InferTypeSuite) createTestCase4StrFuncs() []typeInferTestCase {
{`c_int_d like 'abc%'`, mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag | mysql.IsBooleanFlag, 1, 0},
{"tidb_version()", mysql.TypeVarString, charset.CharsetUTF8MB4, mysql.NotNullFlag, len(printer.GetTiDBInfo()), types.UnspecifiedLength},
{"tidb_is_ddl_owner()", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag | mysql.NotNullFlag, mysql.MaxIntWidth, 0},
{"password(c_char)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, mysql.PWDHashLen + 1, types.UnspecifiedLength},
{"elt(c_int_d, c_char, c_char, c_char)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength},
{"elt(c_int_d, c_char, c_char, c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength},
{"elt(c_int_d, c_char, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength},
Expand Down
2 changes: 1 addition & 1 deletion pkg/expression/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestClone(t *testing.T) {
&builtinIfNullTimeSig{}, &builtinIfNullDurationSig{}, &builtinIfNullJSONSig{}, &builtinIfIntSig{}, &builtinIfRealSig{},
&builtinIfDecimalSig{}, &builtinIfStringSig{}, &builtinIfTimeSig{}, &builtinIfDurationSig{}, &builtinIfJSONSig{},
&builtinAesDecryptSig{}, &builtinAesDecryptIVSig{}, &builtinAesEncryptSig{}, &builtinAesEncryptIVSig{}, &builtinCompressSig{},
&builtinMD5Sig{}, &builtinPasswordSig{}, &builtinRandomBytesSig{}, &builtinSHA1Sig{}, &builtinSHA2Sig{},
&builtinMD5Sig{}, &builtinRandomBytesSig{}, &builtinSHA1Sig{}, &builtinSHA2Sig{},
&builtinUncompressSig{}, &builtinUncompressedLengthSig{}, &builtinDatabaseSig{}, &builtinFoundRowsSig{}, &builtinCurrentUserSig{},
&builtinUserSig{}, &builtinConnectionIDSig{}, &builtinLastInsertIDSig{}, &builtinLastInsertIDWithIDSig{}, &builtinVersionSig{},
&builtinTiDBVersionSig{}, &builtinRowCountSig{}, &builtinJSONTypeSig{}, &builtinJSONQuoteSig{}, &builtinJSONUnquoteSig{},
Expand Down
1 change: 0 additions & 1 deletion pkg/parser/ast/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ const (
Decode = "decode"
Encode = "encode"
MD5 = "md5"
PasswordFunc = "password"
RandomBytes = "random_bytes"
SHA1 = "sha1"
SHA = "sha"
Expand Down
Loading