From 88216748485903608ac9ff4f9bab7c626f7dbb19 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Mon, 27 Nov 2023 17:19:35 +0800 Subject: [PATCH 1/5] update planner/cascades/integration_test, move 1 test case --- pkg/planner/cascades/BUILD.bazel | 5 +- pkg/planner/cascades/integration_test.go | 59 ------------------- pkg/planner/cascades/main_test.go | 7 +-- .../testdata/integration_suite_in.json | 8 --- .../testdata/integration_suite_out.json | 22 ------- .../r/planner/cascades/integration.result | 23 ++++++++ .../t/planner/cascades/integration.test | 19 ++++++ 7 files changed, 44 insertions(+), 99 deletions(-) delete mode 100644 pkg/planner/cascades/integration_test.go delete mode 100644 pkg/planner/cascades/testdata/integration_suite_in.json delete mode 100644 pkg/planner/cascades/testdata/integration_suite_out.json diff --git a/pkg/planner/cascades/BUILD.bazel b/pkg/planner/cascades/BUILD.bazel index 683ca0a738bea..4fde550d48db1 100644 --- a/pkg/planner/cascades/BUILD.bazel +++ b/pkg/planner/cascades/BUILD.bazel @@ -34,7 +34,6 @@ go_test( timeout = "short", srcs = [ "enforcer_rules_test.go", - "integration_test.go", "main_test.go", "optimize_test.go", "stringer_test.go", @@ -43,7 +42,7 @@ go_test( data = glob(["testdata/**"]), embed = [":cascades"], flaky = True, - shard_count = 26, + shard_count = 25, deps = [ "//pkg/domain", "//pkg/expression", @@ -53,10 +52,8 @@ go_test( "//pkg/planner/core", "//pkg/planner/memo", "//pkg/planner/property", - "//pkg/testkit", "//pkg/testkit/testdata", "//pkg/testkit/testsetup", - "@com_github_pingcap_failpoint//:failpoint", "@com_github_stretchr_testify//require", "@org_uber_go_goleak//:goleak", ], diff --git a/pkg/planner/cascades/integration_test.go b/pkg/planner/cascades/integration_test.go deleted file mode 100644 index 193793a6155df..0000000000000 --- a/pkg/planner/cascades/integration_test.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2019 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cascades_test - -import ( - "testing" - - "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/pkg/planner/cascades" - "github.com/pingcap/tidb/pkg/testkit" - "github.com/pingcap/tidb/pkg/testkit/testdata" -) - -func TestCascadePlannerHashedPartTable(t *testing.T) { - failpoint.Enable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune", `return(true)`) - defer failpoint.Disable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune") - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists pt1") - tk.MustExec("create table pt1(a bigint, b bigint) partition by hash(a) partitions 4") - tk.MustExec(`insert into pt1 values(1,10)`) - tk.MustExec(`insert into pt1 values(2,20)`) - tk.MustExec(`insert into pt1 values(3,30)`) - tk.MustExec(`insert into pt1 values(4,40)`) - tk.MustExec(`insert into pt1 values(5,50)`) - - tk.MustExec("set @@tidb_enable_cascades_planner = 1") - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - integrationSuiteData := cascades.GetIntegrationSuiteData() - integrationSuiteData.LoadTestCases(t, &input, &output) - for i, sql := range input { - testdata.OnRecord(func() { - output[i].SQL = sql - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain " + sql).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(sql).Rows()) - }) - tk.MustQuery("explain " + sql).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(sql).Check(testkit.Rows(output[i].Result...)) - } -} diff --git a/pkg/planner/cascades/main_test.go b/pkg/planner/cascades/main_test.go index dc2dfb4d56a24..2c6a038a23820 100644 --- a/pkg/planner/cascades/main_test.go +++ b/pkg/planner/cascades/main_test.go @@ -25,7 +25,7 @@ import ( "go.uber.org/goleak" ) -var testDataMap = make(testdata.BookKeeper, 3) +var testDataMap = make(testdata.BookKeeper, 2) var stringerSuiteData testdata.TestData var transformationRulesSuiteData testdata.TestData @@ -36,7 +36,6 @@ func TestMain(m *testing.M) { testDataMap.LoadTestSuiteData("testdata", "stringer_suite") testDataMap.LoadTestSuiteData("testdata", "transformation_rules_suite") - testDataMap.LoadTestSuiteData("testdata", "integration_suite") stringerSuiteData = testDataMap["stringer_suite"] transformationRulesSuiteData = testDataMap["transformation_rules_suite"] @@ -58,7 +57,3 @@ func TestMain(m *testing.M) { os.Exit(1) } } - -func GetIntegrationSuiteData() testdata.TestData { - return testDataMap["integration_suite"] -} diff --git a/pkg/planner/cascades/testdata/integration_suite_in.json b/pkg/planner/cascades/testdata/integration_suite_in.json deleted file mode 100644 index d70a1e527eeb1..0000000000000 --- a/pkg/planner/cascades/testdata/integration_suite_in.json +++ /dev/null @@ -1,8 +0,0 @@ -[ - { - "name": "TestCascadePlannerHashedPartTable", - "cases": [ - "select * from pt1 order by a" - ] - } -] diff --git a/pkg/planner/cascades/testdata/integration_suite_out.json b/pkg/planner/cascades/testdata/integration_suite_out.json deleted file mode 100644 index cdd2df740a2bd..0000000000000 --- a/pkg/planner/cascades/testdata/integration_suite_out.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "Name": "TestCascadePlannerHashedPartTable", - "Cases": [ - { - "SQL": "select * from pt1 order by a", - "Plan": [ - "Sort_11 10000.00 root test.pt1.a", - "└─TableReader_9 10000.00 root partition:all data:TableFullScan_10", - " └─TableFullScan_10 10000.00 cop[tikv] table:pt1 keep order:false, stats:pseudo" - ], - "Result": [ - "1 10", - "2 20", - "3 30", - "4 40", - "5 50" - ] - } - ] - } -] diff --git a/tests/integrationtest/r/planner/cascades/integration.result b/tests/integrationtest/r/planner/cascades/integration.result index 8b3e15e1845bb..65b42dde9159c 100644 --- a/tests/integrationtest/r/planner/cascades/integration.result +++ b/tests/integrationtest/r/planner/cascades/integration.result @@ -971,3 +971,26 @@ a b 1 11 2 22 3 33 +SET SESSION tidb_opt_fix_control = '44262:ON'; +drop table if exists pt1; +create table pt1(a bigint, b bigint) partition by hash(a) partitions 4; +insert into pt1 values(1,10); +insert into pt1 values(2,20); +insert into pt1 values(3,30); +insert into pt1 values(4,40); +insert into pt1 values(5,50); +set @@tidb_enable_cascades_planner = 1; +explain select * from pt1 order by a; +id estRows task access object operator info +Sort_11 10000.00 root planner__cascades__integration.pt1.a +└─TableReader_9 10000.00 root partition:all data:TableFullScan_10 + └─TableFullScan_10 10000.00 cop[tikv] table:pt1 keep order:false, stats:pseudo +select * from pt1 order by a; +a b +1 10 +2 20 +3 30 +4 40 +5 50 +set session tidb_opt_fix_control = default; +set @@tidb_enable_cascades_planner = default; diff --git a/tests/integrationtest/t/planner/cascades/integration.test b/tests/integrationtest/t/planner/cascades/integration.test index 4eaf53e8753ed..4d6b695aabeda 100644 --- a/tests/integrationtest/t/planner/cascades/integration.test +++ b/tests/integrationtest/t/planner/cascades/integration.test @@ -260,3 +260,22 @@ explain select a from (select a from t where b > 2 order by a, b limit 3 offset select a from (select a from t where b > 2 order by a, b limit 3 offset 1) as t1 order by a limit 2 offset 1; explain select * from (select * from t order by a limit 3) as t1 order by a, b limit 5; select * from (select * from t order by a limit 3) as t1 order by a, b limit 5; + + +# TestCascadePlannerHashedPartTable +SET SESSION tidb_opt_fix_control = '44262:ON'; +drop table if exists pt1; +create table pt1(a bigint, b bigint) partition by hash(a) partitions 4; +insert into pt1 values(1,10); +insert into pt1 values(2,20); +insert into pt1 values(3,30); +insert into pt1 values(4,40); +insert into pt1 values(5,50); +set @@tidb_enable_cascades_planner = 1; +explain select * from pt1 order by a; +select * from pt1 order by a; + +set session tidb_opt_fix_control = default; +set @@tidb_enable_cascades_planner = default; + + From 2cf3d78ad18e0701c1a932c4c3f44b0c18b5384f Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Tue, 28 Nov 2023 10:56:30 +0800 Subject: [PATCH 2/5] enable table-lock for integrationtest update lock table related tests, move 8 test cases --- pkg/ddl/db_integration_test.go | 108 ------------------ pkg/ddl/tests/partition/BUILD.bazel | 2 +- pkg/ddl/tests/partition/db_partition_test.go | 51 --------- pkg/ddl/tests/serial/BUILD.bazel | 2 +- pkg/ddl/tests/serial/serial_test.go | 21 +--- pkg/executor/test/executor/BUILD.bazel | 3 +- pkg/executor/test/executor/executor_test.go | 28 ----- pkg/executor/test/fktest/BUILD.bazel | 3 +- pkg/executor/test/fktest/foreign_key_test.go | 32 ------ pkg/planner/core/point_get_plan_test.go | 17 --- tests/integrationtest/config.toml | 1 + .../disable_new_collation.toml | 1 + .../r/ddl/db_integration.result | 75 ++++++++++++ .../integrationtest/r/ddl/db_partition.result | 23 ++++ tests/integrationtest/r/ddl/db_table.result | 1 + tests/integrationtest/r/ddl/serial.result | 21 ++++ .../r/executor/executor.result | 29 +++++ .../r/executor/foreign_key.result | 23 ++++ .../r/planner/core/point_get_plan.result | 7 ++ .../integrationtest/t/ddl/db_integration.test | 89 +++++++++++++++ tests/integrationtest/t/ddl/db_partition.test | 35 +++++- tests/integrationtest/t/ddl/serial.test | 24 ++++ .../integrationtest/t/executor/executor.test | 63 ++++++++++ .../t/executor/foreign_key.test | 30 +++++ .../t/planner/core/point_get_plan.test | 11 ++ 25 files changed, 438 insertions(+), 262 deletions(-) diff --git a/pkg/ddl/db_integration_test.go b/pkg/ddl/db_integration_test.go index 5fcedeb4e2384..e657eb1a66277 100644 --- a/pkg/ddl/db_integration_test.go +++ b/pkg/ddl/db_integration_test.go @@ -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 conf.Instance.SlowThreshold = 10000 conf.TiKVClient.AsyncCommit.SafeWindow = 0 conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0 @@ -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) } @@ -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) @@ -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 @@ -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()) diff --git a/pkg/ddl/tests/partition/BUILD.bazel b/pkg/ddl/tests/partition/BUILD.bazel index c3db6c4abdd25..6f9ba066a2d5c 100644 --- a/pkg/ddl/tests/partition/BUILD.bazel +++ b/pkg/ddl/tests/partition/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 48, + shard_count = 47, deps = [ "//pkg/config", "//pkg/ddl", diff --git a/pkg/ddl/tests/partition/db_partition_test.go b/pkg/ddl/tests/partition/db_partition_test.go index f315d3c5d25cd..7fe96f0dd22b9 100644 --- a/pkg/ddl/tests/partition/db_partition_test.go +++ b/pkg/ddl/tests/partition/db_partition_test.go @@ -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) @@ -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") diff --git a/pkg/ddl/tests/serial/BUILD.bazel b/pkg/ddl/tests/serial/BUILD.bazel index b0c9469e57e28..a8169eea39895 100644 --- a/pkg/ddl/tests/serial/BUILD.bazel +++ b/pkg/ddl/tests/serial/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "serial_test.go", ], flaky = True, - shard_count = 20, + shard_count = 19, deps = [ "//pkg/config", "//pkg/ddl", diff --git a/pkg/ddl/tests/serial/serial_test.go b/pkg/ddl/tests/serial/serial_test.go index 79818967e8e8c..0ff651e43cac7 100644 --- a/pkg/ddl/tests/serial/serial_test.go +++ b/pkg/ddl/tests/serial/serial_test.go @@ -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 @@ -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) -} diff --git a/pkg/executor/test/executor/BUILD.bazel b/pkg/executor/test/executor/BUILD.bazel index ba040bee380cf..6d62a8cf04d75 100644 --- a/pkg/executor/test/executor/BUILD.bazel +++ b/pkg/executor/test/executor/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 46, + shard_count = 45, deps = [ "//pkg/config", "//pkg/ddl", @@ -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", diff --git a/pkg/executor/test/executor/executor_test.go b/pkg/executor/test/executor/executor_test.go index b3ebaa566874e..fb861e424c4f9 100644 --- a/pkg/executor/test/executor/executor_test.go +++ b/pkg/executor/test/executor/executor_test.go @@ -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" @@ -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) diff --git a/pkg/executor/test/fktest/BUILD.bazel b/pkg/executor/test/fktest/BUILD.bazel index f2e2472485900..4b12743c6c534 100644 --- a/pkg/executor/test/fktest/BUILD.bazel +++ b/pkg/executor/test/fktest/BUILD.bazel @@ -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", diff --git a/pkg/executor/test/fktest/foreign_key_test.go b/pkg/executor/test/fktest/foreign_key_test.go index a6ce72c17e978..8668e2c26d616 100644 --- a/pkg/executor/test/fktest/foreign_key_test.go +++ b/pkg/executor/test/fktest/foreign_key_test.go @@ -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" @@ -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) diff --git a/pkg/planner/core/point_get_plan_test.go b/pkg/planner/core/point_get_plan_test.go index 5fd3ed286b19e..cde9eb6be3f26 100644 --- a/pkg/planner/core/point_get_plan_test.go +++ b/pkg/planner/core/point_get_plan_test.go @@ -19,7 +19,6 @@ import ( "testing" "time" - "github.com/pingcap/tidb/pkg/config" "github.com/pingcap/tidb/pkg/metrics" "github.com/pingcap/tidb/pkg/planner" "github.com/pingcap/tidb/pkg/planner/core" @@ -173,22 +172,6 @@ func TestPointGetId(t *testing.T) { } } -func TestUpdateWithTableReadLockWillFail(t *testing.T) { - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.EnableTableLock = true - }) - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table tbllock(id int, c int);") - tk.MustExec("insert into tbllock values(1, 2), (2, 2);") - tk.MustExec("lock table tbllock read;") - _, err := tk.Exec("update tbllock set c = 3 where id = 2;") - require.Error(t, err) - require.Equal(t, "[schema:1099]Table 'tbllock' was locked with a READ lock and can't be updated", err.Error()) -} - func TestIssue20692(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/tests/integrationtest/config.toml b/tests/integrationtest/config.toml index 4b2c1112b42c4..9653b7bad7864 100644 --- a/tests/integrationtest/config.toml +++ b/tests/integrationtest/config.toml @@ -15,6 +15,7 @@ lease = "0" host = "127.0.0.1" new_collations_enabled_on_first_bootstrap = true +enable-table-lock = true [status] status-host = "127.0.0.1" diff --git a/tests/integrationtest/disable_new_collation.toml b/tests/integrationtest/disable_new_collation.toml index 928e2a14633cc..4d8c5ed9cdc1b 100644 --- a/tests/integrationtest/disable_new_collation.toml +++ b/tests/integrationtest/disable_new_collation.toml @@ -15,6 +15,7 @@ lease = "0" host = "127.0.0.1" new_collations_enabled_on_first_bootstrap = false +enable-table-lock = true [status] status-host = "127.0.0.1" diff --git a/tests/integrationtest/r/ddl/db_integration.result b/tests/integrationtest/r/ddl/db_integration.result index 507558b7702f8..85d3918834356 100644 --- a/tests/integrationtest/r/ddl/db_integration.result +++ b/tests/integrationtest/r/ddl/db_integration.result @@ -1216,3 +1216,78 @@ alter table t reorganize partition p0 into (partition p01 values less than (10), show warnings; Level Code Message Warning 1105 The statistics of related partitions will be outdated after reorganizing partitions. Please use 'ANALYZE TABLE' statement if you want to update it now +drop table if exists t; +create table t (a int, b real); +alter table t add primary key ((a+b)) nonclustered; +Error 3756 (HY000): The primary key cannot be an expression index +create table t(a int, index((cast(a as JSON)))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +drop table if exists t; +create table t (a int, b real); +alter table t add primary key ((a+b)) nonclustered; +Error 3756 (HY000): The primary key cannot be an expression index +alter table t add index ((rand())); +Error 3758 (HY000): Expression of expression index 'expression_index' contains a disallowed function +alter table t add index ((now()+1)); +Error 3758 (HY000): Expression of expression index 'expression_index' contains a disallowed function +alter table t add column (_V$_idx_0 int); +alter table t add index idx((a+1)); +Error 1060 (42S21): Duplicate column name '_V$_idx_0' +alter table t drop column _V$_idx_0; +alter table t add index idx((a+1)); +alter table t add column (_V$_idx_0 int); +Error 1060 (42S21): Duplicate column name '_V$_idx_0' +alter table t drop index idx; +alter table t add column (_V$_idx_0 int); +alter table t add column (_V$_expression_index_0 int); +alter table t add index ((a+1)); +Error 1060 (42S21): Duplicate column name '_V$_expression_index_0' +alter table t drop column _V$_expression_index_0; +alter table t add index ((a+1)); +alter table t drop column _V$_expression_index_0; +Error 1091 (42000): Can't DROP '_V$_expression_index_0'; check that column/key exists +alter table t add column e int as (_V$_expression_index_0 + 1); +Error 1054 (42S22): Unknown column '_v$_expression_index_0' in 'generated column function' +drop table if exists t; +create table t (j json, key k (((j,j)))); +Error 3800 (HY000): Expression of expression index 'k' cannot refer to a row value +create table t (j json, key k ((j+1),(j+1))); +create table t1 (col1 int, index ((concat('')))); +Error 3761 (HY000): The used storage engine cannot index the expression 'concat(_utf8mb4'')' +CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED); +Error 3756 (HY000): The primary key cannot be an expression index +drop table if exists t; +create table t(id char(10) primary key, short_name char(10), name char(10), key n((upper(`name`)))); +update t t1 set t1.short_name='a' where t1.id='1'; +set @@tidb_enable_strict_double_type_check = 'ON'; +drop table if exists double_type_check; +create table double_type_check(id int, c double(10)); +Error 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use +set @@tidb_enable_strict_double_type_check = 'OFF'; +create table double_type_check(id int, c double(10)); +set @@tidb_enable_strict_double_type_check = default; +drop table if exists t1, t2, tt; +begin; +create temporary table t1(id int primary key, v int); +select * from t1; +id v +insert into t1 values(123, 456); +select * from t1 where id=123; +id v +123 456 +truncate table t1; +select * from t1 where id=123; +id v +commit; +create table tt(id int); +begin; +create temporary table t1(id int); +insert into tt select * from t1; +drop table tt; +create table t2(id int primary key, v int); +insert into t2 values(234, 567); +begin; +create temporary table t2(id int primary key, v int); +select * from t2 where id=234; +id v +commit; diff --git a/tests/integrationtest/r/ddl/db_partition.result b/tests/integrationtest/r/ddl/db_partition.result index eb8321953ca51..875301fe1da5b 100644 --- a/tests/integrationtest/r/ddl/db_partition.result +++ b/tests/integrationtest/r/ddl/db_partition.result @@ -3294,3 +3294,26 @@ partition by range(unix_timestamp(time_recorded)) ( partition p1 values less than (1559192604) ); set @@session.tidb_enable_table_partition = default; +set @@tidb_enable_exchange_partition=1; +drop table if exists pt1; +create table pt1(a int, b int, c int) PARTITION BY hash (a) partitions 1; +alter table pt1 add index idx((a+c)); +drop table if exists nt1; +create table nt1(a int, b int, c int); +alter table pt1 exchange partition p0 with table nt1; +Error 1736 (HY000): Tables have different definitions +alter table nt1 add column (`_V$_idx_0` bigint(20) generated always as (a+b) virtual); +alter table pt1 exchange partition p0 with table nt1; +Error 1736 (HY000): Tables have different definitions +alter table nt1 drop column `_V$_idx_0`; +alter table nt1 add index idx((b-c)); +alter table pt1 exchange partition p0 with table nt1; +Error 1736 (HY000): Tables have different definitions +alter table nt1 drop index idx; +alter table nt1 add index idx((concat(a, b))); +alter table pt1 exchange partition p0 with table nt1; +Error 1736 (HY000): Tables have different definitions +drop table if exists nt2; +create table nt2 (a int, b int, c int); +alter table nt2 add index idx((a+c)); +alter table pt1 exchange partition p0 with table nt2; diff --git a/tests/integrationtest/r/ddl/db_table.result b/tests/integrationtest/r/ddl/db_table.result index a62837e6c4565..0d679a8742989 100644 --- a/tests/integrationtest/r/ddl/db_table.result +++ b/tests/integrationtest/r/ddl/db_table.result @@ -57,6 +57,7 @@ NULL 1 update t1 set id=-1 where id=1; LOCK TABLE t1 READ; update t1 set id=1 where id=1; +Error 1099 (HY000): Table 't1' was locked with a READ lock and can't be updated unlock tables; update t1 set id=1 where id=-1; drop table t1; diff --git a/tests/integrationtest/r/ddl/serial.result b/tests/integrationtest/r/ddl/serial.result index 0de92fadf720e..61f55af5964b4 100644 --- a/tests/integrationtest/r/ddl/serial.result +++ b/tests/integrationtest/r/ddl/serial.result @@ -88,3 +88,24 @@ alter table t1 modify a varchar(20) charset utf8 collate utf8_roman_ci; Error 1273 (HY000): Unsupported collation when new collation is enabled: 'utf8_roman_ci' drop database if exists ucd; use ddl__serial; +drop table if exists t1, tmp1; +create table t1 (id int); +create temporary table tmp1 (id int primary key, a int unique, b int); +rename table tmp1 to tmp2; +Error 8200 (HY000): TiDB doesn't support RENAME TABLE for local temporary table +alter table tmp1 add column c int; +Error 8200 (HY000): TiDB doesn't support ALTER TABLE for local temporary table +alter table tmp1 add index b(b); +Error 8200 (HY000): TiDB doesn't support ALTER TABLE for local temporary table +create index a on tmp1(b); +Error 8200 (HY000): TiDB doesn't support CREATE INDEX for local temporary table +drop index a on tmp1; +Error 8200 (HY000): TiDB doesn't support DROP INDEX for local temporary table +lock tables tmp1 read; +Error 8200 (HY000): TiDB doesn't support LOCK TABLES for local temporary table +lock tables tmp1 write; +Error 8200 (HY000): TiDB doesn't support LOCK TABLES for local temporary table +lock tables t1 read, tmp1 read; +Error 8200 (HY000): TiDB doesn't support LOCK TABLES for local temporary table +admin cleanup table lock tmp1; +Error 8200 (HY000): TiDB doesn't support ADMIN CLEANUP TABLE LOCK for local temporary table diff --git a/tests/integrationtest/r/executor/executor.result b/tests/integrationtest/r/executor/executor.result index e84cda08a7f47..84e5ad2fe6535 100644 --- a/tests/integrationtest/r/executor/executor.result +++ b/tests/integrationtest/r/executor/executor.result @@ -4549,3 +4549,32 @@ stmt_type Update set @@tidb_mem_quota_query=default; set global tidb_mem_oom_action=default; +drop table if exists t; +drop user if exists 'testuser'@'localhost'; +create table t(a int); +create user 'testuser'@'localhost'; +LOCK TABLE executor__executor.t WRITE; +Error 1044 (42000): Access denied for user 'testuser'@'localhost' to database 'executor__executor' +GRANT LOCK TABLES ON executor__executor.* to 'testuser'@'localhost'; +LOCK TABLE executor__executor.t WRITE; +Error 1142 (42000): SELECT command denied to user 'testuser'@'localhost' for table 't' +REVOKE ALL ON executor__executor.* FROM 'testuser'@'localhost'; +GRANT SELECT ON executor__executor.* to 'testuser'@'localhost'; +LOCK TABLE executor__executor.t WRITE; +Error 1044 (42000): Access denied for user 'testuser'@'localhost' to database 'executor__executor' +GRANT LOCK TABLES ON executor__executor.* to 'testuser'@'localhost'; +LOCK TABLE executor__executor.t WRITE; +drop database if exists test2; +create database test2; +create table test2.t2(a int); +LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; +Error 1044 (42000): Access denied for user 'testuser'@'localhost' to database 'test2' +GRANT LOCK TABLES ON test2.* to 'testuser'@'localhost'; +LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; +Error 1142 (42000): SELECT command denied to user 'testuser'@'localhost' for table 't2' +GRANT SELECT ON test2.* to 'testuser'@'localhost'; +LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; +LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; +Error 8020 (HY000): Table 't' was locked in WRITE by server: session: +unlock tables; +drop user 'testuser'@'localhost'; diff --git a/tests/integrationtest/r/executor/foreign_key.result b/tests/integrationtest/r/executor/foreign_key.result index b02a4751c3330..b0ba6ed955906 100644 --- a/tests/integrationtest/r/executor/foreign_key.result +++ b/tests/integrationtest/r/executor/foreign_key.result @@ -431,3 +431,26 @@ id pid SET GLOBAL tidb_mem_oom_action = DEFAULT; set @@tidb_mem_quota_query=DEFAULT; set @@foreign_key_checks=DEFAULT; +set @@global.tidb_enable_foreign_key=1; +set @@foreign_key_checks=1; +drop table if exists t1, t2; +create table t1 (id int key); +create table t2 (id int key, foreign key fk (id) references t1(id) ON DELETE CASCADE ON UPDATE CASCADE); +insert into t1 values (1), (2), (3); +insert into t2 values (1), (2), (3); +lock table t2 read; +set @@foreign_key_checks=1; +delete from t1 where id = 1; +Error 8020 (HY000): Table 't2' was locked in READ by server: session: +unlock tables; +delete from t1 where id = 1; +select * from t1 order by id; +id +2 +3 +select * from t2 order by id; +id +2 +3 +set @@global.tidb_enable_foreign_key=default; +set @@foreign_key_checks=default; diff --git a/tests/integrationtest/r/planner/core/point_get_plan.result b/tests/integrationtest/r/planner/core/point_get_plan.result index 9bd32ff939cb5..005a81660da99 100644 --- a/tests/integrationtest/r/planner/core/point_get_plan.result +++ b/tests/integrationtest/r/planner/core/point_get_plan.result @@ -612,3 +612,10 @@ id val 6 6 rollback; set @@session.autocommit = default; +drop table if exists tbllock; +create table tbllock(id int, c int); +insert into tbllock values(1, 2), (2, 2); +lock table tbllock read; +update tbllock set c = 3 where id = 2; +Error 1099 (HY000): Table 'tbllock' was locked with a READ lock and can't be updated +unlock tables; diff --git a/tests/integrationtest/t/ddl/db_integration.test b/tests/integrationtest/t/ddl/db_integration.test index 8b5c170681b05..74949497795f2 100644 --- a/tests/integrationtest/t/ddl/db_integration.test +++ b/tests/integrationtest/t/ddl/db_integration.test @@ -1019,3 +1019,92 @@ create table t (id bigint, b varchar(20), index idxb(b)) partition by range(id) alter table t reorganize partition p0 into (partition p01 values less than (10), partition p02 values less than (20)); show warnings; + +# TestCreateExpressionIndexError +drop table if exists t; +create table t (a int, b real); +-- error 3756 +alter table t add primary key ((a+b)) nonclustered; +-- error 3753 +create table t(a int, index((cast(a as JSON)))); +drop table if exists t; +create table t (a int, b real); +-- error 3756 +alter table t add primary key ((a+b)) nonclustered; +-- error 3758 +alter table t add index ((rand())); +-- error 3758 +alter table t add index ((now()+1)); +alter table t add column (_V$_idx_0 int); +-- error 1060 +alter table t add index idx((a+1)); +alter table t drop column _V$_idx_0; +alter table t add index idx((a+1)); +-- error 1060 +alter table t add column (_V$_idx_0 int); +alter table t drop index idx; +alter table t add column (_V$_idx_0 int); +alter table t add column (_V$_expression_index_0 int); +-- error 1060 +alter table t add index ((a+1)); +alter table t drop column _V$_expression_index_0; +alter table t add index ((a+1)); +-- error 1091 +alter table t drop column _V$_expression_index_0; +-- error 1054 +alter table t add column e int as (_V$_expression_index_0 + 1); + +## NOTE (#18150): In creating expression index, row value is not allowed. +drop table if exists t; +-- error 3800 +create table t (j json, key k (((j,j)))); +create table t (j json, key k ((j+1),(j+1))); +-- error 3761 +create table t1 (col1 int, index ((concat('')))); +-- error 3756 +CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED); + +## For issue 26349 +drop table if exists t; +create table t(id char(10) primary key, short_name char(10), name char(10), key n((upper(`name`)))); +update t t1 set t1.short_name='a' where t1.id='1'; + + +# TestStrictDoubleTypeCheck +set @@tidb_enable_strict_double_type_check = 'ON'; +drop table if exists double_type_check; +--error 1149 +create table double_type_check(id int, c double(10)); +set @@tidb_enable_strict_double_type_check = 'OFF'; +create table double_type_check(id int, c double(10)); +set @@tidb_enable_strict_double_type_check = default; + + +# TestCreateTempTableInTxn +# https://github.com/pingcap/tidb/issues/35644 +drop table if exists t1, t2, tt; +begin; +create temporary table t1(id int primary key, v int); +select * from t1; +insert into t1 values(123, 456); +select * from t1 where id=123; +truncate table t1; +select * from t1 where id=123; +commit; + +connect (conn1, localhost, root,, ddl__db_integration); +create table tt(id int); +begin; +create temporary table t1(id int); +insert into tt select * from t1; +drop table tt; +disconnect conn1; + +connect (conn1, localhost, root,, ddl__db_integration); +create table t2(id int primary key, v int); +insert into t2 values(234, 567); +begin; +create temporary table t2(id int primary key, v int); +select * from t2 where id=234; +commit; +disconnect conn1; diff --git a/tests/integrationtest/t/ddl/db_partition.test b/tests/integrationtest/t/ddl/db_partition.test index 3f8389edbdac8..275193160e0e0 100644 --- a/tests/integrationtest/t/ddl/db_partition.test +++ b/tests/integrationtest/t/ddl/db_partition.test @@ -2212,4 +2212,37 @@ create table t5 ( time_recorded timestamp ) partition by range(unix_timestamp(time_recorded)) ( partition p1 values less than (1559192604) ); -set @@session.tidb_enable_table_partition = default; \ No newline at end of file +set @@session.tidb_enable_table_partition = default; + + +# TestExchangePartitionExpressIndex +set @@tidb_enable_exchange_partition=1; +drop table if exists pt1; +create table pt1(a int, b int, c int) PARTITION BY hash (a) partitions 1; +alter table pt1 add index idx((a+c)); + +drop table if exists nt1; +create table nt1(a int, b int, c int); +--error 1736 +alter table pt1 exchange partition p0 with table nt1; + +alter table nt1 add column (`_V$_idx_0` bigint(20) generated always as (a+b) virtual); +--error 1736 +alter table pt1 exchange partition p0 with table nt1; + +## test different expression index when expression returns same field type +alter table nt1 drop column `_V$_idx_0`; +alter table nt1 add index idx((b-c)); +--error 1736 +alter table pt1 exchange partition p0 with table nt1; + +## test different expression index when expression returns different field type +alter table nt1 drop index idx; +alter table nt1 add index idx((concat(a, b))); +--error 1736 +alter table pt1 exchange partition p0 with table nt1; + +drop table if exists nt2; +create table nt2 (a int, b int, c int); +alter table nt2 add index idx((a+c)); +alter table pt1 exchange partition p0 with table nt2; diff --git a/tests/integrationtest/t/ddl/serial.test b/tests/integrationtest/t/ddl/serial.test index bb136851aab21..95d2fbae4afb7 100644 --- a/tests/integrationtest/t/ddl/serial.test +++ b/tests/integrationtest/t/ddl/serial.test @@ -98,3 +98,27 @@ alter table t1 modify a varchar(20) charset utf8 collate utf8_roman_ci; # mustGetUnsupportedCollation("alter table t convert to collate utf8mb4_unicode_ci", "utf8mb4_unicode_ci") drop database if exists ucd; use ddl__serial; + + +# TestLocalTemporaryTableBlockedDDL +drop table if exists t1, tmp1; +create table t1 (id int); +create temporary table tmp1 (id int primary key, a int unique, b int); +--error 8200 +rename table tmp1 to tmp2; +--error 8200 +alter table tmp1 add column c int; +--error 8200 +alter table tmp1 add index b(b); +--error 8200 +create index a on tmp1(b); +--error 8200 +drop index a on tmp1; +--error 8200 +lock tables tmp1 read; +--error 8200 +lock tables tmp1 write; +--error 8200 +lock tables t1 read, tmp1 read; +--error 8200 +admin cleanup table lock tmp1; diff --git a/tests/integrationtest/t/executor/executor.test b/tests/integrationtest/t/executor/executor.test index bf5ac6da7dda2..e67c5142cd8f9 100644 --- a/tests/integrationtest/t/executor/executor.test +++ b/tests/integrationtest/t/executor/executor.test @@ -2848,3 +2848,66 @@ select stmt_type from information_schema.statements_summary where digest_text = set @@tidb_mem_quota_query=default; set global tidb_mem_oom_action=default; + + +# TestTableLockPrivilege +drop table if exists t; +drop user if exists 'testuser'@'localhost'; +create table t(a int); +create user 'testuser'@'localhost'; + +connect (conn1, localhost, testuser,,); +--error 1044 +LOCK TABLE executor__executor.t WRITE; + +connection default; +GRANT LOCK TABLES ON executor__executor.* to 'testuser'@'localhost'; + +connection conn1; +--error 1142 +LOCK TABLE executor__executor.t WRITE; + +connection default; +REVOKE ALL ON executor__executor.* FROM 'testuser'@'localhost'; +GRANT SELECT ON executor__executor.* to 'testuser'@'localhost'; + +connection conn1; +--error 1044 +LOCK TABLE executor__executor.t WRITE; + +connection default; +GRANT LOCK TABLES ON executor__executor.* to 'testuser'@'localhost'; + +connection conn1; +LOCK TABLE executor__executor.t WRITE; + +connection default; +drop database if exists test2; +create database test2; +create table test2.t2(a int); + +connection conn1; +--error 1044 +LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; + +connection default; +GRANT LOCK TABLES ON test2.* to 'testuser'@'localhost'; + +connection conn1; +--error 1142 +LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; + +connection default; +GRANT SELECT ON test2.* to 'testuser'@'localhost'; + +connection conn1; +LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; + +connection default; +--replace_regex /server: .*session: .*/server: session: / +--error 8020 +LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; + +disconnect conn1; +unlock tables; +drop user 'testuser'@'localhost'; diff --git a/tests/integrationtest/t/executor/foreign_key.test b/tests/integrationtest/t/executor/foreign_key.test index 46b274f662f30..12920167e9f70 100644 --- a/tests/integrationtest/t/executor/foreign_key.test +++ b/tests/integrationtest/t/executor/foreign_key.test @@ -347,3 +347,33 @@ set @@tidb_mem_quota_query=DEFAULT; set @@foreign_key_checks=DEFAULT; +# TestTableLockInForeignKeyCascade +set @@global.tidb_enable_foreign_key=1; +set @@foreign_key_checks=1; +drop table if exists t1, t2; +create table t1 (id int key); +create table t2 (id int key, foreign key fk (id) references t1(id) ON DELETE CASCADE ON UPDATE CASCADE); +insert into t1 values (1), (2), (3); +insert into t2 values (1), (2), (3); +lock table t2 read; + +connect (conn1, localhost, root,, executor__foreign_key); +set @@foreign_key_checks=1; +--replace_regex /server: .*session: .*/server: session: / +--error 1099 +delete from t1 where id = 1; + +connection default; +unlock tables; + +connection conn1; +delete from t1 where id = 1; + +connection default; +select * from t1 order by id; +select * from t2 order by id; +disconnect conn1; + +set @@global.tidb_enable_foreign_key=default; +set @@foreign_key_checks=default; + diff --git a/tests/integrationtest/t/planner/core/point_get_plan.test b/tests/integrationtest/t/planner/core/point_get_plan.test index 8f103cea2d2b0..795cdaeb3d6c6 100644 --- a/tests/integrationtest/t/planner/core/point_get_plan.test +++ b/tests/integrationtest/t/planner/core/point_get_plan.test @@ -356,3 +356,14 @@ select * from fu where id = 6 for update; rollback; set @@session.autocommit = default; + + +# TestUpdateWithTableReadLockWillFail +drop table if exists tbllock; +create table tbllock(id int, c int); +insert into tbllock values(1, 2), (2, 2); +lock table tbllock read; +--error 1099 +update tbllock set c = 3 where id = 2; + +unlock tables; From 99055dbf3786d27106b81108297bff26853319cf Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Tue, 28 Nov 2023 14:05:38 +0800 Subject: [PATCH 3/5] update mysql-tester --- tests/integrationtest/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrationtest/run-tests.sh b/tests/integrationtest/run-tests.sh index e0142e77d0692..704753356bf1f 100755 --- a/tests/integrationtest/run-tests.sh +++ b/tests/integrationtest/run-tests.sh @@ -88,7 +88,7 @@ function build_mysql_tester() { echo "building mysql-tester binary: $mysql_tester" rm -rf $mysql_tester - GOBIN=$PWD go install github.com/pingcap/mysql-tester/src@77628a8d2fae0c2f4cbc059d45785ae9615c817a + GOBIN=$PWD go install github.com/pingcap/mysql-tester/src@17b728effac3dd2f347bf508d4920657860ef719 mv src mysql_tester } From 3aa2de8fa198e1c5d4a6009a29cacdd3b294af09 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Tue, 28 Nov 2023 14:17:15 +0800 Subject: [PATCH 4/5] fix unstable test --- tests/integrationtest/r/planner/core/cbo.result | 4 ++-- tests/integrationtest/t/planner/core/cbo.test | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integrationtest/r/planner/core/cbo.result b/tests/integrationtest/r/planner/core/cbo.result index 230e53fe949ca..0847873f33bb9 100644 --- a/tests/integrationtest/r/planner/core/cbo.result +++ b/tests/integrationtest/r/planner/core/cbo.result @@ -73,10 +73,10 @@ Projection_9 1.00 1 root NULL time:, loops:, RU:, Concurrency:OFF └─StreamAgg_11 1.00 1 root NULL time:, loops: funcs:sum(Column#16)->Column#8, funcs:firstrow(Column#17)->planner__core__cbo.t1.a, funcs:firstrow(Column#18)->planner__core__cbo.t1.b N/A └─Projection_53 4.00 3 root NULL time:, loops:, Concurrency:OFF cast(planner__core__cbo.t1.c, decimal(10,0) BINARY)->Column#16, planner__core__cbo.t1.a->Column#17, planner__core__cbo.t1.b->Column#18 N/A └─HashJoin_51 4.00 3 root NULL time:, loops:, build_hash_table:{total:, fetch:, build:}, probe:{concurrency:, total:, max:, probe:, fetch:} inner join, equal:[eq(planner__core__cbo.t1.a, planner__core__cbo.t2.b)] - ├─TableReader_30(Build) 6.00 6 root NULL time:, loops:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:Selection_29 N/A + ├─TableReader_30(Build) 6.00 6 root NULL time.*loops.*cop_task.* data:Selection_29 N/A │ └─Selection_29 6.00 6 cop[tikv] NULL tikv_task:{time:, loops:} gt(planner__core__cbo.t2.b, 1), not(isnull(planner__core__cbo.t2.b)) N/A N/A │ └─TableFullScan_28 6.00 6 cop[tikv] table:t2 tikv_task:{time:, loops:} keep order:false N/A N/A - └─TableReader_33(Probe) 4.00 4 root NULL time:, loops:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:Selection_32 N/A + └─TableReader_33(Probe) 4.00 4 root NULL time.*loops.*cop_task.* data:Selection_32 N/A └─Selection_32 4.00 4 cop[tikv] NULL tikv_task:{time:, loops:} gt(planner__core__cbo.t1.a, 1), not(isnull(planner__core__cbo.t1.a)) N/A N/A └─TableFullScan_31 5.00 5 cop[tikv] table:t1 tikv_task:{time:, loops:} keep order:false N/A N/A set sql_mode=default; diff --git a/tests/integrationtest/t/planner/core/cbo.test b/tests/integrationtest/t/planner/core/cbo.test index 7eab31bc66b5e..f9608ceaf8cb0 100644 --- a/tests/integrationtest/t/planner/core/cbo.test +++ b/tests/integrationtest/t/planner/core/cbo.test @@ -59,6 +59,6 @@ create table t2(a int, b int); insert into t1 values (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5); insert into t2 values (2, 22), (3, 33), (5, 55), (233, 2), (333, 3), (3434, 5); analyze table t1, t2; ---replace_regex /:[ ]?[.0-9]+[nµms]*/:/ /, scan_detail: {.*}// / tot_proc:.*?, tot_wait:.*?,// /[.0-9]+ ((KB)|(Bytes))// +--replace_regex /:[ ]?[.0-9]+[nµms]*/:/ /time.*loops.*cop_task.*/time.*loops.*cop_task.*/ /[.0-9]+ ((KB)|(Bytes))// explain analyze select t1.a, t1.b, sum(t1.c) from t1 join t2 on t1.a = t2.b where t1.a > 1; set sql_mode=default; From 83d697847ea34b25bdca98259cffc204f2023d0b Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Tue, 28 Nov 2023 14:50:33 +0800 Subject: [PATCH 5/5] fix unstable test --- tests/integrationtest/r/explain_easy.result | 2 +- tests/integrationtest/t/explain_easy.test | 2 +- tests/integrationtest/t/planner/core/cbo.test | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integrationtest/r/explain_easy.result b/tests/integrationtest/r/explain_easy.result index 83e569d15ba5e..bc4a5fa12ea69 100644 --- a/tests/integrationtest/r/explain_easy.result +++ b/tests/integrationtest/r/explain_easy.result @@ -197,7 +197,7 @@ HashAgg 24000.00 root group by:Column#10, funcs:firstrow(Column#11)->Column#10 └─IndexReader 8000.00 root index:StreamAgg └─StreamAgg 8000.00 cop[tikv] group by:explain_easy.t2.c1, └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:true, stats:pseudo -select * from information_schema.tidb_indexes where table_name='t4'; +select * from information_schema.tidb_indexes where table_name='t4' and table_schema='explain_easy'; TABLE_SCHEMA TABLE_NAME NON_UNIQUE KEY_NAME SEQ_IN_INDEX COLUMN_NAME SUB_PART INDEX_COMMENT Expression INDEX_ID IS_VISIBLE CLUSTERED explain_easy t4 0 PRIMARY 1 a NULL NULL 0 YES YES explain_easy t4 1 idx 1 a NULL NULL 1 YES NO diff --git a/tests/integrationtest/t/explain_easy.test b/tests/integrationtest/t/explain_easy.test index 2d452215da985..23dda18f3c003 100644 --- a/tests/integrationtest/t/explain_easy.test +++ b/tests/integrationtest/t/explain_easy.test @@ -42,7 +42,7 @@ explain format = 'brief' select if(10, t1.c1, t1.c2) from t1; explain format = 'brief' select c1 from t2 union select c1 from t2 union all select c1 from t2; explain format = 'brief' select c1 from t2 union all select c1 from t2 union select c1 from t2; -select * from information_schema.tidb_indexes where table_name='t4'; +select * from information_schema.tidb_indexes where table_name='t4' and table_schema='explain_easy'; # https://github.com/pingcap/tidb/issues/9125 explain format = 'brief' select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2; diff --git a/tests/integrationtest/t/planner/core/cbo.test b/tests/integrationtest/t/planner/core/cbo.test index f9608ceaf8cb0..911bfbd47b309 100644 --- a/tests/integrationtest/t/planner/core/cbo.test +++ b/tests/integrationtest/t/planner/core/cbo.test @@ -59,6 +59,6 @@ create table t2(a int, b int); insert into t1 values (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5); insert into t2 values (2, 22), (3, 33), (5, 55), (233, 2), (333, 3), (3434, 5); analyze table t1, t2; ---replace_regex /:[ ]?[.0-9]+[nµms]*/:/ /time.*loops.*cop_task.*/time.*loops.*cop_task.*/ /[.0-9]+ ((KB)|(Bytes))// +--replace_regex /:[ ]?[.0-9]+[nµms]*/:/ /time.*loops.*cop_task.*/time.*loops.*cop_task.*/ /, scan_detail: {.*}// /[.0-9]+ ((KB)|(Bytes))// explain analyze select t1.a, t1.b, sum(t1.c) from t1 join t2 on t1.a = t2.b where t1.a > 1; set sql_mode=default;