Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: update mysql-tester, enable table-lock in integrationtest #48956

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 0 additions & 108 deletions pkg/ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1817,8 +1817,6 @@ func TestParserIssue284(t *testing.T) {

func TestAddExpressionIndex(t *testing.T) {
config.UpdateGlobal(func(conf *config.Config) {
// Test for table lock.
conf.EnableTableLock = true
zimulala marked this conversation as resolved.
Show resolved Hide resolved
conf.Instance.SlowThreshold = 10000
conf.TiKVClient.AsyncCommit.SafeWindow = 0
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0
Expand Down Expand Up @@ -1897,60 +1895,6 @@ func TestAddExpressionIndex(t *testing.T) {
})
}

func TestCreateExpressionIndexError(t *testing.T) {
config.UpdateGlobal(func(conf *config.Config) {
// Test for table lock.
conf.EnableTableLock = true
conf.Instance.SlowThreshold = 10000
conf.TiKVClient.AsyncCommit.SafeWindow = 0
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0
conf.Experimental.AllowsExpressionIndex = true
})
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a int, b real);")
tk.MustGetErrCode("alter table t add primary key ((a+b)) nonclustered;", errno.ErrFunctionalIndexPrimaryKey)

tk.MustGetErrCode("create table t(a int, index((cast(a as JSON))))", errno.ErrFunctionalIndexOnJSONOrGeometryFunction)

// Test for error
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a int, b real);")
tk.MustGetErrCode("alter table t add primary key ((a+b)) nonclustered;", errno.ErrFunctionalIndexPrimaryKey)
tk.MustGetErrCode("alter table t add index ((rand()));", errno.ErrFunctionalIndexFunctionIsNotAllowed)
tk.MustGetErrCode("alter table t add index ((now()+1));", errno.ErrFunctionalIndexFunctionIsNotAllowed)

tk.MustExec("alter table t add column (_V$_idx_0 int);")
tk.MustGetErrCode("alter table t add index idx((a+1));", errno.ErrDupFieldName)
tk.MustExec("alter table t drop column _V$_idx_0;")
tk.MustExec("alter table t add index idx((a+1));")
tk.MustGetErrCode("alter table t add column (_V$_idx_0 int);", errno.ErrDupFieldName)
tk.MustExec("alter table t drop index idx;")
tk.MustExec("alter table t add column (_V$_idx_0 int);")

tk.MustExec("alter table t add column (_V$_expression_index_0 int);")
tk.MustGetErrCode("alter table t add index ((a+1));", errno.ErrDupFieldName)
tk.MustExec("alter table t drop column _V$_expression_index_0;")
tk.MustExec("alter table t add index ((a+1));")
tk.MustGetErrCode("alter table t drop column _V$_expression_index_0;", errno.ErrCantDropFieldOrKey)
tk.MustGetErrCode("alter table t add column e int as (_V$_expression_index_0 + 1);", errno.ErrBadField)

// NOTE (#18150): In creating expression index, row value is not allowed.
tk.MustExec("drop table if exists t;")
tk.MustGetErrCode("create table t (j json, key k (((j,j))))", errno.ErrFunctionalIndexRowValueIsNotAllowed)
tk.MustExec("create table t (j json, key k ((j+1),(j+1)))")

tk.MustGetErrCode("create table t1 (col1 int, index ((concat(''))));", errno.ErrWrongKeyColumnFunctionalIndex)
tk.MustGetErrCode("CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED);", errno.ErrFunctionalIndexPrimaryKey)

// For issue 26349
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t(id char(10) primary key, short_name char(10), name char(10), key n((upper(`name`))));")
tk.MustExec("update t t1 set t1.short_name='a' where t1.id='1';")
}

func queryIndexOnTable(dbName, tableName string) string {
return fmt.Sprintf("select distinct index_name, is_visible from information_schema.statistics where table_schema = '%s' and table_name = '%s' order by index_name", dbName, tableName)
}
Expand Down Expand Up @@ -2349,20 +2293,6 @@ func TestEnumAndSetDefaultValue(t *testing.T) {
require.Equal(t, "a", tbl.Meta().Columns[1].DefaultValue)
}

func TestStrictDoubleTypeCheck(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set @@tidb_enable_strict_double_type_check = 'ON'")
sql := "create table double_type_check(id int, c double(10));"
_, err := tk.Exec(sql)
require.Error(t, err)
require.Equal(t, "[parser:1149]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use", err.Error())
tk.MustExec("set @@tidb_enable_strict_double_type_check = 'OFF'")
defer tk.MustExec("set @@tidb_enable_strict_double_type_check = 'ON'")
tk.MustExec(sql)
}

func TestDuplicateErrorMessage(t *testing.T) {
defer collate.SetNewCollationEnabledForTest(true)
store := testkit.CreateMockStore(t)
Expand Down Expand Up @@ -2669,8 +2599,6 @@ func TestAvoidCreateViewOnLocalTemporaryTable(t *testing.T) {

func TestDropTemporaryTable(t *testing.T) {
config.UpdateGlobal(func(conf *config.Config) {
// Test for table lock.
conf.EnableTableLock = true
conf.Instance.SlowThreshold = 10000
conf.TiKVClient.AsyncCommit.SafeWindow = 0
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0
Expand Down Expand Up @@ -2936,42 +2864,6 @@ func TestIssue29282(t *testing.T) {
}
}

// See https://github.com/pingcap/tidb/issues/35644
func TestCreateTempTableInTxn(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("begin")
// new created temporary table should be visible
tk.MustExec("create temporary table t1(id int primary key, v int)")
tk.MustQuery("select * from t1").Check(testkit.Rows())
// new inserted data should be visible
tk.MustExec("insert into t1 values(123, 456)")
tk.MustQuery("select * from t1 where id=123").Check(testkit.Rows("123 456"))
// truncate table will clear data but table still visible
tk.MustExec("truncate table t1")
tk.MustQuery("select * from t1 where id=123").Check(testkit.Rows())
tk.MustExec("commit")

tk1 := testkit.NewTestKit(t, store)
tk1.MustExec("use test")
tk1.MustExec("create table tt(id int)")
tk1.MustExec("begin")
tk1.MustExec("create temporary table t1(id int)")
tk1.MustExec("insert into tt select * from t1")
tk1.MustExec("drop table tt")

tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("use test")
tk2.MustExec("create table t2(id int primary key, v int)")
tk2.MustExec("insert into t2 values(234, 567)")
tk2.MustExec("begin")
// create a new temporary table with the same name will override physical table
tk2.MustExec("create temporary table t2(id int primary key, v int)")
tk2.MustQuery("select * from t2 where id=234").Check(testkit.Rows())
tk2.MustExec("commit")
}

// See https://github.com/pingcap/tidb/issues/29327
func TestEnumDefaultValue(t *testing.T) {
store := testkit.CreateMockStore(t, mockstore.WithDDLChecker())
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/tests/partition/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_test(
"main_test.go",
],
flaky = True,
shard_count = 48,
shard_count = 47,
deps = [
"//pkg/config",
"//pkg/ddl",
Expand Down
51 changes: 0 additions & 51 deletions pkg/ddl/tests/partition/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2454,49 +2454,6 @@ func TestExchangePartitionAutoID(t *testing.T) {
tk.MustQuery("select count(*) from pt where a >= 4000000").Check(testkit.Rows("1"))
}

func TestExchangePartitionExpressIndex(t *testing.T) {
restore := config.RestoreFunc()
defer restore()
config.UpdateGlobal(func(conf *config.Config) {
// Test for table lock.
conf.EnableTableLock = true
conf.Instance.SlowThreshold = 10000
conf.TiKVClient.AsyncCommit.SafeWindow = 0
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0
conf.Experimental.AllowsExpressionIndex = true
})
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set @@tidb_enable_exchange_partition=1")
defer tk.MustExec("set @@tidb_enable_exchange_partition=0")
tk.MustExec("drop table if exists pt1;")
tk.MustExec("create table pt1(a int, b int, c int) PARTITION BY hash (a) partitions 1;")
tk.MustExec("alter table pt1 add index idx((a+c));")

tk.MustExec("drop table if exists nt1;")
tk.MustExec("create table nt1(a int, b int, c int);")
tk.MustGetErrCode("alter table pt1 exchange partition p0 with table nt1;", errno.ErrTablesDifferentMetadata)

tk.MustExec("alter table nt1 add column (`_V$_idx_0` bigint(20) generated always as (a+b) virtual);")
tk.MustGetErrCode("alter table pt1 exchange partition p0 with table nt1;", errno.ErrTablesDifferentMetadata)

// test different expression index when expression returns same field type
tk.MustExec("alter table nt1 drop column `_V$_idx_0`;")
tk.MustExec("alter table nt1 add index idx((b-c));")
tk.MustGetErrCode("alter table pt1 exchange partition p0 with table nt1;", errno.ErrTablesDifferentMetadata)

// test different expression index when expression returns different field type
tk.MustExec("alter table nt1 drop index idx;")
tk.MustExec("alter table nt1 add index idx((concat(a, b)));")
tk.MustGetErrCode("alter table pt1 exchange partition p0 with table nt1;", errno.ErrTablesDifferentMetadata)

tk.MustExec("drop table if exists nt2;")
tk.MustExec("create table nt2 (a int, b int, c int)")
tk.MustExec("alter table nt2 add index idx((a+c))")
tk.MustExec("alter table pt1 exchange partition p0 with table nt2")
}

func TestAddPartitionTooManyPartitions(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -3036,14 +2993,6 @@ func TestPartitionErrorCode(t *testing.T) {
}

func TestCommitWhenSchemaChange(t *testing.T) {
restore := config.RestoreFunc()
defer restore()
config.UpdateGlobal(func(conf *config.Config) {
// Test for table lock.
conf.EnableTableLock = true
conf.Instance.SlowThreshold = 10000
conf.Experimental.AllowsExpressionIndex = true
})
store := testkit.CreateMockStoreWithSchemaLease(t, time.Second)
tk := testkit.NewTestKit(t, store)
tk.MustExec("set global tidb_enable_metadata_lock=0")
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/tests/serial/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_test(
"serial_test.go",
],
flaky = True,
shard_count = 20,
shard_count = 19,
deps = [
"//pkg/config",
"//pkg/ddl",
Expand Down
21 changes: 2 additions & 19 deletions pkg/ddl/tests/serial/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,13 +846,13 @@ func TestCanceledJobTakeTime(t *testing.T) {
require.Less(t, sub, ddl.GetWaitTimeWhenErrorOccurred())
}

func TestTableLocksEnable(t *testing.T) {
func TestTableLocksDisable(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t1 (a int)")

// Test for enable table lock config.
// Test for disable table lock config.
defer config.RestoreFunc()()
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableTableLock = false
Expand Down Expand Up @@ -1285,20 +1285,3 @@ func TestGetReverseKey(t *testing.T) {
endKey = maxKey.Next()
checkRet(startKey, endKey, endKey)
}

func TestLocalTemporaryTableBlockedDDL(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t1 (id int)")
tk.MustExec("create temporary table tmp1 (id int primary key, a int unique, b int)")
require.ErrorIs(t, tk.ExecToErr("rename table tmp1 to tmp2"), dbterror.ErrUnsupportedLocalTempTableDDL)
require.ErrorIs(t, tk.ExecToErr("alter table tmp1 add column c int"), dbterror.ErrUnsupportedLocalTempTableDDL)
require.ErrorIs(t, tk.ExecToErr("alter table tmp1 add index b(b)"), dbterror.ErrUnsupportedLocalTempTableDDL)
require.ErrorIs(t, tk.ExecToErr("create index a on tmp1(b)"), dbterror.ErrUnsupportedLocalTempTableDDL)
require.ErrorIs(t, tk.ExecToErr("drop index a on tmp1"), dbterror.ErrUnsupportedLocalTempTableDDL)
require.ErrorIs(t, tk.ExecToErr("lock tables tmp1 read"), dbterror.ErrUnsupportedLocalTempTableDDL)
require.ErrorIs(t, tk.ExecToErr("lock tables tmp1 write"), dbterror.ErrUnsupportedLocalTempTableDDL)
require.ErrorIs(t, tk.ExecToErr("lock tables t1 read, tmp1 read"), dbterror.ErrUnsupportedLocalTempTableDDL)
require.ErrorIs(t, tk.ExecToErr("admin cleanup table lock tmp1"), dbterror.ErrUnsupportedLocalTempTableDDL)
}
3 changes: 1 addition & 2 deletions pkg/executor/test/executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_test(
"main_test.go",
],
flaky = True,
shard_count = 46,
shard_count = 45,
deps = [
"//pkg/config",
"//pkg/ddl",
Expand All @@ -21,7 +21,6 @@ go_test(
"//pkg/meta",
"//pkg/meta/autoid",
"//pkg/parser",
"//pkg/parser/auth",
"//pkg/parser/model",
"//pkg/parser/mysql",
"//pkg/parser/terror",
Expand Down
28 changes: 0 additions & 28 deletions pkg/executor/test/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/pingcap/tidb/pkg/meta"
"github.com/pingcap/tidb/pkg/meta/autoid"
"github.com/pingcap/tidb/pkg/parser"
"github.com/pingcap/tidb/pkg/parser/auth"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/parser/terror"
Expand Down Expand Up @@ -2576,33 +2575,6 @@ func TestIsFastPlan(t *testing.T) {
}
}

func TestTableLockPrivilege(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk2 := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(a int)")
tk.MustExec("create user 'testuser'@'localhost'")
require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "testuser", Hostname: "localhost"}, nil, nil, nil))
tk2.MustGetErrMsg("LOCK TABLE test.t WRITE", "[planner:1044]Access denied for user 'testuser'@'localhost' to database 'test'")
tk.MustExec("GRANT LOCK TABLES ON test.* to 'testuser'@'localhost'")
tk2.MustGetErrMsg("LOCK TABLE test.t WRITE", "[planner:1142]SELECT command denied to user 'testuser'@'localhost' for table 't'")
tk.MustExec("REVOKE ALL ON test.* FROM 'testuser'@'localhost'")
tk.MustExec("GRANT SELECT ON test.* to 'testuser'@'localhost'")
tk2.MustGetErrMsg("LOCK TABLE test.t WRITE", "[planner:1044]Access denied for user 'testuser'@'localhost' to database 'test'")
tk.MustExec("GRANT LOCK TABLES ON test.* to 'testuser'@'localhost'")
tk2.MustExec("LOCK TABLE test.t WRITE")

tk.MustExec("create database test2")
tk.MustExec("create table test2.t2(a int)")
tk2.MustGetErrMsg("LOCK TABLE test.t WRITE, test2.t2 WRITE", "[planner:1044]Access denied for user 'testuser'@'localhost' to database 'test2'")
tk.MustExec("GRANT LOCK TABLES ON test2.* to 'testuser'@'localhost'")
tk2.MustGetErrMsg("LOCK TABLE test.t WRITE, test2.t2 WRITE", "[planner:1142]SELECT command denied to user 'testuser'@'localhost' for table 't2'")
tk.MustExec("GRANT SELECT ON test2.* to 'testuser'@'localhost'")
tk2.MustExec("LOCK TABLE test.t WRITE, test2.t2 WRITE")
tk.MustExec("LOCK TABLE test.t WRITE, test2.t2 WRITE")
}

func TestGlobalMemoryControl2(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)

Expand Down
3 changes: 1 addition & 2 deletions pkg/executor/test/fktest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ go_test(
"main_test.go",
],
flaky = True,
shard_count = 25,
shard_count = 24,
deps = [
"//pkg/config",
"//pkg/executor",
"//pkg/infoschema",
"//pkg/kv",
"//pkg/meta/autoid",
"//pkg/parser",
Expand Down
32 changes: 0 additions & 32 deletions pkg/executor/test/fktest/foreign_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
"testing"
"time"

"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/executor"
"github.com/pingcap/tidb/pkg/infoschema"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/parser"
"github.com/pingcap/tidb/pkg/parser/ast"
Expand Down Expand Up @@ -2339,36 +2337,6 @@ func TestPrivilegeCheckInForeignKeyCascade(t *testing.T) {
}
}

func TestTableLockInForeignKeyCascade(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("set @@global.tidb_enable_foreign_key=1")
tk.MustExec("set @@foreign_key_checks=1")
tk.MustExec("use test")
tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("use test")
tk2.MustExec("set @@foreign_key_checks=1")
// enable table lock
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableTableLock = true
})
defer func() {
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableTableLock = false
})
}()
tk.MustExec("create table t1 (id int key);")
tk.MustExec("create table t2 (id int key, foreign key fk (id) references t1(id) ON DELETE CASCADE ON UPDATE CASCADE);")
tk.MustExec("insert into t1 values (1), (2), (3);")
tk.MustExec("insert into t2 values (1), (2), (3);")
tk.MustExec("lock table t2 read;")
tk2.MustGetDBError("delete from t1 where id = 1", infoschema.ErrTableLocked)
tk.MustExec("unlock tables;")
tk2.MustExec("delete from t1 where id = 1")
tk.MustQuery("select * from t1 order by id").Check(testkit.Rows("2", "3"))
tk.MustQuery("select * from t2 order by id").Check(testkit.Rows("2", "3"))
}

func TestForeignKeyIssue39732(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
Loading