Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

executor: add some test cases about partition table dynamic-mode with clustered-index #24523

Merged
merged 8 commits into from
May 11, 2021
49 changes: 49 additions & 0 deletions session/clustered_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
package session_test

import (
"fmt"
"math/rand"
"strings"

. "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"
)
Expand Down Expand Up @@ -578,6 +583,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)
Expand Down