Skip to content

Commit

Permalink
executor: add test case for memory cache in parition table (pingcap#2…
Browse files Browse the repository at this point in the history
…2291)

Signed-off-by: Shuaipeng Yu <[email protected]>
  • Loading branch information
jackysp authored Jan 8, 2021
1 parent 0a4ec0d commit 4071a72
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion executor/point_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ func (s *testSerialSuite) mustExecDDL(tk *testkit.TestKit, c *C, sql string) {
c.Assert(s.domain.Reload(), IsNil)
}

func (s *testSerialSuite) TestPointGetReadLock(c *C) {
func (s *testSerialSuite) TestMemCacheReadLock(c *C) {
defer config.RestoreFunc()()
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableTableLock = true
Expand All @@ -614,8 +614,10 @@ func (s *testSerialSuite) TestPointGetReadLock(c *C) {
tk.Se.GetSessionVars().EnablePointGetCache = true
defer func() {
tk.Se.GetSessionVars().EnablePointGetCache = false
tk.MustExec("drop table if exists point")
}()

tk.MustExec("drop table if exists point")
tk.MustExec("create table point (id int primary key, c int, d varchar(10), unique c_d (c, d))")
tk.MustExec("insert point values (1, 1, 'a')")
tk.MustExec("insert point values (2, 2, 'b')")
Expand Down Expand Up @@ -679,6 +681,47 @@ func (s *testSerialSuite) TestPointGetReadLock(c *C) {
}
}

func (s *testSerialSuite) TestPartitionMemCacheReadLock(c *C) {
defer config.RestoreFunc()()
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableTableLock = true
})
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

tk.Se.GetSessionVars().EnablePointGetCache = true
defer func() {
tk.Se.GetSessionVars().EnablePointGetCache = false
tk.MustExec("drop table if exists point")
}()

tk.MustExec("drop table if exists point")
tk.MustExec("create table point (id int unique key, c int, d varchar(10)) partition by hash (id) partitions 4")
tk.MustExec("insert point values (1, 1, 'a')")
tk.MustExec("insert point values (2, 2, 'b')")

// Confirm _tidb_rowid will not be duplicated.
tk.MustQuery("select distinct(_tidb_rowid) from point order by _tidb_rowid").Check(testkit.Rows("1", "2"))

s.mustExecDDL(tk, c, "lock tables point read")

tk.MustQuery("select _tidb_rowid from point where id = 1").Check(testkit.Rows("1"))
s.mustExecDDL(tk, c, "unlock tables")

tk.MustQuery("select _tidb_rowid from point where id = 1").Check(testkit.Rows("1"))
tk.MustExec("update point set id = -id")

// Test cache release after unlocking tables.
s.mustExecDDL(tk, c, "lock tables point read")
tk.MustQuery("select _tidb_rowid from point where id = 1").Check(testkit.Rows())

tk.MustQuery("select _tidb_rowid from point where id = -1").Check(testkit.Rows("1"))
tk.MustQuery("select _tidb_rowid from point where id = -1").Check(testkit.Rows("1"))
tk.MustQuery("select _tidb_rowid from point where id = -2").Check(testkit.Rows("2"))

s.mustExecDDL(tk, c, "unlock tables")
}

func (s *testPointGetSuite) TestPointGetWriteLock(c *C) {
defer config.RestoreFunc()()
config.UpdateGlobal(func(conf *config.Config) {
Expand Down

0 comments on commit 4071a72

Please sign in to comment.