Skip to content

Commit

Permalink
remove useless codes
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhangxian1008 committed Nov 7, 2023
1 parent ca15a82 commit 8485794
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pkg/expression/builtin_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,13 @@ func setDecimalFromArgs(evalType types.EvalType, resultFieldType *types.FieldTyp
}

// NonBinaryStr means the arg is a string but not binary string
func getNonBinaryStrIdx(args []*types.FieldType) []int {
result := make([]int, 0)
for i, arg := range args {
func hasNonBinaryStr(args []*types.FieldType) bool {
for _, arg := range args {
if types.IsNonBinaryStr(arg) {
result = append(result, i)
return true
}
}
return result
return false
}

func hasBinaryStr(args []*types.FieldType) bool {
Expand Down Expand Up @@ -196,9 +195,9 @@ func addCollateAndCharsetAndFlagFromArgs(ctx sessionctx.Context, funcName string
argTypes = append(argTypes, arg.GetType())
}

nonBinaryStrIdx := getNonBinaryStrIdx(argTypes)
nonBinaryStrExist := hasNonBinaryStr(argTypes)
binaryStrExist := hasBinaryStr(argTypes)
if !binaryStrExist && len(nonBinaryStrIdx) > 0 {
if !binaryStrExist && nonBinaryStrExist {
ec, err := CheckAndDeriveCollationFromExprs(ctx, funcName, evalType, args...)
if err != nil {
return err
Expand All @@ -207,8 +206,6 @@ func addCollateAndCharsetAndFlagFromArgs(ctx sessionctx.Context, funcName string
resultFieldType.SetCharset(ec.Charset)
resultFieldType.SetFlag(0)

ifFirstNonBinaryStrsHaveBinaryFlag := mysql.HasBinaryFlag(argTypes[nonBinaryStrIdx[0]].GetFlag())

// hasNonStringType means that there is a type that is not string
hasNonStringType := false
for _, argType := range argTypes {
Expand All @@ -218,7 +215,7 @@ func addCollateAndCharsetAndFlagFromArgs(ctx sessionctx.Context, funcName string
}
}

if ifFirstNonBinaryStrsHaveBinaryFlag || hasNonStringType {
if hasNonStringType {
resultFieldType.AddFlag(mysql.BinaryFlag)
}
} else if binaryStrExist || !evalType.IsStringKind() {
Expand Down

0 comments on commit 8485794

Please sign in to comment.