-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
Copy pathbatch_point_get_test.go
129 lines (116 loc) · 4 KB
/
batch_point_get_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package executor_test
import (
. "github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/util/testkit"
)
type testBatchPointGetSuite struct {
store kv.Storage
dom *domain.Domain
}
func newStoreWithBootstrap() (kv.Storage, *domain.Domain, error) {
store, err := mockstore.NewMockTikvStore()
if err != nil {
return nil, nil, errors.Trace(err)
}
session.SetSchemaLease(0)
session.DisableStats4Test()
dom, err := session.BootstrapSession(store)
if err != nil {
return nil, nil, err
}
return store, dom, errors.Trace(err)
}
func (s *testBatchPointGetSuite) SetUpSuite(c *C) {
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
s.store = store
s.dom = dom
}
func (s *testBatchPointGetSuite) TearDownSuite(c *C) {
s.dom.Close()
s.store.Close()
}
func (s *testBatchPointGetSuite) TestBatchPointGetExec(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int primary key auto_increment not null, b int, c int, unique key idx_abc(a, b, c))")
tk.MustExec("insert into t values(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 5)")
tk.MustQuery("select * from t").Check(testkit.Rows(
"1 1 1",
"2 2 2",
"3 3 3",
"4 4 5",
))
tk.MustQuery("select a, b, c from t where (a, b, c) in ((1, 1, 1), (1, 1, 1), (1, 1, 1))").Check(testkit.Rows(
"1 1 1",
))
tk.MustQuery("select a, b, c from t where (a, b, c) in ((1, 1, 1), (2, 2, 2), (1, 1, 1))").Check(testkit.Rows(
"1 1 1",
"2 2 2",
))
tk.MustQuery("select a, b, c from t where (a, b, c) in ((1, 1, 1), (2, 2, 2), (100, 1, 1))").Check(testkit.Rows(
"1 1 1",
"2 2 2",
))
tk.MustQuery("select a, b, c from t where (a, b, c) in ((1, 1, 1), (2, 2, 2), (100, 1, 1), (4, 4, 5))").Check(testkit.Rows(
"1 1 1",
"2 2 2",
"4 4 5",
))
tk.MustQuery("select * from t where a in (1, 2, 4, 1, 2)").Check(testkit.Rows(
"1 1 1",
"2 2 2",
"4 4 5",
))
tk.MustQuery("select * from t where a in (1, 2, 4, 1, 2, 100)").Check(testkit.Rows(
"1 1 1",
"2 2 2",
"4 4 5",
))
tk.MustQuery("select a from t where a in (1, 2, 4, 1, 2, 100)").Check(testkit.Rows(
"1",
"2",
"4",
))
}
func (s *testBatchPointGetSuite) TestBatchPointGetInTxn(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (id int primary key auto_increment, name varchar(30))")
// Fix a bug that BatchPointGetExec doesn't consider membuffer data in a transaction.
tk.MustExec("begin")
tk.MustExec("insert into t values (4, 'name')")
tk.MustQuery("select * from t where id in (4)").Check(testkit.Rows("4 name"))
tk.MustQuery("select * from t where id in (4) for update").Check(testkit.Rows("4 name"))
tk.MustExec("rollback")
tk.MustExec("begin pessimistic")
tk.MustExec("insert into t values (4, 'name')")
tk.MustQuery("select * from t where id in (4)").Check(testkit.Rows("4 name"))
tk.MustQuery("select * from t where id in (4) for update").Check(testkit.Rows("4 name"))
tk.MustExec("rollback")
tk.MustExec("create table s (a int, b int, c int, primary key (a, b))")
tk.MustExec("insert s values (1, 1, 1), (3, 3, 3), (5, 5, 5)")
tk.MustExec("begin pessimistic")
tk.MustExec("update s set c = 10 where a = 3")
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")
}