Skip to content

Commit

Permalink
executor: insert, update and replace statements for _tidb_rowid are n…
Browse files Browse the repository at this point in the history
…ot support now.
  • Loading branch information
zimulala committed Oct 31, 2018
1 parent 0a37bd5 commit 0244bb2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
55 changes: 44 additions & 11 deletions executor/rowid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"github.com/pingcap/tidb/util/testkit"
)

/*
Insert, update and replace statements for _tidb_rowid are not support now.
After we support it, the following operations can be passed.
func (s *testSuite) TestExportRowID(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand All @@ -38,15 +41,45 @@ func (s *testSuite) TestExportRowID(c *C) {
tk.MustQuery("select *, _tidb_rowid from t").
Check(testkit.Rows("1 7 1", "2 2 2", "1 9 3", "5 5 5"))
// If PK is handle, _tidb_rowid is unknown column.
tk.MustExec("create table s (a int primary key)")
tk.MustExec("insert s values (1)")
_, err := tk.Exec("insert s (a, _tidb_rowid) values (1, 2)")
c.Assert(err, NotNil)
_, err = tk.Exec("select _tidb_rowid from s")
c.Assert(err, NotNil)
_, err = tk.Exec("update s set a = 2 where _tidb_rowid = 1")
c.Assert(err, NotNil)
_, err = tk.Exec("delete from s where _tidb_rowid = 1")
c.Assert(err, NotNil)
// If PK is handle, _tidb_rowid is unknown column.
tk.MustExec("create table s (a int primary key)")
tk.MustExec("insert s values (1)")
_, err := tk.Exec("insert s (a, _tidb_rowid) values (1, 2)")
c.Assert(err, NotNil)
_, err = tk.Exec("select _tidb_rowid from s")
c.Assert(err, NotNil)
_, err = tk.Exec("update s set a = 2 where _tidb_rowid = 1")
c.Assert(err, NotNil)
_, err = tk.Exec("delete from s where _tidb_rowid = 1")
c.Assert(err, NotNil)
}
*/

func (s *testSuite) TestRowID(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table tt(id binary(10), c int, primary key(id));")
tk.MustExec("insert tt values (1, 10);")

// select statement
tk.MustQuery("select *, _tidb_rowid from tt").
Check(testkit.Rows("1\x00\x00\x00\x00\x00\x00\x00\x00\x00 10 1"))
// insert statement
_, err := tk.Exec("insert into tt (id, c, _tidb_rowid) values(30000,10,1);")
c.Assert(err.Error(), Equals, "insert, update and replace statements for _tidb_rowid are not support.")
// replace statement
_, err = tk.Exec("replace into tt (id, c, _tidb_rowid) values(30000,10,1);")
c.Assert(err.Error(), Equals, "insert, update and replace statements for _tidb_rowid are not support.")
// update statement
_, err = tk.Exec("update tt set id = 2, _tidb_rowid = 1 where _tidb_rowid = 1")
c.Assert(err.Error(), Equals, "insert, update and replace statements for _tidb_rowid are not support.")
tk.MustExec("update tt set id = 2 where _tidb_rowid = 1")

tk.MustExec("admin check table tt;")
tk.MustExec("drop table tt")

// Insert, update and replace statements for _tidb_rowid are not support now.
// After we support it, the following operations must be passed.
// tk.MustExec("insert into tt (id, c, _tidb_rowid) values(30000,10,1);")
// tk.MustExec("admin check table tt;")
}
5 changes: 4 additions & 1 deletion executor/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ func (e *InsertValues) getColumns(tableCols []*table.Column) ([]*table.Column, e
for _, col := range cols {
if col.Name.L == model.ExtraHandleName.L {
e.hasExtraHandle = true
break
return nil, errors.Errorf("insert, update and replace statements for _tidb_rowid are not support.")
}
}

Expand Down Expand Up @@ -1998,6 +1998,9 @@ func (e *UpdateExec) Next(ctx context.Context, chk *chunk.Chunk) error {
func getUpdateColumns(assignList []*expression.Assignment, schemaLen int) ([]bool, error) {
assignFlag := make([]bool, schemaLen)
for _, v := range assignList {
if v.Col.ColName.L == model.ExtraHandleName.L {
return nil, errors.Errorf("insert, update and replace statements for _tidb_rowid are not support.")
}
idx := v.Col.Index
assignFlag[idx] = true
}
Expand Down

0 comments on commit 0244bb2

Please sign in to comment.