Skip to content

Commit

Permalink
ddl: add virtual columns compatibility for temporary table (#25065)
Browse files Browse the repository at this point in the history
  • Loading branch information
Howie59 authored Jun 4, 2021
1 parent 5ca65a8 commit 4457ba8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3514,6 +3514,37 @@ out:
tk.MustExec("drop table tnn")
}

func (s *testDBSuite3) TestVirtualColumnDDL(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set tidb_enable_global_temporary_table=true")
tk.MustExec("use test")
tk.MustExec("drop table if exists test_gv_ddl")
tk.MustExec(`create global temporary table test_gv_ddl(a int, b int as (a+8) virtual, c int as (b + 2) stored) on commit delete rows;`)
defer tk.MustExec("drop table if exists test_gv_ddl")
is := tk.Se.(sessionctx.Context).GetInfoSchema().(infoschema.InfoSchema)
table, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("test_gv_ddl"))
c.Assert(err, IsNil)
testCases := []struct {
generatedExprString string
generatedStored bool
}{
{"", false},
{"`a` + 8", false},
{"`b` + 2", true},
}
for i, column := range table.Meta().Columns {
c.Assert(column.GeneratedExprString, Equals, testCases[i].generatedExprString)
c.Assert(column.GeneratedStored, Equals, testCases[i].generatedStored)
}
result := tk.MustQuery(`DESC test_gv_ddl`)
result.Check(testkit.Rows(`a int(11) YES <nil> `, `b int(11) YES <nil> VIRTUAL GENERATED`, `c int(11) YES <nil> STORED GENERATED`))
tk.MustExec("begin;")
tk.MustExec("insert into test_gv_ddl values (1, default, default)")
tk.MustQuery("select * from test_gv_ddl").Check(testkit.Rows("1 9 11"))
_, err = tk.Exec("commit")
c.Assert(err, IsNil)
}

func (s *testDBSuite3) TestGeneratedColumnDDL(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down

0 comments on commit 4457ba8

Please sign in to comment.