Skip to content

Commit

Permalink
*: add comment in detail
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Dec 28, 2021
1 parent 4f8a041 commit 71e4389
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion expression/collation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions parser/charset/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion parser/yy_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ type inputDecoder struct {

func newInputDecoder(chs string) *inputDecoder {
return &inputDecoder{
encoding: charset.FindEncodingUTF8AsNoop(chs),
encoding: charset.FindEncodingTakeUTF8AsNoop(chs),
buffer: nil,
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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
}

Expand Down

0 comments on commit 71e4389

Please sign in to comment.