diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 1bd3153d0568e..90cfb8932aabb 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -4947,3 +4947,16 @@ func (s *testIntegrationSuite) TestIssue30094(c *C) { " └─TableFullScan 10000.00 cop[tikv] table:t30094 keep order:false, stats:pseudo", )) } + +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")) + +} diff --git a/types/datum.go b/types/datum.go index efaef65675627..f81c3c7a94d14 100644 --- a/types/datum.go +++ b/types/datum.go @@ -2180,7 +2180,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 @@ -2362,7 +2363,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 } diff --git a/types/datum_test.go b/types/datum_test.go index 2a36f21d4cc7e..3fc00d94efca1 100644 --- a/types/datum_test.go +++ b/types/datum_test.go @@ -476,7 +476,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) } diff --git a/util/ranger/detacher.go b/util/ranger/detacher.go index e3d6dfc0fc6f8..7b422d10243cc 100644 --- a/util/ranger/detacher.go +++ b/util/ranger/detacher.go @@ -715,7 +715,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 } diff --git a/util/rowDecoder/decoder_test.go b/util/rowDecoder/decoder_test.go index cb743418d1692..26abf03eb6e95 100644 --- a/util/rowDecoder/decoder_test.go +++ b/util/rowDecoder/decoder_test.go @@ -130,7 +130,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 { @@ -144,7 +144,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) }