From a034b30dd3a77197cf9738371023cdd370c03a77 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Wed, 1 Nov 2023 13:57:25 +0800 Subject: [PATCH 1/8] update admin --- pkg/executor/test/admintest/BUILD.bazel | 2 +- pkg/executor/test/admintest/admin_test.go | 60 ------------------- tests/integrationtest/r/executor/admin.result | 48 +++++++++++++++ tests/integrationtest/t/executor/admin.test | 43 +++++++++++++ 4 files changed, 92 insertions(+), 61 deletions(-) diff --git a/pkg/executor/test/admintest/BUILD.bazel b/pkg/executor/test/admintest/BUILD.bazel index 7d217e0fa3d1d..75376d7081a9a 100644 --- a/pkg/executor/test/admintest/BUILD.bazel +++ b/pkg/executor/test/admintest/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 21, + shard_count = 18, deps = [ "//pkg/config", "//pkg/domain", diff --git a/pkg/executor/test/admintest/admin_test.go b/pkg/executor/test/admintest/admin_test.go index 63c7bb4372965..ab535641485b3 100644 --- a/pkg/executor/test/admintest/admin_test.go +++ b/pkg/executor/test/admintest/admin_test.go @@ -45,53 +45,6 @@ import ( "go.uber.org/zap" ) -func TestAdminCheckIndexRange(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists check_index_test;`) - tk.MustExec(`create table check_index_test (a int, b varchar(10), index a_b (a, b), index b (b))`) - tk.MustExec(`insert check_index_test values (3, "ab"),(2, "cd"),(1, "ef"),(-1, "hi")`) - result := tk.MustQuery("admin check index check_index_test a_b (2, 4);") - result.Check(testkit.Rows("1 ef 3", "2 cd 2")) - - result = tk.MustQuery("admin check index check_index_test a_b (3, 5);") - result.Check(testkit.Rows("-1 hi 4", "1 ef 3")) - - tk.MustExec("use mysql") - result = tk.MustQuery("admin check index test.check_index_test a_b (2, 3), (4, 5);") - result.Check(testkit.Rows("-1 hi 4", "2 cd 2")) -} - -func TestAdminCheckIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - check := func() { - tk.MustExec("insert admin_test (c1, c2) values (1, 1), (2, 2), (5, 5), (10, 10), (11, 11), (NULL, NULL)") - tk.MustExec("admin check index admin_test c1") - tk.MustExec("admin check index admin_test c2") - } - tk.MustExec("drop table if exists admin_test") - tk.MustExec("create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2))") - check() - - // Test for hash partition table. - tk.MustExec("drop table if exists admin_test") - tk.MustExec("create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)) partition by hash(c2) partitions 5;") - check() - - // Test for range partition table. - tk.MustExec("drop table if exists admin_test") - tk.MustExec(`create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)) PARTITION BY RANGE ( c2 ) ( - PARTITION p0 VALUES LESS THAN (5), - PARTITION p1 VALUES LESS THAN (10), - PARTITION p2 VALUES LESS THAN (MAXVALUE))`) - check() -} - func TestAdminRecoverIndex(t *testing.T) { store, domain := testkit.CreateMockStoreAndDomain(t) @@ -1770,16 +1723,3 @@ func TestAdminCheckTableErrorLocateForClusterIndex(t *testing.T) { tk.MustExec("admin check table admin_test") } } - -func TestAdminCheckTableErrorLocateBigTable(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists admin_test") - tk.MustExec("create table admin_test (c1 int, c2 int, primary key(c1), key(c2))") - tk.MustExec("set cte_max_recursion_depth=100000;") - tk.MustExec("insert into admin_test with recursive cte(a, b) as (select 1, 1 union select a+1, b+1 from cte where cte.a< 100000) select * from cte;") - tk.MustQuery("select /*+ read_from_storage(tikv[`test`.`admin_test`]) */ bit_xor(crc32(md5(concat_ws(0x2, `c1`, `c2`)))), ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024), count(*) from `test`.`admin_test` use index() where 0 = 0 group by ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024)") - tk.MustQuery("select bit_xor(crc32(md5(concat_ws(0x2, `c1`, `c2`)))), ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024), count(*) from `test`.`admin_test` use index(`c2`) where 0 = 0 group by ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024)") -} diff --git a/tests/integrationtest/r/executor/admin.result b/tests/integrationtest/r/executor/admin.result index c1ce27f640122..fc561ce64047a 100644 --- a/tests/integrationtest/r/executor/admin.result +++ b/tests/integrationtest/r/executor/admin.result @@ -190,3 +190,51 @@ alter table t1 modify column a decimal(3,2); delete from t1; admin check table t1; +drop table if exists check_index_test; +create table check_index_test (a int, b varchar(10), index a_b (a, b), index b (b)); +insert check_index_test values (3, "ab"),(2, "cd"),(1, "ef"),(-1, "hi"); +admin check index check_index_test a_b (2, 4); +a b extra_handle +1 ef 3 +2 cd 2 +admin check index check_index_test a_b (3, 5); +a b extra_handle +-1 hi 4 +1 ef 3 +use mysql; +admin check index executor__admin.check_index_test a_b (2, 3), (4, 5); +a b extra_handle +-1 hi 4 +2 cd 2 +use executor__admin; +drop table if exists admin_test; +create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)); +insert admin_test (c1, c2) values (1, 1), (2, 2), (5, 5), (10, 10), (11, 11), (NULL, NULL); +admin check index admin_test c1; + +admin check index admin_test c2; + +drop table if exists admin_test; +create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)) partition by hash(c2) partitions 5; +insert admin_test (c1, c2) values (1, 1), (2, 2), (5, 5), (10, 10), (11, 11), (NULL, NULL); +admin check index admin_test c1; + +admin check index admin_test c2; + +drop table if exists admin_test; +create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)) PARTITION BY RANGE ( c2 ) ( +PARTITION p0 VALUES LESS THAN (5), +PARTITION p1 VALUES LESS THAN (10), +PARTITION p2 VALUES LESS THAN (MAXVALUE)); +insert admin_test (c1, c2) values (1, 1), (2, 2), (5, 5), (10, 10), (11, 11), (NULL, NULL); +admin check index admin_test c1; + +admin check index admin_test c2; + +drop table if exists admin_test; +create table admin_test (c1 int, c2 int, primary key(c1), key(c2)); +set cte_max_recursion_depth=100000; +insert into admin_test with recursive cte(a, b) as (select 1, 1 union select a+1, b+1 from cte where cte.a< 100000) select * from cte; +select /*+ read_from_storage(tikv[`executor__admin`.`admin_test`]) */ bit_xor(crc32(md5(concat_ws(0x2, `c1`, `c2`)))), ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024), count(*) from `executor__admin`.`admin_test` use index() where 0 = 0 group by ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024); +select bit_xor(crc32(md5(concat_ws(0x2, `c1`, `c2`)))), ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024), count(*) from `executor__admin`.`admin_test` use index(`c2`) where 0 = 0 group by ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024); +set cte_max_recursion_depth=default; diff --git a/tests/integrationtest/t/executor/admin.test b/tests/integrationtest/t/executor/admin.test index 90cb7da71935e..fcb9eeb5b5065 100644 --- a/tests/integrationtest/t/executor/admin.test +++ b/tests/integrationtest/t/executor/admin.test @@ -183,3 +183,46 @@ insert into t1 set a='1.9'; alter table t1 modify column a decimal(3,2); delete from t1; admin check table t1; + +# TestAdminCheckIndexRange +drop table if exists check_index_test; +create table check_index_test (a int, b varchar(10), index a_b (a, b), index b (b)); +insert check_index_test values (3, "ab"),(2, "cd"),(1, "ef"),(-1, "hi"); +admin check index check_index_test a_b (2, 4); +admin check index check_index_test a_b (3, 5); +use mysql; +admin check index executor__admin.check_index_test a_b (2, 3), (4, 5); +use executor__admin; + +# TestAdminCheckIndex +drop table if exists admin_test; +create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)); +insert admin_test (c1, c2) values (1, 1), (2, 2), (5, 5), (10, 10), (11, 11), (NULL, NULL); +admin check index admin_test c1; +admin check index admin_test c2; +drop table if exists admin_test; +## for hash partition +create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)) partition by hash(c2) partitions 5; +insert admin_test (c1, c2) values (1, 1), (2, 2), (5, 5), (10, 10), (11, 11), (NULL, NULL); +admin check index admin_test c1; +admin check index admin_test c2; +drop table if exists admin_test; +## for range partition +create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)) PARTITION BY RANGE ( c2 ) ( + PARTITION p0 VALUES LESS THAN (5), + PARTITION p1 VALUES LESS THAN (10), + PARTITION p2 VALUES LESS THAN (MAXVALUE)); +insert admin_test (c1, c2) values (1, 1), (2, 2), (5, 5), (10, 10), (11, 11), (NULL, NULL); +admin check index admin_test c1; +admin check index admin_test c2; + +# TestAdminCheckTableErrorLocateBigTable +drop table if exists admin_test; +create table admin_test (c1 int, c2 int, primary key(c1), key(c2)); +set cte_max_recursion_depth=100000; +insert into admin_test with recursive cte(a, b) as (select 1, 1 union select a+1, b+1 from cte where cte.a< 100000) select * from cte; +--disable_result_log +select /*+ read_from_storage(tikv[`executor__admin`.`admin_test`]) */ bit_xor(crc32(md5(concat_ws(0x2, `c1`, `c2`)))), ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024), count(*) from `executor__admin`.`admin_test` use index() where 0 = 0 group by ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024); +select bit_xor(crc32(md5(concat_ws(0x2, `c1`, `c2`)))), ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024), count(*) from `executor__admin`.`admin_test` use index(`c2`) where 0 = 0 group by ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024); +set cte_max_recursion_depth=default; +--enable_result_log From 9ea84205999158d8938b071c9d748dab6794797e Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Wed, 1 Nov 2023 14:23:35 +0800 Subject: [PATCH 2/8] update autoid --- pkg/executor/test/autoidtest/BUILD.bazel | 3 +- pkg/executor/test/autoidtest/autoid_test.go | 156 +---- .../integrationtest/r/executor/autoid.result | 570 ++++++++++++++++++ tests/integrationtest/t/executor/autoid.test | 392 ++++++++++++ 4 files changed, 965 insertions(+), 156 deletions(-) create mode 100644 tests/integrationtest/r/executor/autoid.result create mode 100644 tests/integrationtest/t/executor/autoid.test diff --git a/pkg/executor/test/autoidtest/BUILD.bazel b/pkg/executor/test/autoidtest/BUILD.bazel index 61c420b71bfff..37ec8be1ce88f 100644 --- a/pkg/executor/test/autoidtest/BUILD.bazel +++ b/pkg/executor/test/autoidtest/BUILD.bazel @@ -9,14 +9,13 @@ go_test( ], flaky = True, race = "on", - shard_count = 10, + shard_count = 5, deps = [ "//pkg/autoid_service", "//pkg/config", "//pkg/ddl/testutil", "//pkg/meta/autoid", "//pkg/parser/mysql", - "//pkg/session", "//pkg/sessionctx/variable", "//pkg/testkit", "//pkg/testkit/testutil", diff --git a/pkg/executor/test/autoidtest/autoid_test.go b/pkg/executor/test/autoidtest/autoid_test.go index 06bf8bc80c215..8274d207e0d73 100644 --- a/pkg/executor/test/autoidtest/autoid_test.go +++ b/pkg/executor/test/autoidtest/autoid_test.go @@ -16,7 +16,6 @@ package autoid_test import ( "context" - "fmt" "strconv" "strings" "testing" @@ -25,7 +24,6 @@ import ( _ "github.com/pingcap/tidb/pkg/autoid_service" ddltestutil "github.com/pingcap/tidb/pkg/ddl/testutil" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/session" "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/testkit" "github.com/pingcap/tidb/pkg/testkit/testutil" @@ -95,52 +93,6 @@ func TestFilterDifferentAllocators(t *testing.T) { } } -func TestAutoIncrementInsertMinMax(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - cases := []struct { - t string - s string - vals []int64 - expect [][]interface{} - }{ - {"tinyint", "signed", []int64{-128, 0, 127}, testkit.Rows("-128", "1", "2", "3", "127")}, - {"tinyint", "unsigned", []int64{0, 127, 255}, testkit.Rows("1", "2", "127", "128", "255")}, - {"smallint", "signed", []int64{-32768, 0, 32767}, testkit.Rows("-32768", "1", "2", "3", "32767")}, - {"smallint", "unsigned", []int64{0, 32767, 65535}, testkit.Rows("1", "2", "32767", "32768", "65535")}, - {"mediumint", "signed", []int64{-8388608, 0, 8388607}, testkit.Rows("-8388608", "1", "2", "3", "8388607")}, - {"mediumint", "unsigned", []int64{0, 8388607, 16777215}, testkit.Rows("1", "2", "8388607", "8388608", "16777215")}, - {"integer", "signed", []int64{-2147483648, 0, 2147483647}, testkit.Rows("-2147483648", "1", "2", "3", "2147483647")}, - {"integer", "unsigned", []int64{0, 2147483647, 4294967295}, testkit.Rows("1", "2", "2147483647", "2147483648", "4294967295")}, - {"bigint", "signed", []int64{-9223372036854775808, 0, 9223372036854775807}, testkit.Rows("-9223372036854775808", "1", "2", "3", "9223372036854775807")}, - {"bigint", "unsigned", []int64{0, 9223372036854775807}, testkit.Rows("1", "2", "9223372036854775807", "9223372036854775808")}, - } - - for _, option := range []string{"", "auto_id_cache 1", "auto_id_cache 100"} { - for idx, c := range cases { - sql := fmt.Sprintf("create table t%d (a %s %s key auto_increment) %s", idx, c.t, c.s, option) - tk.MustExec(sql) - - for _, val := range c.vals { - tk.MustExec(fmt.Sprintf("insert into t%d values (%d)", idx, val)) - tk.Exec(fmt.Sprintf("insert into t%d values ()", idx)) // ignore error - } - - tk.MustQuery(fmt.Sprintf("select * from t%d order by a", idx)).Check(c.expect) - - tk.MustExec(fmt.Sprintf("drop table t%d", idx)) - } - } - - tk.MustExec("create table t10 (a integer key auto_increment) auto_id_cache 1") - err := tk.ExecToErr("insert into t10 values (2147483648)") - require.Error(t, err) - err = tk.ExecToErr("insert into t10 values (-2147483649)") - require.Error(t, err) -} - func TestInsertWithAutoidSchema(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -154,14 +106,10 @@ func TestInsertWithAutoidSchema(t *testing.T) { tk.MustExec(`create table t7(id int primary key, n double unsigned auto_increment, key I_n(n));`) // test for inserting multiple values tk.MustExec(`create table t8(id int primary key auto_increment, n int);`) - testInsertWithAutoidSchema(t, tk) -} -func TestInsertWithAutoidSchemaCache(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) + // test for auto_id_cache = 1 + tk.MustExec(`drop table if exists t1, t2, t3, t4, t5, t6, t7, t8`) tk.MustExec(`create table t1(id int primary key auto_increment, n int) AUTO_ID_CACHE 1;`) tk.MustExec(`create table t2(id int unsigned primary key auto_increment, n int) AUTO_ID_CACHE 1;`) tk.MustExec(`create table t3(id tinyint primary key auto_increment, n int) AUTO_ID_CACHE 1;`) @@ -171,7 +119,6 @@ func TestInsertWithAutoidSchemaCache(t *testing.T) { tk.MustExec(`create table t7(id int primary key, n double unsigned auto_increment, key I_n(n)) AUTO_ID_CACHE 1;`) // test for inserting multiple values tk.MustExec(`create table t8(id int primary key auto_increment, n int);`) - testInsertWithAutoidSchema(t, tk) } @@ -678,66 +625,6 @@ func TestAutoIDIncrementAndOffset(t *testing.T) { } } -func TestRenameTableForAutoIncrement(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - tk.MustExec("drop table if exists t1, t2, t3;") - tk.MustExec("create table t1 (id int key auto_increment);") - tk.MustExec("insert into t1 values ()") - tk.MustExec("rename table t1 to t11") - tk.MustExec("insert into t11 values ()") - // TODO(tiancaiamao): fix bug and uncomment here, rename table should not discard the cached AUTO_ID. - // tk.MustQuery("select * from t11").Check(testkit.Rows("1", "2")) - - // auto_id_cache 1 use another implementation and do not have such bug. - tk.MustExec("create table t2 (id int key auto_increment) auto_id_cache 1;") - tk.MustExec("insert into t2 values ()") - tk.MustExec("rename table t2 to t22") - tk.MustExec("insert into t22 values ()") - tk.MustQuery("select * from t22").Check(testkit.Rows("1", "2")) - - tk.MustExec("create table t3 (id int key auto_increment) auto_id_cache 100;") - tk.MustExec("insert into t3 values ()") - tk.MustExec("rename table t3 to t33") - tk.MustExec("insert into t33 values ()") - // TODO(tiancaiamao): fix bug and uncomment here, rename table should not discard the cached AUTO_ID. - // tk.MustQuery("select * from t33").Check(testkit.Rows("1", "2")) -} - -func TestAlterTableAutoIDCache(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - tk.MustExec("drop table if exists t_473;") - tk.MustExec("create table t_473 (id int key auto_increment)") - tk.MustExec("insert into t_473 values ()") - tk.MustQuery("select * from t_473").Check(testkit.Rows("1")) - rs, err := tk.Exec("show table t_473 next_row_id") - require.NoError(t, err) - rows, err1 := session.ResultSetToStringSlice(context.Background(), tk.Session(), rs) - require.NoError(t, err1) - // "test t_473 id 1013608 AUTO_INCREMENT" - val, err2 := strconv.ParseUint(rows[0][3], 10, 64) - require.NoError(t, err2) - - tk.MustExec("alter table t_473 auto_id_cache = 100") - tk.MustQuery("show table t_473 next_row_id").Check(testkit.Rows( - fmt.Sprintf("test t_473 id %d _TIDB_ROWID", val), - "test t_473 id 1 AUTO_INCREMENT", - )) - tk.MustExec("insert into t_473 values ()") - tk.MustQuery("select * from t_473").Check(testkit.Rows("1", fmt.Sprintf("%d", val))) - tk.MustQuery("show table t_473 next_row_id").Check(testkit.Rows( - fmt.Sprintf("test t_473 id %d _TIDB_ROWID", val+100), - "test t_473 id 1 AUTO_INCREMENT", - )) - - // Note that auto_id_cache=1 use a different implementation, switch between them is not allowed. - // TODO: relax this restriction and update the test case. - tk.MustExecToErr("alter table t_473 auto_id_cache = 1") -} - func TestMockAutoIDServiceError(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -767,42 +654,3 @@ func TestIssue39528(t *testing.T) { // Make sure the code does not visit tikv on allocate path. require.False(t, codeRun) } - -func TestAutoIDConstraint(t *testing.T) { - // Remove the constraint that auto id column must be defined as a key - // See https://github.com/pingcap/tidb/issues/40580 - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - - // Cover: create table with/without key constraint - template := `create table t%d (id int auto_increment,k int,c char(120)%s) %s` - keyDefs := []string{"", - ",PRIMARY KEY(k, id)", - ",key idx_1(id)", - ",PRIMARY KEY(`k`, `id`), key idx_1(id)", - } - engineDefs := []string{"", - "engine = MyISAM", - "engine = InnoDB", - "auto_id_cache 1", - "auto_id_cache 100", - } - i := 0 - for _, keyDef := range keyDefs { - for _, engineDef := range engineDefs { - tk.MustExec(fmt.Sprintf("drop table if exists t%d", i)) - sql := fmt.Sprintf(template, i, keyDef, engineDef) - tk.MustExec(sql) - i++ - } - } - - // alter table add auto id column is not supported, but cover it here to prevent regression - tk.MustExec("create table tt1 (id int)") - tk.MustExecToErr("alter table tt1 add column (c int auto_increment)") - - // Cover case: create table with auto id column as key, and remove it later - tk.MustExec("create table tt2 (id int, c int auto_increment, key c_idx(c))") - tk.MustExec("alter table tt2 drop index c_idx") -} diff --git a/tests/integrationtest/r/executor/autoid.result b/tests/integrationtest/r/executor/autoid.result new file mode 100644 index 0000000000000..8860229165e2a --- /dev/null +++ b/tests/integrationtest/r/executor/autoid.result @@ -0,0 +1,570 @@ +drop table if exists t0, t1, t2, t3, t4, t5, t6, t7, t8, t9; +create table t0 (a tinyint signed key auto_increment) ; +insert into t0 values (-128); +insert into t0 values (); +insert into t0 values (0); +insert into t0 values (); +insert into t0 values (127); +insert into t0 values (); +Error 1690 (22003): constant 128 overflows tinyint +select * from t0 order by a; +a +-128 +1 +2 +3 +127 +drop table t0; +create table t1 (a tinyint unsigned key auto_increment) ; +insert into t1 values (0); +insert into t1 values (); +insert into t1 values (127); +insert into t1 values (); +insert into t1 values (255); +insert into t1 values (); +Error 1690 (22003): constant 256 overflows tinyint +select * from t1 order by a; +a +1 +2 +127 +128 +255 +drop table t1; +create table t2 (a smallint signed key auto_increment) ; +insert into t2 values (-32768); +insert into t2 values (); +insert into t2 values (0); +insert into t2 values (); +insert into t2 values (32767); +insert into t2 values (); +Error 1690 (22003): constant 32768 overflows smallint +select * from t2 order by a; +a +-32768 +1 +2 +3 +32767 +drop table t2; +create table t3 (a smallint unsigned key auto_increment) ; +insert into t3 values (0); +insert into t3 values (); +insert into t3 values (32767); +insert into t3 values (); +insert into t3 values (65535); +insert into t3 values (); +Error 1690 (22003): constant 65536 overflows smallint +select * from t3 order by a; +a +1 +2 +32767 +32768 +65535 +drop table t3; +create table t4 (a mediumint signed key auto_increment) ; +insert into t4 values (-8388608); +insert into t4 values (); +insert into t4 values (0); +insert into t4 values (); +insert into t4 values (8388607); +insert into t4 values (); +Error 1690 (22003): constant 8388608 overflows mediumint +select * from t4 order by a; +a +-8388608 +1 +2 +3 +8388607 +drop table t4; +create table t5 (a mediumint unsigned key auto_increment) ; +insert into t5 values (0); +insert into t5 values (); +insert into t5 values (8388607); +insert into t5 values (); +insert into t5 values (16777215); +insert into t5 values (); +Error 1690 (22003): constant 16777216 overflows mediumint +select * from t5 order by a; +a +1 +2 +8388607 +8388608 +16777215 +drop table t5; +create table t6 (a integer signed key auto_increment) ; +insert into t6 values (-2147483648); +insert into t6 values (); +insert into t6 values (0); +insert into t6 values (); +insert into t6 values (2147483647); +insert into t6 values (); +Error 1690 (22003): constant 2147483648 overflows int +select * from t6 order by a; +a +-2147483648 +1 +2 +3 +2147483647 +drop table t6; +create table t7 (a integer unsigned key auto_increment) ; +insert into t7 values (0); +insert into t7 values (); +insert into t7 values (2147483647); +insert into t7 values (); +insert into t7 values (4294967295); +insert into t7 values (); +Error 1690 (22003): constant 4294967296 overflows int +select * from t7 order by a; +a +1 +2 +2147483647 +2147483648 +4294967295 +drop table t7; +create table t8 (a bigint signed key auto_increment) ; +insert into t8 values (-9223372036854775808); +insert into t8 values (); +insert into t8 values (0); +insert into t8 values (); +insert into t8 values (9223372036854775807); +insert into t8 values (); +Error 1467 (HY000): Failed to read auto-increment value from storage engine +select * from t8 order by a; +a +-9223372036854775808 +1 +2 +3 +9223372036854775807 +drop table t8; +create table t9 (a bigint unsigned key auto_increment) ; +insert into t9 values (0); +insert into t9 values (); +insert into t9 values (9223372036854775807); +insert into t9 values (); +select * from t9 order by a; +a +1 +2 +9223372036854775807 +9223372036854775808 +drop table t9; +create table t0 (a tinyint signed key auto_increment) auto_id_cache 1; +insert into t0 values (-128); +insert into t0 values (); +insert into t0 values (0); +insert into t0 values (); +insert into t0 values (127); +insert into t0 values (); +Error 1690 (22003): constant 128 overflows tinyint +select * from t0 order by a; +a +-128 +1 +2 +3 +127 +drop table t0; +create table t1 (a tinyint unsigned key auto_increment) auto_id_cache 1; +insert into t1 values (0); +insert into t1 values (); +insert into t1 values (127); +insert into t1 values (); +insert into t1 values (255); +insert into t1 values (); +Error 1690 (22003): constant 256 overflows tinyint +select * from t1 order by a; +a +1 +2 +127 +128 +255 +drop table t1; +create table t2 (a smallint signed key auto_increment) auto_id_cache 1; +insert into t2 values (-32768); +insert into t2 values (); +insert into t2 values (0); +insert into t2 values (); +insert into t2 values (32767); +insert into t2 values (); +Error 1690 (22003): constant 32768 overflows smallint +select * from t2 order by a; +a +-32768 +1 +2 +3 +32767 +drop table t2; +create table t3 (a smallint unsigned key auto_increment) auto_id_cache 1; +insert into t3 values (0); +insert into t3 values (); +insert into t3 values (32767); +insert into t3 values (); +insert into t3 values (65535); +insert into t3 values (); +Error 1690 (22003): constant 65536 overflows smallint +select * from t3 order by a; +a +1 +2 +32767 +32768 +65535 +drop table t3; +create table t4 (a mediumint signed key auto_increment) auto_id_cache 1; +insert into t4 values (-8388608); +insert into t4 values (); +insert into t4 values (0); +insert into t4 values (); +insert into t4 values (8388607); +insert into t4 values (); +Error 1690 (22003): constant 8388608 overflows mediumint +select * from t4 order by a; +a +-8388608 +1 +2 +3 +8388607 +drop table t4; +create table t5 (a mediumint unsigned key auto_increment) auto_id_cache 1; +insert into t5 values (0); +insert into t5 values (); +insert into t5 values (8388607); +insert into t5 values (); +insert into t5 values (16777215); +insert into t5 values (); +Error 1690 (22003): constant 16777216 overflows mediumint +select * from t5 order by a; +a +1 +2 +8388607 +8388608 +16777215 +drop table t5; +create table t6 (a integer signed key auto_increment) auto_id_cache 1; +insert into t6 values (-2147483648); +insert into t6 values (); +insert into t6 values (0); +insert into t6 values (); +insert into t6 values (2147483647); +insert into t6 values (); +Error 1690 (22003): constant 2147483648 overflows int +select * from t6 order by a; +a +-2147483648 +1 +2 +3 +2147483647 +drop table t6; +create table t7 (a integer unsigned key auto_increment) auto_id_cache 1; +insert into t7 values (0); +insert into t7 values (); +insert into t7 values (2147483647); +insert into t7 values (); +insert into t7 values (4294967295); +insert into t7 values (); +Error 1690 (22003): constant 4294967296 overflows int +select * from t7 order by a; +a +1 +2 +2147483647 +2147483648 +4294967295 +drop table t7; +create table t8 (a bigint signed key auto_increment) auto_id_cache 1; +insert into t8 values (-9223372036854775808); +insert into t8 values (); +insert into t8 values (0); +insert into t8 values (); +insert into t8 values (9223372036854775807); +insert into t8 values (); +Error 1105 (HY000): auto increment action failed +select * from t8 order by a; +a +-9223372036854775808 +1 +2 +3 +9223372036854775807 +drop table t8; +create table t9 (a bigint unsigned key auto_increment) auto_id_cache 1; +insert into t9 values (0); +insert into t9 values (); +insert into t9 values (9223372036854775807); +insert into t9 values (); +select * from t9 order by a; +a +1 +2 +9223372036854775807 +9223372036854775808 +drop table t9; +create table t0 (a tinyint signed key auto_increment) auto_id_cache 100; +insert into t0 values (-128); +insert into t0 values (); +insert into t0 values (0); +insert into t0 values (); +insert into t0 values (127); +insert into t0 values (); +Error 1690 (22003): constant 128 overflows tinyint +select * from t0 order by a; +a +-128 +1 +2 +3 +127 +drop table t0; +create table t1 (a tinyint unsigned key auto_increment) auto_id_cache 100; +insert into t1 values (0); +insert into t1 values (); +insert into t1 values (127); +insert into t1 values (); +insert into t1 values (255); +insert into t1 values (); +Error 1690 (22003): constant 256 overflows tinyint +select * from t1 order by a; +a +1 +2 +127 +128 +255 +drop table t1; +create table t2 (a smallint signed key auto_increment) auto_id_cache 100; +insert into t2 values (-32768); +insert into t2 values (); +insert into t2 values (0); +insert into t2 values (); +insert into t2 values (32767); +insert into t2 values (); +Error 1690 (22003): constant 32768 overflows smallint +select * from t2 order by a; +a +-32768 +1 +2 +3 +32767 +drop table t2; +create table t3 (a smallint unsigned key auto_increment) auto_id_cache 100; +insert into t3 values (0); +insert into t3 values (); +insert into t3 values (32767); +insert into t3 values (); +insert into t3 values (65535); +insert into t3 values (); +Error 1690 (22003): constant 65536 overflows smallint +select * from t3 order by a; +a +1 +2 +32767 +32768 +65535 +drop table t3; +create table t4 (a mediumint signed key auto_increment) auto_id_cache 100; +insert into t4 values (-8388608); +insert into t4 values (); +insert into t4 values (0); +insert into t4 values (); +insert into t4 values (8388607); +insert into t4 values (); +Error 1690 (22003): constant 8388608 overflows mediumint +select * from t4 order by a; +a +-8388608 +1 +2 +3 +8388607 +drop table t4; +create table t5 (a mediumint unsigned key auto_increment) auto_id_cache 100; +insert into t5 values (0); +insert into t5 values (); +insert into t5 values (8388607); +insert into t5 values (); +insert into t5 values (16777215); +insert into t5 values (); +Error 1690 (22003): constant 16777216 overflows mediumint +select * from t5 order by a; +a +1 +2 +8388607 +8388608 +16777215 +drop table t5; +create table t6 (a integer signed key auto_increment) auto_id_cache 100; +insert into t6 values (-2147483648); +insert into t6 values (); +insert into t6 values (0); +insert into t6 values (); +insert into t6 values (2147483647); +insert into t6 values (); +Error 1690 (22003): constant 2147483648 overflows int +select * from t6 order by a; +a +-2147483648 +1 +2 +3 +2147483647 +drop table t6; +create table t7 (a integer unsigned key auto_increment) auto_id_cache 100; +insert into t7 values (0); +insert into t7 values (); +insert into t7 values (2147483647); +insert into t7 values (); +insert into t7 values (4294967295); +insert into t7 values (); +Error 1690 (22003): constant 4294967296 overflows int +select * from t7 order by a; +a +1 +2 +2147483647 +2147483648 +4294967295 +drop table t7; +create table t8 (a bigint signed key auto_increment) auto_id_cache 100; +insert into t8 values (-9223372036854775808); +insert into t8 values (); +insert into t8 values (0); +insert into t8 values (); +insert into t8 values (9223372036854775807); +insert into t8 values (); +Error 1467 (HY000): Failed to read auto-increment value from storage engine +select * from t8 order by a; +a +-9223372036854775808 +1 +2 +3 +9223372036854775807 +drop table t8; +create table t9 (a bigint unsigned key auto_increment) auto_id_cache 100; +insert into t9 values (0); +insert into t9 values (); +insert into t9 values (9223372036854775807); +insert into t9 values (); +select * from t9 order by a; +a +1 +2 +9223372036854775807 +9223372036854775808 +drop table t9; +create table t10 (a integer key auto_increment) auto_id_cache 1; +insert into t10 values (2147483648); +Error 1264 (22003): Out of range value for column 'a' at row 1 +insert into t10 values (-2147483649); +Error 1264 (22003): Out of range value for column 'a' at row 1 +drop table if exists t1, t2, t3, t11, t22, t33; +create table t1 (id int key auto_increment); +insert into t1 values (); +rename table t1 to t11; +insert into t11 values (); +select * from t11; +id +1 +30001 +create table t2 (id int key auto_increment) auto_id_cache 1; +insert into t2 values (); +rename table t2 to t22; +insert into t22 values (); +select * from t22; +id +1 +2 +create table t3 (id int key auto_increment) auto_id_cache 100; +insert into t3 values (); +rename table t3 to t33; +insert into t33 values (); +select * from t33; +id +1 +101 +drop table if exists t0; +create table t0 (id int auto_increment,k int,c char(120)) ; +drop table if exists t1; +create table t1 (id int auto_increment,k int,c char(120)) engine = MyISAM; +drop table if exists t2; +create table t2 (id int auto_increment,k int,c char(120)) engine = InnoDB; +drop table if exists t3; +create table t3 (id int auto_increment,k int,c char(120)) auto_id_cache 1; +drop table if exists t4; +create table t4 (id int auto_increment,k int,c char(120)) auto_id_cache 100; +drop table if exists t5; +create table t5 (id int auto_increment,k int,c char(120),PRIMARY KEY(k, id)) ; +drop table if exists t6; +create table t6 (id int auto_increment,k int,c char(120),PRIMARY KEY(k, id)) engine = MyISAM; +drop table if exists t7; +create table t7 (id int auto_increment,k int,c char(120),PRIMARY KEY(k, id)) engine = InnoDB; +drop table if exists t8; +create table t8 (id int auto_increment,k int,c char(120),PRIMARY KEY(k, id)) auto_id_cache 1; +drop table if exists t9; +create table t9 (id int auto_increment,k int,c char(120),PRIMARY KEY(k, id)) auto_id_cache 100; +drop table if exists t10; +create table t10 (id int auto_increment,k int,c char(120),key idx_1(id)) ; +drop table if exists t11; +create table t11 (id int auto_increment,k int,c char(120),key idx_1(id)) engine = MyISAM; +drop table if exists t12; +create table t12 (id int auto_increment,k int,c char(120),key idx_1(id)) engine = InnoDB; +drop table if exists t13; +create table t13 (id int auto_increment,k int,c char(120),key idx_1(id)) auto_id_cache 1; +drop table if exists t14; +create table t14 (id int auto_increment,k int,c char(120),key idx_1(id)) auto_id_cache 100; +drop table if exists t15; +create table t15 (id int auto_increment,k int,c char(120),PRIMARY KEY(`k`, `id`), key idx_1(id)) ; +drop table if exists t16; +create table t16 (id int auto_increment,k int,c char(120),PRIMARY KEY(`k`, `id`), key idx_1(id)) engine = MyISAM; +drop table if exists t17; +create table t17 (id int auto_increment,k int,c char(120),PRIMARY KEY(`k`, `id`), key idx_1(id)) engine = InnoDB; +drop table if exists t18; +create table t18 (id int auto_increment,k int,c char(120),PRIMARY KEY(`k`, `id`), key idx_1(id)) auto_id_cache 1; +drop table if exists t19; +create table t19 (id int auto_increment,k int,c char(120),PRIMARY KEY(`k`, `id`), key idx_1(id)) auto_id_cache 100; +create table tt1 (id int); +alter table tt1 add column (c int auto_increment); +Error 8200 (HY000): unsupported add column 'c' constraint AUTO_INCREMENT when altering 'executor__autoid.tt1' +create table tt2 (id int, c int auto_increment, key c_idx(c)); +alter table tt2 drop index c_idx; +drop table if exists t_473; +create table t_473 (id int key auto_increment); +insert into t_473 values (); +select * from t_473; +id +1 +show table t_473 next_row_id; +DB_NAME TABLE_NAME COLUMN_NAME NEXT_GLOBAL_ROW_ID ID_TYPE +executor__autoid t_473 id 30001 _TIDB_ROWID +executor__autoid t_473 id 1 AUTO_INCREMENT +alter table t_473 auto_id_cache = 100; +show table t_473 next_row_id; +DB_NAME TABLE_NAME COLUMN_NAME NEXT_GLOBAL_ROW_ID ID_TYPE +executor__autoid t_473 id 30001 _TIDB_ROWID +executor__autoid t_473 id 1 AUTO_INCREMENT +insert into t_473 values (); +select * from t_473; +id +1 +30001 +show table t_473 next_row_id; +DB_NAME TABLE_NAME COLUMN_NAME NEXT_GLOBAL_ROW_ID ID_TYPE +executor__autoid t_473 id 30101 _TIDB_ROWID +executor__autoid t_473 id 1 AUTO_INCREMENT +alter table t_473 auto_id_cache = 1; +Error 1105 (HY000): Can't Alter AUTO_ID_CACHE between 1 and non-1, the underlying implementation is different diff --git a/tests/integrationtest/t/executor/autoid.test b/tests/integrationtest/t/executor/autoid.test new file mode 100644 index 0000000000000..0d23f87a8245b --- /dev/null +++ b/tests/integrationtest/t/executor/autoid.test @@ -0,0 +1,392 @@ +# TestAutoIncrementInsertMinMax +drop table if exists t0, t1, t2, t3, t4, t5, t6, t7, t8, t9; +create table t0 (a tinyint signed key auto_increment) ; +insert into t0 values (-128); +insert into t0 values (); +insert into t0 values (0); +insert into t0 values (); +insert into t0 values (127); +-- error 1690 +insert into t0 values (); +select * from t0 order by a; +drop table t0; +create table t1 (a tinyint unsigned key auto_increment) ; +insert into t1 values (0); +insert into t1 values (); +insert into t1 values (127); +insert into t1 values (); +insert into t1 values (255); +-- error 1690 +insert into t1 values (); +select * from t1 order by a; +drop table t1; +create table t2 (a smallint signed key auto_increment) ; +insert into t2 values (-32768); +insert into t2 values (); +insert into t2 values (0); +insert into t2 values (); +insert into t2 values (32767); +-- error 1690 +insert into t2 values (); +select * from t2 order by a; +drop table t2; +create table t3 (a smallint unsigned key auto_increment) ; +insert into t3 values (0); +insert into t3 values (); +insert into t3 values (32767); +insert into t3 values (); +insert into t3 values (65535); +-- error 1690 +insert into t3 values (); +select * from t3 order by a; +drop table t3; +create table t4 (a mediumint signed key auto_increment) ; +insert into t4 values (-8388608); +insert into t4 values (); +insert into t4 values (0); +insert into t4 values (); +insert into t4 values (8388607); +-- error 1690 +insert into t4 values (); +select * from t4 order by a; +drop table t4; +create table t5 (a mediumint unsigned key auto_increment) ; +insert into t5 values (0); +insert into t5 values (); +insert into t5 values (8388607); +insert into t5 values (); +insert into t5 values (16777215); +-- error 1690 +insert into t5 values (); +select * from t5 order by a; +drop table t5; +create table t6 (a integer signed key auto_increment) ; +insert into t6 values (-2147483648); +insert into t6 values (); +insert into t6 values (0); +insert into t6 values (); +insert into t6 values (2147483647); +-- error 1690 +insert into t6 values (); +select * from t6 order by a; +drop table t6; +create table t7 (a integer unsigned key auto_increment) ; +insert into t7 values (0); +insert into t7 values (); +insert into t7 values (2147483647); +insert into t7 values (); +insert into t7 values (4294967295); +-- error 1690 +insert into t7 values (); +select * from t7 order by a; +drop table t7; +create table t8 (a bigint signed key auto_increment) ; +insert into t8 values (-9223372036854775808); +insert into t8 values (); +insert into t8 values (0); +insert into t8 values (); +insert into t8 values (9223372036854775807); +-- error 1467 +insert into t8 values (); +select * from t8 order by a; +drop table t8; +create table t9 (a bigint unsigned key auto_increment) ; +insert into t9 values (0); +insert into t9 values (); +insert into t9 values (9223372036854775807); +insert into t9 values (); +select * from t9 order by a; +drop table t9; +create table t0 (a tinyint signed key auto_increment) auto_id_cache 1; +insert into t0 values (-128); +insert into t0 values (); +insert into t0 values (0); +insert into t0 values (); +insert into t0 values (127); +-- error 1690 +insert into t0 values (); +select * from t0 order by a; +drop table t0; +create table t1 (a tinyint unsigned key auto_increment) auto_id_cache 1; +insert into t1 values (0); +insert into t1 values (); +insert into t1 values (127); +insert into t1 values (); +insert into t1 values (255); +-- error 1690 +insert into t1 values (); +select * from t1 order by a; +drop table t1; +create table t2 (a smallint signed key auto_increment) auto_id_cache 1; +insert into t2 values (-32768); +insert into t2 values (); +insert into t2 values (0); +insert into t2 values (); +insert into t2 values (32767); +-- error 1690 +insert into t2 values (); +select * from t2 order by a; +drop table t2; +create table t3 (a smallint unsigned key auto_increment) auto_id_cache 1; +insert into t3 values (0); +insert into t3 values (); +insert into t3 values (32767); +insert into t3 values (); +insert into t3 values (65535); +-- error 1690 +insert into t3 values (); +select * from t3 order by a; +drop table t3; +create table t4 (a mediumint signed key auto_increment) auto_id_cache 1; +insert into t4 values (-8388608); +insert into t4 values (); +insert into t4 values (0); +insert into t4 values (); +insert into t4 values (8388607); +-- error 1690 +insert into t4 values (); +select * from t4 order by a; +drop table t4; +create table t5 (a mediumint unsigned key auto_increment) auto_id_cache 1; +insert into t5 values (0); +insert into t5 values (); +insert into t5 values (8388607); +insert into t5 values (); +insert into t5 values (16777215); +-- error 1690 +insert into t5 values (); +select * from t5 order by a; +drop table t5; +create table t6 (a integer signed key auto_increment) auto_id_cache 1; +insert into t6 values (-2147483648); +insert into t6 values (); +insert into t6 values (0); +insert into t6 values (); +insert into t6 values (2147483647); +-- error 1690 +insert into t6 values (); +select * from t6 order by a; +drop table t6; +create table t7 (a integer unsigned key auto_increment) auto_id_cache 1; +insert into t7 values (0); +insert into t7 values (); +insert into t7 values (2147483647); +insert into t7 values (); +insert into t7 values (4294967295); +-- error 1690 +insert into t7 values (); +select * from t7 order by a; +drop table t7; +create table t8 (a bigint signed key auto_increment) auto_id_cache 1; +insert into t8 values (-9223372036854775808); +insert into t8 values (); +insert into t8 values (0); +insert into t8 values (); +insert into t8 values (9223372036854775807); +-- error 1105 +insert into t8 values (); +select * from t8 order by a; +drop table t8; +create table t9 (a bigint unsigned key auto_increment) auto_id_cache 1; +insert into t9 values (0); +insert into t9 values (); +insert into t9 values (9223372036854775807); +insert into t9 values (); +select * from t9 order by a; +drop table t9; +create table t0 (a tinyint signed key auto_increment) auto_id_cache 100; +insert into t0 values (-128); +insert into t0 values (); +insert into t0 values (0); +insert into t0 values (); +insert into t0 values (127); +-- error 1690 +insert into t0 values (); +select * from t0 order by a; +drop table t0; +create table t1 (a tinyint unsigned key auto_increment) auto_id_cache 100; +insert into t1 values (0); +insert into t1 values (); +insert into t1 values (127); +insert into t1 values (); +insert into t1 values (255); +-- error 1690 +insert into t1 values (); +select * from t1 order by a; +drop table t1; +create table t2 (a smallint signed key auto_increment) auto_id_cache 100; +insert into t2 values (-32768); +insert into t2 values (); +insert into t2 values (0); +insert into t2 values (); +insert into t2 values (32767); +-- error 1690 +insert into t2 values (); +select * from t2 order by a; +drop table t2; +create table t3 (a smallint unsigned key auto_increment) auto_id_cache 100; +insert into t3 values (0); +insert into t3 values (); +insert into t3 values (32767); +insert into t3 values (); +insert into t3 values (65535); +-- error 1690 +insert into t3 values (); +select * from t3 order by a; +drop table t3; +create table t4 (a mediumint signed key auto_increment) auto_id_cache 100; +insert into t4 values (-8388608); +insert into t4 values (); +insert into t4 values (0); +insert into t4 values (); +insert into t4 values (8388607); +-- error 1690 +insert into t4 values (); +select * from t4 order by a; +drop table t4; +create table t5 (a mediumint unsigned key auto_increment) auto_id_cache 100; +insert into t5 values (0); +insert into t5 values (); +insert into t5 values (8388607); +insert into t5 values (); +insert into t5 values (16777215); +-- error 1690 +insert into t5 values (); +select * from t5 order by a; +drop table t5; +create table t6 (a integer signed key auto_increment) auto_id_cache 100; +insert into t6 values (-2147483648); +insert into t6 values (); +insert into t6 values (0); +insert into t6 values (); +insert into t6 values (2147483647); +-- error 1690 +insert into t6 values (); +select * from t6 order by a; +drop table t6; +create table t7 (a integer unsigned key auto_increment) auto_id_cache 100; +insert into t7 values (0); +insert into t7 values (); +insert into t7 values (2147483647); +insert into t7 values (); +insert into t7 values (4294967295); +-- error 1690 +insert into t7 values (); +select * from t7 order by a; +drop table t7; +create table t8 (a bigint signed key auto_increment) auto_id_cache 100; +insert into t8 values (-9223372036854775808); +insert into t8 values (); +insert into t8 values (0); +insert into t8 values (); +insert into t8 values (9223372036854775807); +-- error 1467 +insert into t8 values (); +select * from t8 order by a; +drop table t8; +create table t9 (a bigint unsigned key auto_increment) auto_id_cache 100; +insert into t9 values (0); +insert into t9 values (); +insert into t9 values (9223372036854775807); +insert into t9 values (); +select * from t9 order by a; +drop table t9; +create table t10 (a integer key auto_increment) auto_id_cache 1; +-- error 1264 +insert into t10 values (2147483648); +-- error 1264 +insert into t10 values (-2147483649); + +# TestRenameTableForAutoIncrement +drop table if exists t1, t2, t3, t11, t22, t33; +create table t1 (id int key auto_increment); +insert into t1 values (); +rename table t1 to t11; +insert into t11 values (); +## TODO(tiancaiamao): fix bug and uncomment here, rename table should not discard the cached AUTO_ID. +select * from t11; + +## auto_id_cache 1 use another implementation and do not have such bug. +create table t2 (id int key auto_increment) auto_id_cache 1; +insert into t2 values (); +rename table t2 to t22; +insert into t22 values (); +select * from t22; + +create table t3 (id int key auto_increment) auto_id_cache 100; +insert into t3 values (); +rename table t3 to t33; +insert into t33 values (); +## TODO(tiancaiamao): fix bug and uncomment here, rename table should not discard the cached AUTO_ID. +select * from t33; + +# TestAutoIDConstraint +# Remove the constraint that auto id column must be defined as a key +# See https://github.com/pingcap/tidb/issues/40580 +drop table if exists t0; +create table t0 (id int auto_increment,k int,c char(120)) ; +drop table if exists t1; +create table t1 (id int auto_increment,k int,c char(120)) engine = MyISAM; +drop table if exists t2; +create table t2 (id int auto_increment,k int,c char(120)) engine = InnoDB; +drop table if exists t3; +create table t3 (id int auto_increment,k int,c char(120)) auto_id_cache 1; +drop table if exists t4; +create table t4 (id int auto_increment,k int,c char(120)) auto_id_cache 100; +drop table if exists t5; +create table t5 (id int auto_increment,k int,c char(120),PRIMARY KEY(k, id)) ; +drop table if exists t6; +create table t6 (id int auto_increment,k int,c char(120),PRIMARY KEY(k, id)) engine = MyISAM; +drop table if exists t7; +create table t7 (id int auto_increment,k int,c char(120),PRIMARY KEY(k, id)) engine = InnoDB; +drop table if exists t8; +create table t8 (id int auto_increment,k int,c char(120),PRIMARY KEY(k, id)) auto_id_cache 1; +drop table if exists t9; +create table t9 (id int auto_increment,k int,c char(120),PRIMARY KEY(k, id)) auto_id_cache 100; +drop table if exists t10; +create table t10 (id int auto_increment,k int,c char(120),key idx_1(id)) ; +drop table if exists t11; +create table t11 (id int auto_increment,k int,c char(120),key idx_1(id)) engine = MyISAM; +drop table if exists t12; +create table t12 (id int auto_increment,k int,c char(120),key idx_1(id)) engine = InnoDB; +drop table if exists t13; +create table t13 (id int auto_increment,k int,c char(120),key idx_1(id)) auto_id_cache 1; +drop table if exists t14; +create table t14 (id int auto_increment,k int,c char(120),key idx_1(id)) auto_id_cache 100; +drop table if exists t15; +create table t15 (id int auto_increment,k int,c char(120),PRIMARY KEY(`k`, `id`), key idx_1(id)) ; +drop table if exists t16; +create table t16 (id int auto_increment,k int,c char(120),PRIMARY KEY(`k`, `id`), key idx_1(id)) engine = MyISAM; +drop table if exists t17; +create table t17 (id int auto_increment,k int,c char(120),PRIMARY KEY(`k`, `id`), key idx_1(id)) engine = InnoDB; +drop table if exists t18; +create table t18 (id int auto_increment,k int,c char(120),PRIMARY KEY(`k`, `id`), key idx_1(id)) auto_id_cache 1; +drop table if exists t19; +create table t19 (id int auto_increment,k int,c char(120),PRIMARY KEY(`k`, `id`), key idx_1(id)) auto_id_cache 100; + +## alter table add auto id column is not supported, but cover it here to prevent regression +create table tt1 (id int); +-- error 8200 +alter table tt1 add column (c int auto_increment); + +## Cover case: create table with auto id column as key, and remove it later +create table tt2 (id int, c int auto_increment, key c_idx(c)); +alter table tt2 drop index c_idx; + +# TestAlterTableAutoIDCache +drop table if exists t_473; +create table t_473 (id int key auto_increment); +insert into t_473 values (); +select * from t_473; +show table t_473 next_row_id; +alter table t_473 auto_id_cache = 100; +show table t_473 next_row_id; +insert into t_473 values (); +select * from t_473; +show table t_473 next_row_id; + +## Note that auto_id_cache=1 use a different implementation, switch between them is not allowed. +## TODO: relax this restriction and update the test case. +-- error 1105 +alter table t_473 auto_id_cache = 1; + From 5a451d88939f0c59cc910cf133c23e0ef0299f0c Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Wed, 1 Nov 2023 15:51:49 +0800 Subject: [PATCH 3/8] update stale_txn --- pkg/executor/stale_txn_test.go | 44 ------------------- .../r/executor/stale_txn.result | 38 ++++++++++++++++ .../integrationtest/t/executor/stale_txn.test | 34 ++++++++++++++ 3 files changed, 72 insertions(+), 44 deletions(-) create mode 100644 tests/integrationtest/r/executor/stale_txn.result create mode 100644 tests/integrationtest/t/executor/stale_txn.test diff --git a/pkg/executor/stale_txn_test.go b/pkg/executor/stale_txn_test.go index ca743c9bd55a0..4b30125453be9 100644 --- a/pkg/executor/stale_txn_test.go +++ b/pkg/executor/stale_txn_test.go @@ -1315,23 +1315,6 @@ func TestPlanCacheWithStaleReadByBinaryProto(t *testing.T) { tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 10")) } -func TestIssue30872(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set tidb_txn_mode='pessimistic'") - tk.MustExec("set tx_isolation = 'READ-COMMITTED'") - tk.MustExec("create table t1 (id int primary key, v int)") - tk.MustExec("insert into t1 values(1, 10)") - time.Sleep(time.Millisecond * 100) - tk.MustExec("set @a=now(6)") - time.Sleep(time.Millisecond * 100) - tk.MustExec("update t1 set v=100 where id=1") - tk.MustExec("set autocommit=0") - tk.MustQuery("select * from t1 as of timestamp @a").Check(testkit.Rows("1 10")) -} - func TestIssue33728(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1347,33 +1330,6 @@ func TestIssue33728(t *testing.T) { require.Equal(t, "[planner:8135]invalid as of timestamp: as of timestamp cannot be NULL", err.Error()) } -func TestIssue31954(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t1 (id int primary key, v int)") - tk.MustExec("insert into t1 values(1, 10)") - time.Sleep(time.Millisecond * 100) - tk.MustExec("set @a=now(6)") - time.Sleep(time.Millisecond * 100) - tk.MustExec("update t1 set v=100 where id=1") - - tk.MustQuery("select * from t1 as of timestamp @a where v=(select v from t1 as of timestamp @a where id=1)"). - Check(testkit.Rows("1 10")) - - tk.MustQuery("select (select v from t1 as of timestamp @a where id=1) as v"). - Check(testkit.Rows("10")) -} - -func TestIssue35686(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - // This query should not panic - tk.MustQuery("select * from information_schema.ddl_jobs as of timestamp now()") -} - func TestStalePrepare(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/tests/integrationtest/r/executor/stale_txn.result b/tests/integrationtest/r/executor/stale_txn.result new file mode 100644 index 0000000000000..62fe1e43c62c5 --- /dev/null +++ b/tests/integrationtest/r/executor/stale_txn.result @@ -0,0 +1,38 @@ +select * from information_schema.ddl_jobs as of timestamp now(); +drop table if exists t1; +create table t1 (id int primary key, v int); +insert into t1 values(1, 10); +select sleep(0.1); +sleep(0.1) +0 +set @a=now(6); +select sleep(0.1); +sleep(0.1) +0 +update t1 set v=100 where id=1; +select * from t1 as of timestamp @a where v=(select v from t1 as of timestamp @a where id=1); +id v +1 10 +select (select v from t1 as of timestamp @a where id=1) as v; +v +10 +set tidb_txn_mode='pessimistic'; +set tx_isolation = 'READ-COMMITTED'; +drop table if exists t1; +create table t1 (id int primary key, v int); +insert into t1 values(1, 10); +select sleep(0.01); +sleep(0.01) +0 +set @a=now(6); +select sleep(0.01); +sleep(0.01) +0 +update t1 set v=100 where id=1; +set autocommit=0; +select * from t1 as of timestamp @a; +id v +1 10 +set tidb_txn_mode = default; +set tx_isolation = default; +set autocommit = default; diff --git a/tests/integrationtest/t/executor/stale_txn.test b/tests/integrationtest/t/executor/stale_txn.test new file mode 100644 index 0000000000000..10bf954ab3f3b --- /dev/null +++ b/tests/integrationtest/t/executor/stale_txn.test @@ -0,0 +1,34 @@ +# TestIssue35686 +## This query should not panic +--disable_result_log +select * from information_schema.ddl_jobs as of timestamp now(); +--enable_result_log + +# TestIssue31954 +drop table if exists t1; +create table t1 (id int primary key, v int); +insert into t1 values(1, 10); +select sleep(0.1); +set @a=now(6); +select sleep(0.1); +update t1 set v=100 where id=1; +select * from t1 as of timestamp @a where v=(select v from t1 as of timestamp @a where id=1); +select (select v from t1 as of timestamp @a where id=1) as v; + +# TestIssue30872 +set tidb_txn_mode='pessimistic'; +set tx_isolation = 'READ-COMMITTED'; +drop table if exists t1; +create table t1 (id int primary key, v int); +insert into t1 values(1, 10); +select sleep(0.01); +set @a=now(6); +select sleep(0.01); +update t1 set v=100 where id=1; +set autocommit=0; +select * from t1 as of timestamp @a; + +set tidb_txn_mode = default; +set tx_isolation = default; +set autocommit = default; + From 3644e0e1f6b24220ec76e408af495b14d8c08f0a Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Wed, 1 Nov 2023 16:33:31 +0800 Subject: [PATCH 4/8] update analyze --- pkg/executor/test/analyzetest/BUILD.bazel | 2 +- pkg/executor/test/analyzetest/analyze_test.go | 102 +---------------- .../integrationtest/r/executor/analyze.result | 96 ++++++++++++++++ tests/integrationtest/t/executor/analyze.test | 104 ++++++++++++++++++ 4 files changed, 204 insertions(+), 100 deletions(-) diff --git a/pkg/executor/test/analyzetest/BUILD.bazel b/pkg/executor/test/analyzetest/BUILD.bazel index f3504f59f6e80..5f37de422e445 100644 --- a/pkg/executor/test/analyzetest/BUILD.bazel +++ b/pkg/executor/test/analyzetest/BUILD.bazel @@ -9,7 +9,7 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 50, + shard_count = 48, deps = [ "//pkg/config", "//pkg/domain", diff --git a/pkg/executor/test/analyzetest/analyze_test.go b/pkg/executor/test/analyzetest/analyze_test.go index 59de964d96ace..6fa02510e342b 100644 --- a/pkg/executor/test/analyzetest/analyze_test.go +++ b/pkg/executor/test/analyzetest/analyze_test.go @@ -122,38 +122,6 @@ func TestAnalyzeReplicaReadFollower(t *testing.T) { ctx.GetSessionVars().SetReplicaRead(kv.ReplicaReadFollower) tk.MustExec("analyze table t") } - -func TestClusterIndexAnalyze(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("drop database if exists test_cluster_index_analyze;") - tk.MustExec("create database test_cluster_index_analyze;") - tk.MustExec("use test_cluster_index_analyze;") - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - - tk.MustExec("create table t (a int, b int, c int, primary key(a, b));") - for i := 0; i < 100; i++ { - tk.MustExec("insert into t values (?, ?, ?)", i, i, i) - } - tk.MustExec("analyze table t;") - tk.MustExec("drop table t;") - - tk.MustExec("create table t (a varchar(255), b int, c float, primary key(c, a));") - for i := 0; i < 100; i++ { - tk.MustExec("insert into t values (?, ?, ?)", strconv.Itoa(i), i, i) - } - tk.MustExec("analyze table t;") - tk.MustExec("drop table t;") - - tk.MustExec("create table t (a char(10), b decimal(5, 3), c int, primary key(a, c, b));") - for i := 0; i < 100; i++ { - tk.MustExec("insert into t values (?, ?, ?)", strconv.Itoa(i), i, i) - } - tk.MustExec("analyze table t;") - tk.MustExec("drop table t;") -} - func TestAnalyzeRestrict(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -246,28 +214,6 @@ func TestAnalyzeTooLongColumns(t *testing.T) { require.Equal(t, int64(65559), tbl.Columns[1].TotColSize) } -func TestAnlyzeIssue(t *testing.T) { - // Issue15993 - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_analyze_version = 1") - tk.MustExec("use test") - tk.MustExec("drop table if exists t0") - tk.MustExec("CREATE TABLE t0(c0 INT PRIMARY KEY);") - tk.MustExec("ANALYZE TABLE t0 INDEX PRIMARY;") - // Issue15751 - tk.MustExec("drop table if exists t0") - tk.MustExec("CREATE TABLE t0(c0 INT, c1 INT, PRIMARY KEY(c0, c1))") - tk.MustExec("INSERT INTO t0 VALUES (0, 0)") - tk.MustExec("ANALYZE TABLE t0") - // Issue15752 - tk.MustExec("drop table if exists t0") - tk.MustExec("CREATE TABLE t0(c0 INT)") - tk.MustExec("INSERT INTO t0 VALUES (0)") - tk.MustExec("CREATE INDEX i0 ON t0(c0)") - tk.MustExec("ANALYZE TABLE t0 INDEX i0") -} - func TestFailedAnalyzeRequest(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1517,34 +1463,6 @@ func TestAnalyzeColumnsWithDynamicPartitionTable(t *testing.T) { } } -func TestIssue34228(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec(`USE test`) - tk.MustExec(`DROP TABLE IF EXISTS Issue34228`) - tk.MustExec(`CREATE TABLE Issue34228 (id bigint NOT NULL, dt datetime NOT NULL) PARTITION BY RANGE COLUMNS(dt) (PARTITION p202201 VALUES LESS THAN ("2022-02-01"), PARTITION p202202 VALUES LESS THAN ("2022-03-01"))`) - tk.MustExec(`INSERT INTO Issue34228 VALUES (1, '2022-02-01 00:00:02'), (2, '2022-02-01 00:00:02')`) - tk.MustExec(`SET @@global.tidb_analyze_version = 1`) - tk.MustExec(`SET @@session.tidb_partition_prune_mode = 'static'`) - tk.MustExec(`ANALYZE TABLE Issue34228`) - tk.MustExec(`SET @@session.tidb_partition_prune_mode = 'dynamic'`) - tk.MustExec(`ANALYZE TABLE Issue34228`) - tk.MustQuery(`SELECT * FROM Issue34228`).Sort().Check(testkit.Rows("1 2022-02-01 00:00:02", "2 2022-02-01 00:00:02")) - // Needs a second run to hit the issue - tk2 := testkit.NewTestKit(t, store) - tk2.MustExec(`USE test`) - tk2.MustExec(`DROP TABLE IF EXISTS Issue34228`) - tk2.MustExec(`CREATE TABLE Issue34228 (id bigint NOT NULL, dt datetime NOT NULL) PARTITION BY RANGE COLUMNS(dt) (PARTITION p202201 VALUES LESS THAN ("2022-02-01"), PARTITION p202202 VALUES LESS THAN ("2022-03-01"))`) - tk2.MustExec(`INSERT INTO Issue34228 VALUES (1, '2022-02-01 00:00:02'), (2, '2022-02-01 00:00:02')`) - tk2.MustExec(`SET @@global.tidb_analyze_version = 1`) - tk2.MustExec(`SET @@session.tidb_partition_prune_mode = 'static'`) - tk2.MustExec(`ANALYZE TABLE Issue34228`) - tk2.MustExec(`SET @@session.tidb_partition_prune_mode = 'dynamic'`) - tk2.MustExec(`ANALYZE TABLE Issue34228`) - tk2.MustQuery(`SELECT * FROM Issue34228`).Sort().Check(testkit.Rows("1 2022-02-01 00:00:02", "2 2022-02-01 00:00:02")) -} - func TestAnalyzeColumnsWithStaticPartitionTable(t *testing.T) { for _, val := range []model.ColumnChoice{model.ColumnList, model.PredicateColumns} { func(choice model.ColumnChoice) { @@ -2037,11 +1955,10 @@ func testKillAutoAnalyze(t *testing.T, ver int) { } } -func TestKillAutoAnalyzeV1(t *testing.T) { +func TestKillAutoAnalyze(t *testing.T) { + // version 1 testKillAutoAnalyze(t, 1) -} - -func TestKillAutoAnalyzeV2(t *testing.T) { + // version 2 testKillAutoAnalyze(t, 2) } @@ -2874,19 +2791,6 @@ func TestAnalyzeColumnsSkipMVIndexJsonCol(t *testing.T) { require.False(t, stats.Indices[tblInfo.Indices[1].ID].IsStatsInitialized()) } -func TestManualAnalyzeSkipColumnTypes(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a int, b int, c json, d text, e mediumtext, f blob, g mediumblob, index idx(d(10)))") - tk.MustExec("set @@session.tidb_analyze_skip_column_types = 'json,blob,mediumblob,text,mediumtext'") - tk.MustExec("analyze table t") - tk.MustQuery("select job_info from mysql.analyze_jobs where job_info like '%analyze table%'").Check(testkit.Rows("analyze table columns a, b, d with 256 buckets, 500 topn, 1 samplerate")) - tk.MustExec("delete from mysql.analyze_jobs") - tk.MustExec("analyze table t columns a, e") - tk.MustQuery("select job_info from mysql.analyze_jobs where job_info like '%analyze table%'").Check(testkit.Rows("analyze table columns a, d with 256 buckets, 500 topn, 1 samplerate")) -} - // TestAnalyzeMVIndex tests analyzing the mv index use some real data in the table. // It checks the analyze jobs, async loading and the stats content in the memory. func TestAnalyzeMVIndex(t *testing.T) { diff --git a/tests/integrationtest/r/executor/analyze.result b/tests/integrationtest/r/executor/analyze.result index e3a48d683dbbf..3762068660eb4 100644 --- a/tests/integrationtest/r/executor/analyze.result +++ b/tests/integrationtest/r/executor/analyze.result @@ -761,3 +761,99 @@ drop table if exists t; create table t(a int, b int, primary key(a), index idx(b)) partition by range(a) (partition p0 values less than (10), partition p1 values less than (20)); analyze incremental table t partition p0 index idx; Error 1105 (HY000): the incremental analyze feature has already been removed in TiDB v7.5.0, so this will have no effect +drop table if exists t; +set tidb_enable_clustered_index=on; +create table t (a int, b int, c int, primary key(a, b)); +insert into t values (0, 0, 0); +insert into t values (1, 1, 1); +insert into t values (2, 2, 2); +insert into t values (3, 3, 3); +insert into t values (4, 4, 4); +insert into t values (5, 5, 5); +insert into t values (6, 6, 6); +insert into t values (7, 7, 7); +insert into t values (8, 8, 8); +insert into t values (9, 9, 9); +analyze table t; +drop table t; +create table t (a varchar(255), b int, c float, primary key(c, a)); +insert into t values (0, 0, 0); +insert into t values (1, 1, 1); +insert into t values (2, 2, 2); +insert into t values (3, 3, 3); +insert into t values (4, 4, 4); +insert into t values (5, 5, 5); +insert into t values (6, 6, 6); +insert into t values (7, 7, 7); +insert into t values (8, 8, 8); +insert into t values (9, 9, 9); +analyze table t; +drop table t; +create table t (a char(10), b decimal(5, 3), c int, primary key(a, c, b)); +insert into t values (0, 0, 0); +insert into t values (1, 1, 1); +insert into t values (2, 2, 2); +insert into t values (3, 3, 3); +insert into t values (4, 4, 4); +insert into t values (5, 5, 5); +insert into t values (6, 6, 6); +insert into t values (7, 7, 7); +insert into t values (8, 8, 8); +insert into t values (9, 9, 9); +analyze table t; +drop table t; +set tidb_enable_clustered_index=default; +set @@tidb_analyze_version = 1; +drop table if exists t0; +CREATE TABLE t0(c0 INT PRIMARY KEY); +ANALYZE TABLE t0 INDEX PRIMARY; +drop table if exists t0; +CREATE TABLE t0(c0 INT, c1 INT, PRIMARY KEY(c0, c1)); +INSERT INTO t0 VALUES (0, 0); +ANALYZE TABLE t0; +drop table if exists t0; +CREATE TABLE t0(c0 INT); +INSERT INTO t0 VALUES (0); +CREATE INDEX i0 ON t0(c0); +ANALYZE TABLE t0 INDEX i0; +set @@tidb_analyze_version = default; +drop table if exists t; +create table t(a int, b int, c json, d text, e mediumtext, f blob, g mediumblob, index idx(d(10))); +set @@session.tidb_analyze_skip_column_types = 'json,blob,mediumblob,text,mediumtext'; +delete from mysql.analyze_jobs; +analyze table t; +select job_info from mysql.analyze_jobs where job_info like '%analyze table%'; +job_info +analyze table columns a, b, d with 256 buckets, 500 topn, 1 samplerate +delete from mysql.analyze_jobs; +analyze table t columns a, e; +select job_info from mysql.analyze_jobs where job_info like '%analyze table%'; +job_info +analyze table columns a, d with 256 buckets, 500 topn, 1 samplerate +set @@session.tidb_analyze_skip_column_types = default; +DROP TABLE IF EXISTS Issue34228; +CREATE TABLE Issue34228 (id bigint NOT NULL, dt datetime NOT NULL) PARTITION BY RANGE COLUMNS(dt) (PARTITION p202201 VALUES LESS THAN ("2022-02-01"), PARTITION p202202 VALUES LESS THAN ("2022-03-01")); +INSERT INTO Issue34228 VALUES (1, '2022-02-01 00:00:02'), (2, '2022-02-01 00:00:02'); +SET @@global.tidb_analyze_version = 1; +SET @@session.tidb_partition_prune_mode = 'static'; +ANALYZE TABLE Issue34228; +SET @@session.tidb_partition_prune_mode = 'dynamic'; +ANALYZE TABLE Issue34228; +SELECT * FROM Issue34228; +id dt +1 2022-02-01 00:00:02 +2 2022-02-01 00:00:02 +DROP TABLE IF EXISTS Issue34228; +CREATE TABLE Issue34228 (id bigint NOT NULL, dt datetime NOT NULL) PARTITION BY RANGE COLUMNS(dt) (PARTITION p202201 VALUES LESS THAN ("2022-02-01"), PARTITION p202202 VALUES LESS THAN ("2022-03-01")); +INSERT INTO Issue34228 VALUES (1, '2022-02-01 00:00:02'), (2, '2022-02-01 00:00:02'); +SET @@global.tidb_analyze_version = 1; +SET @@session.tidb_partition_prune_mode = 'static'; +ANALYZE TABLE Issue34228; +SET @@session.tidb_partition_prune_mode = 'dynamic'; +ANALYZE TABLE Issue34228; +SELECT * FROM Issue34228; +id dt +1 2022-02-01 00:00:02 +2 2022-02-01 00:00:02 +SET @@global.tidb_analyze_version = default; +SET @@session.tidb_partition_prune_mode = default; diff --git a/tests/integrationtest/t/executor/analyze.test b/tests/integrationtest/t/executor/analyze.test index 5aeb03207acdd..f4b0aa789ee56 100644 --- a/tests/integrationtest/t/executor/analyze.test +++ b/tests/integrationtest/t/executor/analyze.test @@ -829,3 +829,107 @@ create table t(a int, b int, primary key(a), index idx(b)) partition by range(a) -- error 1105 analyze incremental table t partition p0 index idx; +# TestClusterIndexAnalyze +drop table if exists t; +set tidb_enable_clustered_index=on; +create table t (a int, b int, c int, primary key(a, b)); +insert into t values (0, 0, 0); +insert into t values (1, 1, 1); +insert into t values (2, 2, 2); +insert into t values (3, 3, 3); +insert into t values (4, 4, 4); +insert into t values (5, 5, 5); +insert into t values (6, 6, 6); +insert into t values (7, 7, 7); +insert into t values (8, 8, 8); +insert into t values (9, 9, 9); +analyze table t; +drop table t; +create table t (a varchar(255), b int, c float, primary key(c, a)); +insert into t values (0, 0, 0); +insert into t values (1, 1, 1); +insert into t values (2, 2, 2); +insert into t values (3, 3, 3); +insert into t values (4, 4, 4); +insert into t values (5, 5, 5); +insert into t values (6, 6, 6); +insert into t values (7, 7, 7); +insert into t values (8, 8, 8); +insert into t values (9, 9, 9); +analyze table t; +drop table t; +create table t (a char(10), b decimal(5, 3), c int, primary key(a, c, b)); +insert into t values (0, 0, 0); +insert into t values (1, 1, 1); +insert into t values (2, 2, 2); +insert into t values (3, 3, 3); +insert into t values (4, 4, 4); +insert into t values (5, 5, 5); +insert into t values (6, 6, 6); +insert into t values (7, 7, 7); +insert into t values (8, 8, 8); +insert into t values (9, 9, 9); +analyze table t; +drop table t; +set tidb_enable_clustered_index=default; + +# TestAnlyzeIssue +set @@tidb_analyze_version = 1; +## Issue15993 +drop table if exists t0; +CREATE TABLE t0(c0 INT PRIMARY KEY); +ANALYZE TABLE t0 INDEX PRIMARY; +## Issue15751 +drop table if exists t0; +CREATE TABLE t0(c0 INT, c1 INT, PRIMARY KEY(c0, c1)); +INSERT INTO t0 VALUES (0, 0); +ANALYZE TABLE t0; +## Issue15752 +drop table if exists t0; +CREATE TABLE t0(c0 INT); +INSERT INTO t0 VALUES (0); +CREATE INDEX i0 ON t0(c0); +ANALYZE TABLE t0 INDEX i0; +set @@tidb_analyze_version = default; + +# TestManualAnalyzeSkipColumnTypes +drop table if exists t; +create table t(a int, b int, c json, d text, e mediumtext, f blob, g mediumblob, index idx(d(10))); +set @@session.tidb_analyze_skip_column_types = 'json,blob,mediumblob,text,mediumtext'; +delete from mysql.analyze_jobs; +analyze table t; +select job_info from mysql.analyze_jobs where job_info like '%analyze table%'; +delete from mysql.analyze_jobs; +analyze table t columns a, e; +select job_info from mysql.analyze_jobs where job_info like '%analyze table%'; +set @@session.tidb_analyze_skip_column_types = default; + +# TestIssue34228 +DROP TABLE IF EXISTS Issue34228; +CREATE TABLE Issue34228 (id bigint NOT NULL, dt datetime NOT NULL) PARTITION BY RANGE COLUMNS(dt) (PARTITION p202201 VALUES LESS THAN ("2022-02-01"), PARTITION p202202 VALUES LESS THAN ("2022-03-01")); +INSERT INTO Issue34228 VALUES (1, '2022-02-01 00:00:02'), (2, '2022-02-01 00:00:02'); +SET @@global.tidb_analyze_version = 1; +SET @@session.tidb_partition_prune_mode = 'static'; +ANALYZE TABLE Issue34228; +SET @@session.tidb_partition_prune_mode = 'dynamic'; +ANALYZE TABLE Issue34228; +--sorted_result +SELECT * FROM Issue34228; + +## Needs a second run to hit the issue +connect (conn1, localhost, root,, executor__analyze); +DROP TABLE IF EXISTS Issue34228; +CREATE TABLE Issue34228 (id bigint NOT NULL, dt datetime NOT NULL) PARTITION BY RANGE COLUMNS(dt) (PARTITION p202201 VALUES LESS THAN ("2022-02-01"), PARTITION p202202 VALUES LESS THAN ("2022-03-01")); +INSERT INTO Issue34228 VALUES (1, '2022-02-01 00:00:02'), (2, '2022-02-01 00:00:02'); +SET @@global.tidb_analyze_version = 1; +SET @@session.tidb_partition_prune_mode = 'static'; +ANALYZE TABLE Issue34228; +SET @@session.tidb_partition_prune_mode = 'dynamic'; +ANALYZE TABLE Issue34228; +--sorted_result +SELECT * FROM Issue34228; + +connection default; +disconnect conn1; +SET @@global.tidb_analyze_version = default; +SET @@session.tidb_partition_prune_mode = default; From 7498c6b2d414068781ef5bb3052daef6de4b5cd6 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Wed, 1 Nov 2023 17:11:07 +0800 Subject: [PATCH 5/8] update --- tests/integrationtest/r/executor/stale_txn.result | 8 ++++---- tests/integrationtest/t/executor/stale_txn.test | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integrationtest/r/executor/stale_txn.result b/tests/integrationtest/r/executor/stale_txn.result index 62fe1e43c62c5..d1e7c85a2829b 100644 --- a/tests/integrationtest/r/executor/stale_txn.result +++ b/tests/integrationtest/r/executor/stale_txn.result @@ -21,12 +21,12 @@ set tx_isolation = 'READ-COMMITTED'; drop table if exists t1; create table t1 (id int primary key, v int); insert into t1 values(1, 10); -select sleep(0.01); -sleep(0.01) +select sleep(0.1); +sleep(0.1) 0 set @a=now(6); -select sleep(0.01); -sleep(0.01) +select sleep(0.1); +sleep(0.1) 0 update t1 set v=100 where id=1; set autocommit=0; diff --git a/tests/integrationtest/t/executor/stale_txn.test b/tests/integrationtest/t/executor/stale_txn.test index 10bf954ab3f3b..0d11911ead762 100644 --- a/tests/integrationtest/t/executor/stale_txn.test +++ b/tests/integrationtest/t/executor/stale_txn.test @@ -21,9 +21,9 @@ set tx_isolation = 'READ-COMMITTED'; drop table if exists t1; create table t1 (id int primary key, v int); insert into t1 values(1, 10); -select sleep(0.01); +select sleep(0.1); set @a=now(6); -select sleep(0.01); +select sleep(0.1); update t1 set v=100 where id=1; set autocommit=0; select * from t1 as of timestamp @a; From 666a4167a2dc0086bd96054a3a1ba25459305db5 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 2 Nov 2023 11:10:01 +0800 Subject: [PATCH 6/8] update seq_executor --- pkg/executor/test/seqtest/BUILD.bazel | 2 +- .../test/seqtest/seq_executor_test.go | 117 ------------------ .../integrationtest/r/executor/charset.result | 18 +++ .../r/executor/jointest/join.result | 25 ++++ tests/integrationtest/r/executor/set.result | 21 ++++ tests/integrationtest/r/executor/show.result | 77 ++++++++++++ tests/integrationtest/t/executor/charset.test | 19 +++ .../t/executor/jointest/join.test | 17 +++ tests/integrationtest/t/executor/set.test | 13 ++ tests/integrationtest/t/executor/show.test | 13 ++ 10 files changed, 204 insertions(+), 118 deletions(-) create mode 100644 tests/integrationtest/r/executor/set.result create mode 100644 tests/integrationtest/t/executor/set.test diff --git a/pkg/executor/test/seqtest/BUILD.bazel b/pkg/executor/test/seqtest/BUILD.bazel index 7367f81c9de15..644e9f4aa79ef 100644 --- a/pkg/executor/test/seqtest/BUILD.bazel +++ b/pkg/executor/test/seqtest/BUILD.bazel @@ -10,7 +10,7 @@ go_test( ], flaky = True, race = "on", - shard_count = 37, + shard_count = 33, deps = [ "//pkg/config", "//pkg/ddl/testutil", diff --git a/pkg/executor/test/seqtest/seq_executor_test.go b/pkg/executor/test/seqtest/seq_executor_test.go index 9b2885da5b97d..363f97c3b2ec4 100644 --- a/pkg/executor/test/seqtest/seq_executor_test.go +++ b/pkg/executor/test/seqtest/seq_executor_test.go @@ -1188,72 +1188,6 @@ func TestCoprocessorPriority(t *testing.T) { cli.mu.Unlock() } -func TestShowForNewCollations(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - expectRows := testkit.Rows( - "ascii_bin ascii 65 Yes Yes 1", - "binary binary 63 Yes Yes 1", - "gbk_bin gbk 87 Yes 1", - "gbk_chinese_ci gbk 28 Yes Yes 1", - "latin1_bin latin1 47 Yes Yes 1", - "utf8_bin utf8 83 Yes Yes 1", - "utf8_general_ci utf8 33 Yes 1", - "utf8_unicode_ci utf8 192 Yes 1", - "utf8mb4_0900_ai_ci utf8mb4 255 Yes 1", - "utf8mb4_0900_bin utf8mb4 309 Yes 1", - "utf8mb4_bin utf8mb4 46 Yes Yes 1", - "utf8mb4_general_ci utf8mb4 45 Yes 1", - "utf8mb4_unicode_ci utf8mb4 224 Yes 1", - ) - tk.MustQuery("show collation").Check(expectRows) - tk.MustQuery("select * from information_schema.COLLATIONS").Check(expectRows) - tk.MustQuery("show character set like '%utf8mb4%'").Check(testkit.Rows("utf8mb4 UTF-8 Unicode utf8mb4_bin 4")) - tk.MustQuery("select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'").Check(testkit.Rows("utf8mb4_bin utf8mb4 46 Yes Yes 1")) - // update default_collation_for_utf8mb4 - tk.MustExec("set @@session.default_collation_for_utf8mb4='utf8mb4_0900_ai_ci';") - tk.MustQuery("show variables like 'default_collation_for_utf8mb4';").Check(testkit.Rows("default_collation_for_utf8mb4 utf8mb4_0900_ai_ci")) - expectRows1 := testkit.Rows( - "ascii_bin ascii 65 Yes Yes 1", - "binary binary 63 Yes Yes 1", - "gbk_bin gbk 87 Yes 1", - "gbk_chinese_ci gbk 28 Yes Yes 1", - "latin1_bin latin1 47 Yes Yes 1", - "utf8_bin utf8 83 Yes Yes 1", - "utf8_general_ci utf8 33 Yes 1", - "utf8_unicode_ci utf8 192 Yes 1", - "utf8mb4_0900_ai_ci utf8mb4 255 Yes Yes 1", - "utf8mb4_0900_bin utf8mb4 309 Yes 1", - "utf8mb4_bin utf8mb4 46 Yes 1", - "utf8mb4_general_ci utf8mb4 45 Yes 1", - "utf8mb4_unicode_ci utf8mb4 224 Yes 1", - ) - tk.MustQuery("show collation").Check(expectRows1) - tk.MustQuery("select * from information_schema.COLLATIONS").Check(expectRows) - tk.MustQuery("show character set like '%utf8mb4%'").Check(testkit.Rows("utf8mb4 UTF-8 Unicode utf8mb4_0900_ai_ci 4")) - tk.MustQuery("select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'").Check(testkit.Rows("utf8mb4_bin utf8mb4 46 Yes Yes 1")) -} - -func TestForbidUnsupportedCollations(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - mustGetUnsupportedCollation := func(sql string, coll string) { - tk.MustGetErrMsg(sql, fmt.Sprintf("[ddl:1273]Unsupported collation when new collation is enabled: '%s'", coll)) - } - - mustGetUnsupportedCollation("select 'a' collate utf8_roman_ci", "utf8_roman_ci") - mustGetUnsupportedCollation("select cast('a' as char) collate utf8_roman_ci", "utf8_roman_ci") - mustGetUnsupportedCollation("set names utf8 collate utf8_roman_ci", "utf8_roman_ci") - mustGetUnsupportedCollation("set session collation_server = 'utf8_roman_ci'", "utf8_roman_ci") - mustGetUnsupportedCollation("set session collation_database = 'utf8_roman_ci'", "utf8_roman_ci") - mustGetUnsupportedCollation("set session collation_connection = 'utf8_roman_ci'", "utf8_roman_ci") - mustGetUnsupportedCollation("set global collation_server = 'utf8_roman_ci'", "utf8_roman_ci") - mustGetUnsupportedCollation("set global collation_database = 'utf8_roman_ci'", "utf8_roman_ci") - mustGetUnsupportedCollation("set global collation_connection = 'utf8_roman_ci'", "utf8_roman_ci") -} - func TestAutoIncIDInRetry(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1463,33 +1397,6 @@ func TestAutoRandRecoverTable(t *testing.T) { require.Equal(t, []int64{1, 2, 3, autoRandIDStep + 1, autoRandIDStep + 2, autoRandIDStep + 3}, ordered) } -func TestMaxDeltaSchemaCount(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - require.Equal(t, int64(variable.DefTiDBMaxDeltaSchemaCount), variable.GetMaxDeltaSchemaCount()) - - tk.MustExec("set @@global.tidb_max_delta_schema_count= -1") - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_max_delta_schema_count value: '-1'")) - // Make sure a new session will load global variables. - tk.RefreshSession() - tk.MustExec("use test") - require.Equal(t, int64(100), variable.GetMaxDeltaSchemaCount()) - tk.MustExec(fmt.Sprintf("set @@global.tidb_max_delta_schema_count= %v", uint64(math.MaxInt64))) - tk.MustQuery("show warnings;").Check(testkit.Rows(fmt.Sprintf("Warning 1292 Truncated incorrect tidb_max_delta_schema_count value: '%d'", uint64(math.MaxInt64)))) - tk.RefreshSession() - tk.MustExec("use test") - require.Equal(t, int64(16384), variable.GetMaxDeltaSchemaCount()) - tk.MustGetErrCode("set @@global.tidb_max_delta_schema_count= invalid_val", errno.ErrWrongTypeForVar) - - tk.MustExec("set @@global.tidb_max_delta_schema_count= 2048") - tk.RefreshSession() - tk.MustExec("use test") - require.Equal(t, int64(2048), variable.GetMaxDeltaSchemaCount()) - tk.MustQuery("select @@global.tidb_max_delta_schema_count").Check(testkit.Rows("2048")) -} - func TestOOMPanicInHashJoinWhenFetchBuildRows(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1556,30 +1463,6 @@ func TestIssue18744(t *testing.T) { require.EqualError(t, err, "mockIndexHashJoinOuterWorkerErr") } -func TestIssue19410(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1, t2, t3;") - tk.MustExec("create table t(a int, b enum('A', 'B'));") - tk.MustExec("create table t1(a1 int, b1 enum('B', 'A') NOT NULL, UNIQUE KEY (b1));") - tk.MustExec("insert into t values (1, 'A');") - tk.MustExec("insert into t1 values (1, 'A');") - tk.MustQuery("select /*+ INL_HASH_JOIN(t1) */ * from t join t1 on t.b = t1.b1;").Check(testkit.Rows("1 A 1 A")) - tk.MustQuery("select /*+ INL_JOIN(t1) */ * from t join t1 on t.b = t1.b1;").Check(testkit.Rows("1 A 1 A")) - - tk.MustExec("create table t2(a1 int, b1 enum('C', 'D') NOT NULL, UNIQUE KEY (b1));") - tk.MustExec("insert into t2 values (1, 'C');") - tk.MustQuery("select /*+ INL_HASH_JOIN(t2) */ * from t join t2 on t.b = t2.b1;").Check(testkit.Rows()) - tk.MustQuery("select /*+ INL_JOIN(t2) */ * from t join t2 on t.b = t2.b1;").Check(testkit.Rows()) - - tk.MustExec("create table t3(a1 int, b1 enum('A', 'B') NOT NULL, UNIQUE KEY (b1));") - tk.MustExec("insert into t3 values (1, 'A');") - tk.MustQuery("select /*+ INL_HASH_JOIN(t3) */ * from t join t3 on t.b = t3.b1;").Check(testkit.Rows("1 A 1 A")) - tk.MustQuery("select /*+ INL_JOIN(t3) */ * from t join t3 on t.b = t3.b1;").Check(testkit.Rows("1 A 1 A")) -} - func TestAnalyzeNextRawErrorNoLeak(t *testing.T) { store := testkit.CreateMockStore(t) diff --git a/tests/integrationtest/r/executor/charset.result b/tests/integrationtest/r/executor/charset.result index 6736319dce5a8..18314b1606ec1 100644 --- a/tests/integrationtest/r/executor/charset.result +++ b/tests/integrationtest/r/executor/charset.result @@ -102,3 +102,21 @@ a 中文 b 一二三 一二三 一二三 中文 中文 +select 'a' collate utf8_roman_ci; +Error 1273 (HY000): Unsupported collation when new collation is enabled: 'utf8_roman_ci' +select cast('a' as char) collate utf8_roman_ci; +Error 1273 (HY000): Unsupported collation when new collation is enabled: 'utf8_roman_ci' +set names utf8 collate utf8_roman_ci; +Error 1273 (HY000): Unsupported collation when new collation is enabled: 'utf8_roman_ci' +set session collation_server = 'utf8_roman_ci'; +Error 1273 (HY000): Unsupported collation when new collation is enabled: 'utf8_roman_ci' +set session collation_database = 'utf8_roman_ci'; +Error 1273 (HY000): Unsupported collation when new collation is enabled: 'utf8_roman_ci' +set session collation_connection = 'utf8_roman_ci'; +Error 1273 (HY000): Unsupported collation when new collation is enabled: 'utf8_roman_ci' +set global collation_server = 'utf8_roman_ci'; +Error 1273 (HY000): Unsupported collation when new collation is enabled: 'utf8_roman_ci' +set global collation_database = 'utf8_roman_ci'; +Error 1273 (HY000): Unsupported collation when new collation is enabled: 'utf8_roman_ci' +set global collation_connection = 'utf8_roman_ci'; +Error 1273 (HY000): Unsupported collation when new collation is enabled: 'utf8_roman_ci' diff --git a/tests/integrationtest/r/executor/jointest/join.result b/tests/integrationtest/r/executor/jointest/join.result index eaafbf9f87c72..ac36ba737e673 100644 --- a/tests/integrationtest/r/executor/jointest/join.result +++ b/tests/integrationtest/r/executor/jointest/join.result @@ -853,3 +853,28 @@ select * from (t1 natural join t2) right outer join (t3 natural join t4) using ( c b y a 3 1 11 2 3 1 2 2 +drop table if exists t, t1, t2, t3; +create table t(a int, b enum('A', 'B')); +create table t1(a1 int, b1 enum('B', 'A') NOT NULL, UNIQUE KEY (b1)); +insert into t values (1, 'A'); +insert into t1 values (1, 'A'); +select /*+ INL_HASH_JOIN(t1) */ * from t join t1 on t.b = t1.b1; +a b a1 b1 +1 A 1 A +select /*+ INL_JOIN(t1) */ * from t join t1 on t.b = t1.b1; +a b a1 b1 +1 A 1 A +create table t2(a1 int, b1 enum('C', 'D') NOT NULL, UNIQUE KEY (b1)); +insert into t2 values (1, 'C'); +select /*+ INL_HASH_JOIN(t2) */ * from t join t2 on t.b = t2.b1; +a b a1 b1 +select /*+ INL_JOIN(t2) */ * from t join t2 on t.b = t2.b1; +a b a1 b1 +create table t3(a1 int, b1 enum('A', 'B') NOT NULL, UNIQUE KEY (b1)); +insert into t3 values (1, 'A'); +select /*+ INL_HASH_JOIN(t3) */ * from t join t3 on t.b = t3.b1; +a b a1 b1 +1 A 1 A +select /*+ INL_JOIN(t3) */ * from t join t3 on t.b = t3.b1; +a b a1 b1 +1 A 1 A diff --git a/tests/integrationtest/r/executor/set.result b/tests/integrationtest/r/executor/set.result new file mode 100644 index 0000000000000..1482cac01daa4 --- /dev/null +++ b/tests/integrationtest/r/executor/set.result @@ -0,0 +1,21 @@ +set @@global.tidb_max_delta_schema_count= -1; +show warnings; +Level Code Message +Warning 1292 Truncated incorrect tidb_max_delta_schema_count value: '-1' +select @@global.tidb_max_delta_schema_count; +@@global.tidb_max_delta_schema_count +100 +set @@global.tidb_max_delta_schema_count= 9223372036854775807; +show warnings; +Level Code Message +Warning 1292 Truncated incorrect tidb_max_delta_schema_count value: '9223372036854775807' +select @@global.tidb_max_delta_schema_count; +@@global.tidb_max_delta_schema_count +16384 +set @@global.tidb_max_delta_schema_count= invalid_val; +Error 1232 (42000): Incorrect argument type to variable 'tidb_max_delta_schema_count' +set @@global.tidb_max_delta_schema_count= 2048; +select @@global.tidb_max_delta_schema_count; +@@global.tidb_max_delta_schema_count +2048 +set @@global.tidb_max_delta_schema_count= default; diff --git a/tests/integrationtest/r/executor/show.result b/tests/integrationtest/r/executor/show.result index 42f3f82125667..679caffa6fa8c 100644 --- a/tests/integrationtest/r/executor/show.result +++ b/tests/integrationtest/r/executor/show.result @@ -1045,3 +1045,80 @@ current_value ****** SET GLOBAL authentication_ldap_simple_bind_root_pwd = default; SET GLOBAL authentication_ldap_sasl_bind_root_pwd = default; +show collation; +Collation Charset Id Default Compiled Sortlen +ascii_bin ascii 65 Yes Yes 1 +binary binary 63 Yes Yes 1 +gbk_bin gbk 87 Yes 1 +gbk_chinese_ci gbk 28 Yes Yes 1 +latin1_bin latin1 47 Yes Yes 1 +utf8_bin utf8 83 Yes Yes 1 +utf8_general_ci utf8 33 Yes 1 +utf8_unicode_ci utf8 192 Yes 1 +utf8mb4_0900_ai_ci utf8mb4 255 Yes 1 +utf8mb4_0900_bin utf8mb4 309 Yes 1 +utf8mb4_bin utf8mb4 46 Yes Yes 1 +utf8mb4_general_ci utf8mb4 45 Yes 1 +utf8mb4_unicode_ci utf8mb4 224 Yes 1 +select * from information_schema.COLLATIONS; +COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN +ascii_bin ascii 65 Yes Yes 1 +binary binary 63 Yes Yes 1 +gbk_bin gbk 87 Yes 1 +gbk_chinese_ci gbk 28 Yes Yes 1 +latin1_bin latin1 47 Yes Yes 1 +utf8_bin utf8 83 Yes Yes 1 +utf8_general_ci utf8 33 Yes 1 +utf8_unicode_ci utf8 192 Yes 1 +utf8mb4_0900_ai_ci utf8mb4 255 Yes 1 +utf8mb4_0900_bin utf8mb4 309 Yes 1 +utf8mb4_bin utf8mb4 46 Yes Yes 1 +utf8mb4_general_ci utf8mb4 45 Yes 1 +utf8mb4_unicode_ci utf8mb4 224 Yes 1 +show character set like '%utf8mb4%'; +Charset Description Default collation Maxlen +utf8mb4 UTF-8 Unicode utf8mb4_bin 4 +select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'; +COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN +utf8mb4_bin utf8mb4 46 Yes Yes 1 +set @@session.default_collation_for_utf8mb4='utf8mb4_0900_ai_ci'; +show variables like 'default_collation_for_utf8mb4'; +Variable_name Value +default_collation_for_utf8mb4 utf8mb4_0900_ai_ci +show collation; +Collation Charset Id Default Compiled Sortlen +ascii_bin ascii 65 Yes Yes 1 +binary binary 63 Yes Yes 1 +gbk_bin gbk 87 Yes 1 +gbk_chinese_ci gbk 28 Yes Yes 1 +latin1_bin latin1 47 Yes Yes 1 +utf8_bin utf8 83 Yes Yes 1 +utf8_general_ci utf8 33 Yes 1 +utf8_unicode_ci utf8 192 Yes 1 +utf8mb4_0900_ai_ci utf8mb4 255 Yes Yes 1 +utf8mb4_0900_bin utf8mb4 309 Yes 1 +utf8mb4_bin utf8mb4 46 Yes 1 +utf8mb4_general_ci utf8mb4 45 Yes 1 +utf8mb4_unicode_ci utf8mb4 224 Yes 1 +select * from information_schema.COLLATIONS; +COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN +ascii_bin ascii 65 Yes Yes 1 +binary binary 63 Yes Yes 1 +gbk_bin gbk 87 Yes 1 +gbk_chinese_ci gbk 28 Yes Yes 1 +latin1_bin latin1 47 Yes Yes 1 +utf8_bin utf8 83 Yes Yes 1 +utf8_general_ci utf8 33 Yes 1 +utf8_unicode_ci utf8 192 Yes 1 +utf8mb4_0900_ai_ci utf8mb4 255 Yes 1 +utf8mb4_0900_bin utf8mb4 309 Yes 1 +utf8mb4_bin utf8mb4 46 Yes Yes 1 +utf8mb4_general_ci utf8mb4 45 Yes 1 +utf8mb4_unicode_ci utf8mb4 224 Yes 1 +show character set like '%utf8mb4%'; +Charset Description Default collation Maxlen +utf8mb4 UTF-8 Unicode utf8mb4_0900_ai_ci 4 +select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'; +COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN +utf8mb4_bin utf8mb4 46 Yes Yes 1 +set @@session.default_collation_for_utf8mb4=default; diff --git a/tests/integrationtest/t/executor/charset.test b/tests/integrationtest/t/executor/charset.test index a5c3a3abca482..c97caaf04db7e 100644 --- a/tests/integrationtest/t/executor/charset.test +++ b/tests/integrationtest/t/executor/charset.test @@ -60,3 +60,22 @@ insert into t values ('a', '中文'), ('中文', '中文'), ('一二三', '一 --sorted_result select * from t; +# TestForbidUnsupportedCollations +-- error 1273 +select 'a' collate utf8_roman_ci; +-- error 1273 +select cast('a' as char) collate utf8_roman_ci; +-- error 1273 +set names utf8 collate utf8_roman_ci; +-- error 1273 +set session collation_server = 'utf8_roman_ci'; +-- error 1273 +set session collation_database = 'utf8_roman_ci'; +-- error 1273 +set session collation_connection = 'utf8_roman_ci'; +-- error 1273 +set global collation_server = 'utf8_roman_ci'; +-- error 1273 +set global collation_database = 'utf8_roman_ci'; +-- error 1273 +set global collation_connection = 'utf8_roman_ci'; diff --git a/tests/integrationtest/t/executor/jointest/join.test b/tests/integrationtest/t/executor/jointest/join.test index e6fac7c4f1434..e94d4207335b8 100644 --- a/tests/integrationtest/t/executor/jointest/join.test +++ b/tests/integrationtest/t/executor/jointest/join.test @@ -569,3 +569,20 @@ select * from (t1 natural join t2) left outer join (t3 natural join t4) using (b --sorted_result select * from (t1 natural join t2) right outer join (t3 natural join t4) using (c,b); +# TestIssue19410 +drop table if exists t, t1, t2, t3; +create table t(a int, b enum('A', 'B')); +create table t1(a1 int, b1 enum('B', 'A') NOT NULL, UNIQUE KEY (b1)); +insert into t values (1, 'A'); +insert into t1 values (1, 'A'); +select /*+ INL_HASH_JOIN(t1) */ * from t join t1 on t.b = t1.b1; +select /*+ INL_JOIN(t1) */ * from t join t1 on t.b = t1.b1; +create table t2(a1 int, b1 enum('C', 'D') NOT NULL, UNIQUE KEY (b1)); +insert into t2 values (1, 'C'); +select /*+ INL_HASH_JOIN(t2) */ * from t join t2 on t.b = t2.b1; +select /*+ INL_JOIN(t2) */ * from t join t2 on t.b = t2.b1; +create table t3(a1 int, b1 enum('A', 'B') NOT NULL, UNIQUE KEY (b1)); +insert into t3 values (1, 'A'); +select /*+ INL_HASH_JOIN(t3) */ * from t join t3 on t.b = t3.b1; +select /*+ INL_JOIN(t3) */ * from t join t3 on t.b = t3.b1; + diff --git a/tests/integrationtest/t/executor/set.test b/tests/integrationtest/t/executor/set.test new file mode 100644 index 0000000000000..112926aaf67d4 --- /dev/null +++ b/tests/integrationtest/t/executor/set.test @@ -0,0 +1,13 @@ +# TestMaxDeltaSchemaCount +set @@global.tidb_max_delta_schema_count= -1; +show warnings; +select @@global.tidb_max_delta_schema_count; +set @@global.tidb_max_delta_schema_count= 9223372036854775807; +show warnings; +select @@global.tidb_max_delta_schema_count; +-- error 1232 +set @@global.tidb_max_delta_schema_count= invalid_val; +set @@global.tidb_max_delta_schema_count= 2048; +select @@global.tidb_max_delta_schema_count; +set @@global.tidb_max_delta_schema_count= default; + diff --git a/tests/integrationtest/t/executor/show.test b/tests/integrationtest/t/executor/show.test index 8763e94d0175c..ef88ad76614eb 100644 --- a/tests/integrationtest/t/executor/show.test +++ b/tests/integrationtest/t/executor/show.test @@ -414,3 +414,16 @@ show variables like 'authentication_ldap_simple_bind_root_pwd'; SELECT current_value FROM information_schema.variables_info WHERE VARIABLE_NAME LIKE 'authentication_ldap_simple_bind_root_pwd'; SET GLOBAL authentication_ldap_simple_bind_root_pwd = default; SET GLOBAL authentication_ldap_sasl_bind_root_pwd = default; + +# TestShowForNewCollations +show collation; +select * from information_schema.COLLATIONS; +show character set like '%utf8mb4%'; +select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'; +set @@session.default_collation_for_utf8mb4='utf8mb4_0900_ai_ci'; +show variables like 'default_collation_for_utf8mb4'; +show collation; +select * from information_schema.COLLATIONS; +show character set like '%utf8mb4%'; +select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'; +set @@session.default_collation_for_utf8mb4=default; From 5b9e29b9c05a067fa5fb65a3d579c182bfa69304 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 2 Nov 2023 11:57:07 +0800 Subject: [PATCH 7/8] update --- tests/integrationtest/r/executor/adapter.result | 6 +++--- tests/integrationtest/t/executor/adapter.test | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/integrationtest/r/executor/adapter.result b/tests/integrationtest/r/executor/adapter.result index fdb89c456847c..ea7d968aa8de4 100644 --- a/tests/integrationtest/r/executor/adapter.result +++ b/tests/integrationtest/r/executor/adapter.result @@ -1,4 +1,4 @@ -set @a = now(); +set @a = now(6); drop table if exists t; create table t(a int); insert into t values (1), (1), (1), (1), (1); @@ -29,6 +29,6 @@ a a 1 1 1 1 1 1 -select timestampdiff(second,@a, now()) < 1; -timestampdiff(second,@a, now()) < 1 +select timestampdiff(microsecond, @a, now(6)) < 1000000; +timestampdiff(microsecond, @a, now(6)) < 1000000 1 diff --git a/tests/integrationtest/t/executor/adapter.test b/tests/integrationtest/t/executor/adapter.test index d0a62f5c012f2..05fa9a2a50b6f 100644 --- a/tests/integrationtest/t/executor/adapter.test +++ b/tests/integrationtest/t/executor/adapter.test @@ -1,8 +1,9 @@ # TestQueryTime -set @a = now(); +set @a = now(6); drop table if exists t; create table t(a int); insert into t values (1), (1), (1), (1), (1); select * from t t1 join t t2 on t1.a = t2.a; -select timestampdiff(second,@a, now()) < 1; +## should less than 1 second +select timestampdiff(microsecond, @a, now(6)) < 1000000; From 4449e87a7df8098c7061bd4c2af024ceb8532efa Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 2 Nov 2023 14:43:20 +0800 Subject: [PATCH 8/8] make tests stable --- tests/integrationtest/r/planner/core/tests/prepare/issue.result | 2 ++ tests/integrationtest/t/planner/core/tests/prepare/issue.test | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/integrationtest/r/planner/core/tests/prepare/issue.result b/tests/integrationtest/r/planner/core/tests/prepare/issue.result index 34c3af078411e..d56e2ab7c6ca8 100644 --- a/tests/integrationtest/r/planner/core/tests/prepare/issue.result +++ b/tests/integrationtest/r/planner/core/tests/prepare/issue.result @@ -287,6 +287,8 @@ count(*) select @@last_plan_from_cache; @@last_plan_from_cache 0 +set tidb_enable_prepared_plan_cache=DEFAULT; +set @@tidb_enable_collect_execution_info=DEFAULT; set tidb_enable_prepared_plan_cache=1; set tidb_enable_clustered_index=on; drop table if exists PK_TCOLLATION10197; diff --git a/tests/integrationtest/t/planner/core/tests/prepare/issue.test b/tests/integrationtest/t/planner/core/tests/prepare/issue.test index e15e95ca30385..0056cfb8b2144 100644 --- a/tests/integrationtest/t/planner/core/tests/prepare/issue.test +++ b/tests/integrationtest/t/planner/core/tests/prepare/issue.test @@ -199,6 +199,8 @@ execute stmt using @a, @b, @c, @d, @e; select @@last_plan_from_cache; execute stmt using @f, @b, @c, @d, @e; select @@last_plan_from_cache; +set tidb_enable_prepared_plan_cache=DEFAULT; +set @@tidb_enable_collect_execution_info=DEFAULT; # TestIssue29805 set tidb_enable_prepared_plan_cache=1;