From fc5bb13f855ef79f59cf11def8de9f4a8f3e970f Mon Sep 17 00:00:00 2001 From: lysu Date: Thu, 24 Sep 2020 22:00:08 +0800 Subject: [PATCH 1/2] cherry pick #20108 to release-4.0 Signed-off-by: ti-srebot --- executor/batch_point_get.go | 33 +++++++++++++++++++++++++++++++- executor/batch_point_get_test.go | 27 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/executor/batch_point_get.go b/executor/batch_point_get.go index 50329caec87ed..71f0c23c36e86 100644 --- a/executor/batch_point_get.go +++ b/executor/batch_point_get.go @@ -15,10 +15,12 @@ package executor import ( "context" + "fmt" "sort" "github.com/pingcap/failpoint" "github.com/pingcap/parser/model" + "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/store/tikv" @@ -231,12 +233,41 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error { failpoint.InjectContext(ctx, "batchPointGetRepeatableReadTest-step2", nil) }) } else if e.keepOrder { - sort.Slice(e.handles, func(i int, j int) bool { + less := func(i int, j int) bool { if e.desc { return e.handles[i] > e.handles[j] } +<<<<<<< HEAD return e.handles[i] < e.handles[j] }) +======= + return e.handles[i].Compare(e.handles[j]) < 0 + + } + if e.tblInfo.PKIsHandle && mysql.HasUnsignedFlag(e.tblInfo.GetPkColInfo().Flag) { + uintComparator := func(i, h kv.Handle) int { + if !i.IsInt() || !h.IsInt() { + panic(fmt.Sprintf("both handles need be IntHandle, but got %T and %T ", i, h)) + } + ihVal := uint64(i.IntValue()) + hVal := uint64(h.IntValue()) + if ihVal > hVal { + return 1 + } + if ihVal < hVal { + return -1 + } + return 0 + } + less = func(i int, j int) bool { + if e.desc { + return uintComparator(e.handles[i], e.handles[j]) > 0 + } + return uintComparator(e.handles[i], e.handles[j]) < 0 + } + } + sort.Slice(e.handles, less) +>>>>>>> 10fd83446... executor: fix sort result for batch-point-get by unsigned pk (#20108) } keys := make([]kv.Key, len(e.handles)) diff --git a/executor/batch_point_get_test.go b/executor/batch_point_get_test.go index 732c45ee2fc3f..4d21f89046d4d 100644 --- a/executor/batch_point_get_test.go +++ b/executor/batch_point_get_test.go @@ -138,3 +138,30 @@ func (s *testBatchPointGetSuite) TestBatchPointGetCache(c *C) { tk.MustQuery("SELECT id, token FROM test.customers WHERE id IN (28)") tk.MustQuery("SELECT id, token FROM test.customers WHERE id IN (28, 29);").Check(testkit.Rows("28 07j", "29 03j")) } +<<<<<<< HEAD +======= + +func (s *testBatchPointGetSuite) TestIssue18843(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("create table t18843 ( id bigint(10) primary key, f varchar(191) default null, unique key `idx_f` (`f`))") + tk.MustExec("insert into t18843 values (1, '')") + tk.MustQuery("select * from t18843 where f in (null)").Check(testkit.Rows()) + + tk.MustExec("insert into t18843 values (2, null)") + tk.MustQuery("select * from t18843 where f in (null)").Check(testkit.Rows()) + tk.MustQuery("select * from t18843 where f is null").Check(testkit.Rows("2 ")) +} + +func (s *testBatchPointGetSuite) TestBatchPointGetUnsignedHandleWithSort(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t2") + tk.MustExec("create table t2 (id bigint(20) unsigned, primary key(id))") + tk.MustExec("insert into t2 values (8738875760185212610)") + tk.MustExec("insert into t2 values (9814441339970117597)") + tk.MustExec("insert into t2 values (1)") + tk.MustQuery("select id from t2 where id in (8738875760185212610, 1, 9814441339970117597) order by id").Check(testkit.Rows("1", "8738875760185212610", "9814441339970117597")) + tk.MustQuery("select id from t2 where id in (8738875760185212610, 1, 9814441339970117597) order by id desc").Check(testkit.Rows("9814441339970117597", "8738875760185212610", "1")) +} +>>>>>>> 10fd83446... executor: fix sort result for batch-point-get by unsigned pk (#20108) From 5aad18b29232284c14b806cee6995faea0b0506b Mon Sep 17 00:00:00 2001 From: lysu Date: Fri, 25 Sep 2020 13:01:31 +0800 Subject: [PATCH 2/2] resolve conflict --- executor/batch_point_get.go | 25 ++----------------------- executor/batch_point_get_test.go | 15 --------------- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/executor/batch_point_get.go b/executor/batch_point_get.go index 71f0c23c36e86..b2b8ff82a9594 100644 --- a/executor/batch_point_get.go +++ b/executor/batch_point_get.go @@ -15,7 +15,6 @@ package executor import ( "context" - "fmt" "sort" "github.com/pingcap/failpoint" @@ -237,37 +236,17 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error { if e.desc { return e.handles[i] > e.handles[j] } -<<<<<<< HEAD return e.handles[i] < e.handles[j] - }) -======= - return e.handles[i].Compare(e.handles[j]) < 0 - } if e.tblInfo.PKIsHandle && mysql.HasUnsignedFlag(e.tblInfo.GetPkColInfo().Flag) { - uintComparator := func(i, h kv.Handle) int { - if !i.IsInt() || !h.IsInt() { - panic(fmt.Sprintf("both handles need be IntHandle, but got %T and %T ", i, h)) - } - ihVal := uint64(i.IntValue()) - hVal := uint64(h.IntValue()) - if ihVal > hVal { - return 1 - } - if ihVal < hVal { - return -1 - } - return 0 - } less = func(i int, j int) bool { if e.desc { - return uintComparator(e.handles[i], e.handles[j]) > 0 + return uint64(e.handles[i]) > uint64(e.handles[j]) } - return uintComparator(e.handles[i], e.handles[j]) < 0 + return uint64(e.handles[i]) < uint64(e.handles[j]) } } sort.Slice(e.handles, less) ->>>>>>> 10fd83446... executor: fix sort result for batch-point-get by unsigned pk (#20108) } keys := make([]kv.Key, len(e.handles)) diff --git a/executor/batch_point_get_test.go b/executor/batch_point_get_test.go index 4d21f89046d4d..e53c608647052 100644 --- a/executor/batch_point_get_test.go +++ b/executor/batch_point_get_test.go @@ -138,20 +138,6 @@ func (s *testBatchPointGetSuite) TestBatchPointGetCache(c *C) { tk.MustQuery("SELECT id, token FROM test.customers WHERE id IN (28)") tk.MustQuery("SELECT id, token FROM test.customers WHERE id IN (28, 29);").Check(testkit.Rows("28 07j", "29 03j")) } -<<<<<<< HEAD -======= - -func (s *testBatchPointGetSuite) TestIssue18843(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("create table t18843 ( id bigint(10) primary key, f varchar(191) default null, unique key `idx_f` (`f`))") - tk.MustExec("insert into t18843 values (1, '')") - tk.MustQuery("select * from t18843 where f in (null)").Check(testkit.Rows()) - - tk.MustExec("insert into t18843 values (2, null)") - tk.MustQuery("select * from t18843 where f in (null)").Check(testkit.Rows()) - tk.MustQuery("select * from t18843 where f is null").Check(testkit.Rows("2 ")) -} func (s *testBatchPointGetSuite) TestBatchPointGetUnsignedHandleWithSort(c *C) { tk := testkit.NewTestKit(c, s.store) @@ -164,4 +150,3 @@ func (s *testBatchPointGetSuite) TestBatchPointGetUnsignedHandleWithSort(c *C) { tk.MustQuery("select id from t2 where id in (8738875760185212610, 1, 9814441339970117597) order by id").Check(testkit.Rows("1", "8738875760185212610", "9814441339970117597")) tk.MustQuery("select id from t2 where id in (8738875760185212610, 1, 9814441339970117597) order by id desc").Check(testkit.Rows("9814441339970117597", "8738875760185212610", "1")) } ->>>>>>> 10fd83446... executor: fix sort result for batch-point-get by unsigned pk (#20108)