From fe0b65351cae66936f43f306d4a7ec371ed266d5 Mon Sep 17 00:00:00 2001 From: Evan Zhou Date: Tue, 28 Jul 2020 09:35:38 +0800 Subject: [PATCH] store/tikv: fix BatchPointGetCache wrong result. --- executor/batch_point_get_test.go | 11 +++++++++++ store/tikv/snapshot.go | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/executor/batch_point_get_test.go b/executor/batch_point_get_test.go index cd53b8093b523..4429c400ee8d2 100644 --- a/executor/batch_point_get_test.go +++ b/executor/batch_point_get_test.go @@ -127,3 +127,14 @@ func (s *testBatchPointGetSuite) TestBatchPointGetInTxn(c *C) { tk.MustQuery("select * from s where (a, b) in ((1, 1), (2, 2), (3, 3)) for update").Check(testkit.Rows("1 1 1", "3 3 10")) tk.MustExec("rollback") } + +func (s *testBatchPointGetSuite) TestBatchPointGetCache(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("create table customers (id int primary key, token varchar(255) unique)") + tk.MustExec("INSERT INTO test.customers (id, token) VALUES (28, '07j')") + tk.MustExec("INSERT INTO test.customers (id, token) VALUES (29, '03j')") + tk.MustExec("BEGIN") + 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")) +} diff --git a/store/tikv/snapshot.go b/store/tikv/snapshot.go index 5ac5c471d29c2..7f58155d2223a 100644 --- a/store/tikv/snapshot.go +++ b/store/tikv/snapshot.go @@ -108,7 +108,7 @@ func (s *tikvSnapshot) BatchGet(ctx context.Context, keys []kv.Key) (map[string] m := make(map[string][]byte) s.mu.RLock() if s.mu.cached != nil { - tmp := keys[:0] + tmp := make([]kv.Key, 0, len(keys)) for _, key := range keys { if val, ok := s.mu.cached[string(key)]; ok { atomic.AddInt64(&s.mu.hitCnt, 1)