Skip to content
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

*: replace compareDatum by compare and fix wrong optimize order by #30273

Merged
merged 8 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4897,3 +4897,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 @@ -2175,7 +2175,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 @@ -2357,7 +2358,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 @@ -490,7 +490,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