-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
collation: cast charset according to the function's resulting charset #29029
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1218,7 +1218,12 @@ func convertUint(val []byte) (*Constant, error) { | |
func convertString(val []byte, tp *tipb.FieldType) (*Constant, error) { | ||
var d types.Datum | ||
d.SetBytesAsString(val, protoToCollation(tp.Collate), uint32(tp.Flen)) | ||
return &Constant{Value: d, RetType: types.NewFieldType(mysql.TypeVarString)}, nil | ||
return &Constant{Value: d, RetType: &types.FieldType{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pb to string expression should use charset information in pb |
||
Tp: mysql.TypeString, | ||
Flag: uint(tp.Flag), | ||
Charset: tp.Charset, | ||
Flen: int(tp.Flen), | ||
}}, nil | ||
} | ||
|
||
func convertFloat(val []byte, f32 bool) (*Constant, error) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1180,7 +1180,7 @@ func (s *testIntegrationSuite2) TestStringBuiltin(c *C) { | |
|
||
// for insert | ||
result = tk.MustQuery(`select insert("中文", 1, 1, cast("aaa" as binary)), insert("ba", -1, 1, "aaa"), insert("ba", 1, 100, "aaa"), insert("ba", 100, 1, "aaa");`) | ||
result.Check(testkit.Rows("aaa文 ba aaa ba")) | ||
result.Check(testkit.Rows("aaa\xb8\xad文 ba aaa ba")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is compatible with mysql version before 8.0.24. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change happened? Because of implicit cast? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, before 8.0.24, MySQL uses 1st and 4th arguments to determine the resulting charset, after it, only uses 1st argument. in this case, the resulting charset will be |
||
result = tk.MustQuery(`select insert("bb", NULL, 1, "aa"), insert("bb", 1, NULL, "aa"), insert(NULL, 1, 1, "aaa"), insert("bb", 1, 1, NULL);`) | ||
result.Check(testkit.Rows("<nil> <nil> <nil> <nil>")) | ||
result = tk.MustQuery(`SELECT INSERT("bb", 0, 1, NULL), INSERT("bb", 0, NULL, "aaa");`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can move
types.IsBinaryStr(c.GetType())
to the beginning of this loop to avoid unnecessaryEvalString
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xiongjiwei Please address this comment.