diff --git a/expression/collation.go b/expression/collation.go index 4f9fd9a26c8f5..edfba16197895 100644 --- a/expression/collation.go +++ b/expression/collation.go @@ -297,7 +297,7 @@ func CheckAndDeriveCollationFromExprs(ctx sessionctx.Context, funcName string, e } func safeConvert(ctx sessionctx.Context, ec *ExprCollation, args ...Expression) bool { - enc := charset.FindEncodingUTF8AsNoop(ec.Charset) + enc := charset.FindEncodingTakeUTF8AsNoop(ec.Charset) for _, arg := range args { if arg.GetType().Charset == ec.Charset { continue diff --git a/parser/charset/encoding.go b/parser/charset/encoding.go index 02f74c1fbad6a..eb9cef46ecc24 100644 --- a/parser/charset/encoding.go +++ b/parser/charset/encoding.go @@ -29,9 +29,10 @@ func IsSupportedEncoding(charset string) bool { return ok } -// FindEncodingUTF8AsNoop finds the encoding according to charset -// except that utf-8 is treated as binary encoding. -func FindEncodingUTF8AsNoop(charset string) Encoding { +// FindEncodingTakeUTF8AsNoop finds the encoding according to the charset +// except that utf-8 is treated as no-operation encoding. This is used to +// reduce the overhead of utf-8 validation in some cases. +func FindEncodingTakeUTF8AsNoop(charset string) Encoding { enc := FindEncoding(charset) if enc.Tp() == EncodingTpUTF8 { return EncodingBinImpl diff --git a/parser/yy_parser.go b/parser/yy_parser.go index a0e373618f26b..5fedd0a1afb48 100644 --- a/parser/yy_parser.go +++ b/parser/yy_parser.go @@ -436,6 +436,6 @@ type CharsetClient string // ApplyOn implements ParseParam interface. func (c CharsetClient) ApplyOn(p *Parser) error { - p.lexer.encoding = charset.FindEncodingUTF8AsNoop(string(c)) + p.lexer.encoding = charset.FindEncodingTakeUTF8AsNoop(string(c)) return nil } diff --git a/server/util.go b/server/util.go index 3604c1c779629..8314f7d6cfd05 100644 --- a/server/util.go +++ b/server/util.go @@ -298,7 +298,7 @@ type inputDecoder struct { func newInputDecoder(chs string) *inputDecoder { return &inputDecoder{ - encoding: charset.FindEncodingUTF8AsNoop(chs), + encoding: charset.FindEncodingTakeUTF8AsNoop(chs), buffer: nil, } } @@ -336,7 +336,7 @@ type resultEncoder struct { func newResultEncoder(chs string) *resultEncoder { return &resultEncoder{ chsName: chs, - encoding: charset.FindEncodingUTF8AsNoop(chs), + encoding: charset.FindEncodingTakeUTF8AsNoop(chs), buffer: nil, isBinary: chs == charset.CharsetBinary, isNull: len(chs) == 0, @@ -353,7 +353,7 @@ func (d *resultEncoder) updateDataEncoding(chsID uint16) { if err != nil { logutil.BgLogger().Warn("unknown charset ID", zap.Error(err)) } - d.dataEncoding = charset.FindEncodingUTF8AsNoop(chs) + d.dataEncoding = charset.FindEncodingTakeUTF8AsNoop(chs) d.dataIsBinary = chsID == mysql.BinaryDefaultCollationID }