Skip to content

Commit

Permalink
executor: add a test case for 'tidb_constraint_check_in_place' on tem…
Browse files Browse the repository at this point in the history
…porary table (pingcap#24784)
  • Loading branch information
tiancaiamao authored May 21, 2021
1 parent 163eb5f commit 49f614e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2860,6 +2860,37 @@ func (s *testSuite7) TestDeferConstraintCheckForInsert(c *C) {
tk.MustExec("insert into t values (1, 3)")
_, err = tk.Exec("commit")
c.Assert(err, NotNil)

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

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

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

func (s *testSuite7) TestPessimisticDeleteYourWrites(c *C) {
Expand Down

0 comments on commit 49f614e

Please sign in to comment.