Skip to content

Commit

Permalink
cherry pick pingcap#30273 to release-5.3
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
wjhuang2016 authored and ti-srebot committed Feb 14, 2022
1 parent 83b273a commit b4fa9fa
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
13 changes: 13 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4786,3 +4786,16 @@ func (s *testIntegrationSuite) TestIssues29711(c *C) {
))

}

func (s *testIntegrationSerialSuite) TestIssue30271(c *C) {
defer collate.SetNewCollationEnabledForTest(false)
collate.SetNewCollationEnabledForTest(true)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a char(10), b char(10), c char(10), index (a, b, c)) collate utf8mb4_bin;")
tk.MustExec("insert into t values ('b', 'a', '1'), ('b', 'A', '2'), ('c', 'a', '3');")
tk.MustExec("set names utf8mb4 collate utf8mb4_general_ci;")
tk.MustQuery("select * from t where (a>'a' and b='a') or (b = 'A' and a < 'd') order by a,c;").Check(testkit.Rows("b a 1", "b A 2", "c a 3"))

}
5 changes: 3 additions & 2 deletions types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,8 @@ func (ds *datumsSorter) Len() int {
}

func (ds *datumsSorter) Less(i, j int) bool {
cmp, err := ds.datums[i].CompareDatum(ds.sc, &ds.datums[j])
// TODO: set collation explicitly when rewrites feedback.
cmp, err := ds.datums[i].Compare(ds.sc, &ds.datums[j], collate.GetCollator(ds.datums[i].Collation()))
if err != nil {
ds.err = errors.Trace(err)
return true
Expand Down Expand Up @@ -2215,7 +2216,7 @@ func ChangeReverseResultByUpperLowerBound(
resRetType.Decimal = int(res.GetMysqlDecimal().GetDigitsInt())
}
bound := getDatumBound(&resRetType, rType)
cmp, err := d.CompareDatum(sc, &bound)
cmp, err := d.Compare(sc, &bound, collate.GetCollator(resRetType.Collate))
if err != nil {
return d, err
}
Expand Down
2 changes: 1 addition & 1 deletion types/datum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func TestChangeReverseResultByUpperLowerBound(t *testing.T) {
reverseRes, err := ChangeReverseResultByUpperLowerBound(sc, test.retType, test.a, test.roundType)
require.NoError(t, err)
var cmp int
cmp, err = reverseRes.CompareDatum(sc, &test.res)
cmp, err = reverseRes.Compare(sc, &test.res, collate.GetBinaryCollator())
require.NoError(t, err)
require.Equalf(t, 0, cmp, "%dth got:%#v, expect:%#v", ith, reverseRes, test.res)
}
Expand Down
3 changes: 2 additions & 1 deletion util/ranger/detacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ func isSameValue(sc *stmtctx.StatementContext, lhs, rhs *valueInfo) (bool, error
if lhs == nil || rhs == nil || lhs.mutable || rhs.mutable || lhs.value.Kind() != rhs.value.Kind() {
return false, nil
}
cmp, err := lhs.value.CompareDatum(sc, rhs.value)
// binary collator may not the best choice, but it can make sure the result is correct.
cmp, err := lhs.value.Compare(sc, rhs.value, collate.GetBinaryCollator())
if err != nil {
return false, err
}
Expand Down
4 changes: 2 additions & 2 deletions util/rowDecoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestRowDecoder(t *testing.T) {
for i, col := range cols[:len(cols)-1] {
v, ok := r[col.ID]
if ok {
equal, err1 := v.CompareDatum(sc, &row.output[i])
equal, err1 := v.Compare(sc, &row.output[i], collate.GetBinaryCollator())
require.Nil(t, err1)
require.Equal(t, 0, equal)
} else {
Expand All @@ -143,7 +143,7 @@ func TestRowDecoder(t *testing.T) {
for k, v := range r2 {
v1, ok := r[k]
require.True(t, ok)
equal, err1 := v.CompareDatum(sc, &v1)
equal, err1 := v.Compare(sc, &v1, collate.GetBinaryCollator())
require.Nil(t, err1)
require.Equal(t, 0, equal)
}
Expand Down

0 comments on commit b4fa9fa

Please sign in to comment.