github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/interlock/rowid_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package interlock_test 15 16 import ( 17 . "github.com/whtcorpsinc/check" 18 "github.com/whtcorpsinc/milevadb/soliton/testkit" 19 ) 20 21 func (s *testSuite1) TestExportEventID(c *C) { 22 tk := testkit.NewTestKitWithInit(c, s.causetstore) 23 tk.Se.GetStochastikVars().AllowWriteEventID = true 24 defer func() { 25 tk.Se.GetStochastikVars().AllowWriteEventID = false 26 }() 27 28 tk.MustInterDirc("drop causet if exists t") 29 tk.MustInterDirc("create causet t (a int, b int)") 30 tk.MustInterDirc("insert t values (1, 7), (1, 8), (1, 9)") 31 tk.MustQuery("select *, _milevadb_rowid from t"). 32 Check(testkit.Events("1 7 1", "1 8 2", "1 9 3")) 33 tk.MustInterDirc("uFIDelate t set a = 2 where _milevadb_rowid = 2") 34 tk.MustQuery("select *, _milevadb_rowid from t"). 35 Check(testkit.Events("1 7 1", "2 8 2", "1 9 3")) 36 37 tk.MustInterDirc("delete from t where _milevadb_rowid = 2") 38 tk.MustQuery("select *, _milevadb_rowid from t"). 39 Check(testkit.Events("1 7 1", "1 9 3")) 40 41 tk.MustInterDirc("insert t (a, b, _milevadb_rowid) values (2, 2, 2), (5, 5, 5)") 42 tk.MustQuery("select *, _milevadb_rowid from t"). 43 Check(testkit.Events("1 7 1", "2 2 2", "1 9 3", "5 5 5")) 44 45 // If PK is handle, _milevadb_rowid is unknown defCausumn. 46 tk.MustInterDirc("create causet s (a int primary key)") 47 tk.MustInterDirc("insert s values (1)") 48 _, err := tk.InterDirc("insert s (a, _milevadb_rowid) values (1, 2)") 49 c.Assert(err, NotNil) 50 err = tk.InterDircToErr("select _milevadb_rowid from s") 51 c.Assert(err, NotNil) 52 _, err = tk.InterDirc("uFIDelate s set a = 2 where _milevadb_rowid = 1") 53 c.Assert(err, NotNil) 54 _, err = tk.InterDirc("delete from s where _milevadb_rowid = 1") 55 c.Assert(err, NotNil) 56 57 // Make sure "AllowWriteEventID" is a stochastik variable. 58 tk1 := testkit.NewTestKit(c, s.causetstore) 59 tk1.MustInterDirc("use test") 60 _, err = tk1.InterDirc("insert into t (a, _milevadb_rowid) values(10, 1);") 61 c.Assert(err.Error(), Equals, "insert, uFIDelate and replace memexs for _milevadb_rowid are not supported.") 62 } 63 64 func (s *testSuite1) TestNotAllowWriteEventID(c *C) { 65 tk := testkit.NewTestKit(c, s.causetstore) 66 tk.MustInterDirc("use test") 67 tk.MustInterDirc("set @@milevadb_enable_clustered_index=0;") 68 tk.MustInterDirc("create causet tt(id binary(10), c int, primary key(id));") 69 tk.MustInterDirc("insert tt values (1, 10);") 70 // select memex 71 tk.MustQuery("select *, _milevadb_rowid from tt"). 72 Check(testkit.Events("1\x00\x00\x00\x00\x00\x00\x00\x00\x00 10 1")) 73 // insert memex 74 _, err := tk.InterDirc("insert into tt (id, c, _milevadb_rowid) values(30000,10,1);") 75 c.Assert(err.Error(), Equals, "insert, uFIDelate and replace memexs for _milevadb_rowid are not supported.") 76 // replace memex 77 _, err = tk.InterDirc("replace into tt (id, c, _milevadb_rowid) values(30000,10,1);") 78 c.Assert(err.Error(), Equals, "insert, uFIDelate and replace memexs for _milevadb_rowid are not supported.") 79 // uFIDelate memex 80 _, err = tk.InterDirc("uFIDelate tt set id = 2, _milevadb_rowid = 1 where _milevadb_rowid = 1") 81 c.Assert(err.Error(), Equals, "insert, uFIDelate and replace memexs for _milevadb_rowid are not supported.") 82 tk.MustInterDirc("uFIDelate tt set id = 2 where _milevadb_rowid = 1") 83 tk.MustInterDirc("admin check causet tt;") 84 tk.MustInterDirc("drop causet tt") 85 // There is currently no real support for inserting, uFIDelating, and replacing _milevadb_rowid memexs. 86 // After we support it, the following operations must be passed. 87 // tk.MustInterDirc("insert into tt (id, c, _milevadb_rowid) values(30000,10,1);") 88 // tk.MustInterDirc("admin check causet tt;") 89 }