Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#50146
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
jiyfhust authored and ti-chi-bot committed Feb 19, 2024
1 parent 0e1f055 commit dd715ee
Show file tree
Hide file tree
Showing 5 changed files with 4,926 additions and 1 deletion.
4 changes: 4 additions & 0 deletions expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,10 @@ func WrapWithCastAsString(ctx sessionctx.Context, expr Expression) Expression {
charset, collate := expr.CharsetAndCollation()
tp.SetCharset(charset)
tp.SetCollate(collate)
} else if exprTp.GetType() == mysql.TypeBit {
// Implicitly casting BIT to string will make it a binary
tp.SetCharset(charset.CharsetBin)
tp.SetCollate(charset.CollationBin)
} else {
charset, collate := ctx.GetSessionVars().GetCharsetInfo()
tp.SetCharset(charset)
Expand Down
2 changes: 1 addition & 1 deletion expression/builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ func (c *reverseFunctionClass) getFunction(ctx sessionctx.Context, args []Expres
bf.tp.SetFlen(args[0].GetType().GetFlen())
addBinFlag(bf.tp)
var sig builtinFunc
if types.IsBinaryStr(argTp) {
if types.IsBinaryStr(argTp) || types.IsTypeBit(argTp) {
sig = &builtinReverseSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_Reverse)
} else {
Expand Down
6 changes: 6 additions & 0 deletions expression/collation.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ func deriveCoercibilityForColumn(c *Column) Coercibility {
// For specified type null, it should return CoercibilityIgnorable, which means it got the lowest priority in DeriveCollationFromExprs.
if c.RetType.GetType() == mysql.TypeNull {
return CoercibilityIgnorable
} else if types.IsTypeBit(c.RetType) {
return CoercibilityImplicit
}

switch c.RetType.EvalType() {
Expand Down Expand Up @@ -374,6 +376,8 @@ func inferCollation(exprs ...Expression) *ExprCollation {
dstCharset, dstCollation := exprs[0].GetType().GetCharset(), exprs[0].GetType().GetCollate()
if exprs[0].GetType().EvalType() == types.ETJson {
dstCharset, dstCollation = charset.CharsetUTF8MB4, charset.CollationUTF8MB4
} else if types.IsTypeBit(exprs[0].GetType()) {
dstCharset, dstCollation = charset.CharsetBin, charset.CollationBin
}
unknownCS := false

Expand All @@ -384,6 +388,8 @@ func inferCollation(exprs ...Expression) *ExprCollation {
// see details https://github.com/pingcap/tidb/issues/31320#issuecomment-1010599311
if arg.GetType().EvalType() == types.ETJson {
argCharset, argCollation = charset.CharsetUTF8MB4, charset.CollationUTF8MB4
} else if types.IsTypeBit(arg.GetType()) {
argCharset, argCollation = charset.CharsetBin, charset.CollationBin
}
// If one of the arguments is binary charset, we allow it can be used with other charsets.
// If they have the same coercibility, let the binary charset one to be the winner because binary has more precedence.
Expand Down
Loading

0 comments on commit dd715ee

Please sign in to comment.