From fdb332d8f726646311c8869c27e1f615f83c7f27 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Mon, 10 May 2021 19:36:19 +0800 Subject: [PATCH 1/3] add more test cases about cluster-index --- session/clustered_index_test.go | 50 ++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/session/clustered_index_test.go b/session/clustered_index_test.go index fd40cfd567f11..d084830243407 100644 --- a/session/clustered_index_test.go +++ b/session/clustered_index_test.go @@ -14,13 +14,17 @@ package session_test import ( + "fmt" . "github.com/pingcap/check" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/util/collate" + "github.com/pingcap/tidb/util/israce" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testutil" + "math/rand" + "strings" ) type testClusteredSuiteBase struct{ testSessionSuiteBase } @@ -509,7 +513,7 @@ func (s *testClusteredSuite) TestClusteredIndexSelectWhereInNull(c *C) { tk := s.newTK(c) tk.MustExec("drop table if exists t;") tk.MustExec("create table t (a datetime, b bigint, primary key (a));") - tk.MustQuery("select * from t where a in (null);").Check(testkit.Rows( /* empty result */ )) + tk.MustQuery("select * from t where a in (null);").Check(testkit.Rows( /* empty result */)) } func (s *testClusteredSuite) TestClusteredIndexSyntax(c *C) { @@ -578,6 +582,50 @@ func (s *testClusteredSerialSuite) TestPrefixClusteredIndexAddIndexAndRecover(c tk1.MustExec("admin check table t") } +func (s *testClusteredSerialSuite) TestPartitionTable(c *C) { + if israce.RaceEnabled { + c.Skip("exhaustive types test, skip race test") + } + + tk := testkit.NewTestKitWithInit(c, s.store) + tk.MustExec("create database test_view") + tk.MustExec("use test_view") + tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'") + + tk.MustExec(`create table thash (a int, b int, c varchar(32), primary key(a, b) clustered) partition by hash(a) partitions 4`) + tk.MustExec(`create table trange (a int, b int, c varchar(32), primary key(a, b) clustered) partition by range columns(a) ( + partition p0 values less than (3000), + partition p1 values less than (6000), + partition p2 values less than (9000), + partition p3 values less than (10000))`) + tk.MustExec(`create table tnormal (a int, b int, c varchar(32), primary key(a, b))`) + + vals := make([]string, 0, 4000) + existedPK := make(map[string]struct{}, 4000) + for i := 0; i < 4000; { + a := rand.Intn(10000) + b := rand.Intn(10000) + pk := fmt.Sprintf("%v, %v", a, b) + if _, ok := existedPK[pk]; ok { + continue + } + existedPK[pk] = struct{}{} + i++ + vals = append(vals, fmt.Sprintf(`(%v, %v, '%v')`, a, b, rand.Intn(10000))) + } + + tk.MustExec("insert into thash values " + strings.Join(vals, ", ")) + tk.MustExec("insert into trange values " + strings.Join(vals, ", ")) + tk.MustExec("insert into tnormal values " + strings.Join(vals, ", ")) + + for i := 0; i < 200; i++ { + cond := fmt.Sprintf("where a in (%v, %v, %v) and b < %v", rand.Intn(10000), rand.Intn(10000), rand.Intn(10000), rand.Intn(10000)) + result := tk.MustQuery("select * from tnormal " + cond).Sort().Rows() + tk.MustQuery("select * from thash use index(primary) " + cond).Sort().Check(result) + tk.MustQuery("select * from trange use index(primary) " + cond).Sort().Check(result) + } +} + // https://github.com/pingcap/tidb/issues/23106 func (s *testClusteredSerialSuite) TestClusteredIndexDecodeRestoredDataV5(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) From a8166642e33716b3a08db0c190125e695ac17f6f Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Mon, 10 May 2021 19:38:49 +0800 Subject: [PATCH 2/3] make linter happy --- session/clustered_index_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/session/clustered_index_test.go b/session/clustered_index_test.go index d084830243407..86d0b2a3e9c0c 100644 --- a/session/clustered_index_test.go +++ b/session/clustered_index_test.go @@ -15,6 +15,9 @@ package session_test import ( "fmt" + "math/rand" + "strings" + . "github.com/pingcap/check" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/errno" @@ -23,8 +26,6 @@ import ( "github.com/pingcap/tidb/util/israce" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testutil" - "math/rand" - "strings" ) type testClusteredSuiteBase struct{ testSessionSuiteBase } From 9f630f467c532f03a8ec75c3541e39541f47dd32 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 11 May 2021 16:20:59 +0800 Subject: [PATCH 3/3] make linter happy --- session/clustered_index_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/session/clustered_index_test.go b/session/clustered_index_test.go index 86d0b2a3e9c0c..0f79b1b13fc2e 100644 --- a/session/clustered_index_test.go +++ b/session/clustered_index_test.go @@ -17,7 +17,7 @@ import ( "fmt" "math/rand" "strings" - + . "github.com/pingcap/check" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/errno" @@ -514,7 +514,7 @@ func (s *testClusteredSuite) TestClusteredIndexSelectWhereInNull(c *C) { tk := s.newTK(c) tk.MustExec("drop table if exists t;") tk.MustExec("create table t (a datetime, b bigint, primary key (a));") - tk.MustQuery("select * from t where a in (null);").Check(testkit.Rows( /* empty result */)) + tk.MustQuery("select * from t where a in (null);").Check(testkit.Rows( /* empty result */ )) } func (s *testClusteredSuite) TestClusteredIndexSyntax(c *C) {