Skip to content

Commit

Permalink
*: replace compareDatum by compare and fix wrong optimize order by (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 authored Dec 1, 2021
1 parent 0a92c4d commit 94be83b
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 @@ -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"))

}
5 changes: 3 additions & 2 deletions types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion types/datum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion util/ranger/detacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
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 @@ -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 {
Expand All @@ -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)
}
Expand Down

0 comments on commit 94be83b

Please sign in to comment.