Skip to content

Commit

Permalink
executor: Add tests for tidb_constraint_check_in_place for local te…
Browse files Browse the repository at this point in the history
…mporary table (pingcap#27271)
  • Loading branch information
lcwangchao authored Aug 17, 2021
1 parent 4a3c290 commit 156b438
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2863,6 +2863,7 @@ func (s *testSuite7) TestDeferConstraintCheckForInsert(c *C) {

// Cover the temporary table.
tk.MustExec("set tidb_enable_global_temporary_table=true")
tk.MustExec("set tidb_enable_noop_functions=true")
for val := range []int{0, 1} {
tk.MustExec("set tidb_constraint_check_in_place = ?", val)

Expand Down Expand Up @@ -2891,6 +2892,53 @@ func (s *testSuite7) TestDeferConstraintCheckForInsert(c *C) {
_, err = tk.Exec("insert into t values (3, 1) on duplicated key update b = b + 1")
c.Assert(err, NotNil)
tk.MustExec("commit")

// cases for temporary table
tk.MustExec("drop table if exists tl")
tk.MustExec("create temporary table tl (a int primary key, b int)")
tk.MustExec("begin")
tk.MustExec("insert into tl values (1, 1)")
_, err = tk.Exec(`insert into tl values (1, 3)`)
c.Assert(err, NotNil)
tk.MustExec("insert into tl values (2, 2)")
_, err = tk.Exec("update tl set a = a + 1 where a = 1")
c.Assert(err, NotNil)
_, err = tk.Exec("insert into tl values (1, 3) on duplicated key update a = a + 1")
c.Assert(err, NotNil)
tk.MustExec("commit")

tk.MustExec("begin")
tk.MustQuery("select * from tl").Check(testkit.Rows("1 1", "2 2"))
_, err = tk.Exec(`insert into tl values (1, 3)`)
c.Assert(err, NotNil)
_, err = tk.Exec("update tl set a = a + 1 where a = 1")
c.Assert(err, NotNil)
_, err = tk.Exec("insert into tl values (1, 3) on duplicated key update a = a + 1")
c.Assert(err, NotNil)
tk.MustExec("rollback")

tk.MustExec("drop table tl")
tk.MustExec("create temporary table tl (a int, b int unique)")
tk.MustExec("begin")
tk.MustExec("insert into tl values (1, 1)")
_, err = tk.Exec(`insert into tl values (3, 1)`)
c.Assert(err, NotNil)
tk.MustExec("insert into tl values (2, 2)")
_, err = tk.Exec("update tl set b = b + 1 where a = 1")
c.Assert(err, NotNil)
_, err = tk.Exec("insert into tl values (3, 1) on duplicated key update b = b + 1")
c.Assert(err, NotNil)
tk.MustExec("commit")

tk.MustExec("begin")
tk.MustQuery("select * from tl").Check(testkit.Rows("1 1", "2 2"))
_, err = tk.Exec(`insert into tl values (3, 1)`)
c.Assert(err, NotNil)
_, err = tk.Exec("update tl set b = b + 1 where a = 1")
c.Assert(err, NotNil)
_, err = tk.Exec("insert into tl values (3, 1) on duplicated key update b = b + 1")
c.Assert(err, NotNil)
tk.MustExec("rollback")
}
}

Expand Down

0 comments on commit 156b438

Please sign in to comment.