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: migrate test-infra to testify for executor/index_lookup_join_test.go #30260

Merged
merged 3 commits into from
Dec 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 136 additions & 52 deletions executor/index_lookup_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,67 @@ import (
"fmt"
"math/rand"
"strings"
"testing"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/util/israce"
"github.com/pingcap/tidb/util/testkit"
"github.com/stretchr/testify/require"
)

func (s *testSuite1) TestIndexLookupJoinHang(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIndexLookupJoinHang(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table idxJoinOuter (a int unsigned)")
tk.MustExec("create table idxJoinInner (a int unsigned unique)")
tk.MustExec("insert idxJoinOuter values (1), (1), (1), (1), (1)")
tk.MustExec("insert idxJoinInner values (1)")
tk.Se.GetSessionVars().IndexJoinBatchSize = 1
tk.Se.GetSessionVars().SetIndexLookupJoinConcurrency(1)
tk.Session().GetSessionVars().IndexJoinBatchSize = 1
tk.Session().GetSessionVars().SetIndexLookupJoinConcurrency(1)

rs, err := tk.Exec("select /*+ INL_JOIN(i)*/ * from idxJoinOuter o left join idxJoinInner i on o.a = i.a where o.a in (1, 2) and (i.a - 3) > 0")
c.Assert(err, IsNil)
require.NoError(t, err)
req := rs.NewChunk(nil)
for i := 0; i < 5; i++ {
// FIXME: cannot check err, since err exists, Panic: [tikv:1690]BIGINT UNSIGNED value is out of range in '(Column#0 - 3)'
_ = rs.Next(context.Background(), req)
}
err = rs.Close()
c.Assert(err, IsNil)
require.NoError(t, err)

rs, err = tk.Exec("select /*+ INL_HASH_JOIN(i)*/ * from idxJoinOuter o left join idxJoinInner i on o.a = i.a where o.a in (1, 2) and (i.a - 3) > 0")
c.Assert(err, IsNil)
require.NoError(t, err)
req = rs.NewChunk(nil)
for i := 0; i < 5; i++ {
// to fix: cannot check err, since err exists, Panic: [tikv:1690]BIGINT UNSIGNED value is out of range in '(Column#0 - 3)'
_ = rs.Next(context.Background(), req)
}
err = rs.Close()
c.Assert(err, IsNil)
require.NoError(t, err)

rs, err = tk.Exec("select /*+ INL_MERGE_JOIN(i)*/ * from idxJoinOuter o left join idxJoinInner i on o.a = i.a where o.a in (1, 2) and (i.a - 3) > 0")
c.Assert(err, IsNil)
require.NoError(t, err)
req = rs.NewChunk(nil)
for i := 0; i < 5; i++ {
// to fix: cannot check err, since err exists, Panic: [tikv:1690]BIGINT UNSIGNED value is out of range in '(Column#0 - 3)'
_ = rs.Next(context.Background(), req)
}
err = rs.Close()
c.Assert(err, IsNil)
require.NoError(t, err)
}

func (s *testSuite1) TestIndexJoinUnionScan(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIndexJoinUnionScan(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
tk.MustExec("drop table if exists t2")
tk.MustExec("create table t1(id int primary key, a int)")
tk.MustExec("create table t2(id int primary key, a int, b int, key idx_a(a))")
tk.MustExec("insert into t2 values (1,1,1),(4,2,4)")
Expand Down Expand Up @@ -113,8 +126,15 @@ func (s *testSuite1) TestIndexJoinUnionScan(c *C) {
tk.MustExec("rollback")
}

func (s *testSuite1) TestBatchIndexJoinUnionScan(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestBatchIndexJoinUnionScanTest(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1;")
tk.MustExec("drop table if exists t2;")
tk.MustExec("create table t1(id int primary key, a int)")
tk.MustExec("create table t2(id int primary key, a int, key idx_a(a))")
tk.MustExec("set @@session.tidb_init_chunk_size=1")
Expand All @@ -129,8 +149,13 @@ func (s *testSuite1) TestBatchIndexJoinUnionScan(c *C) {
tk.MustExec("rollback")
}

func (s *testSuite1) TestInapplicableIndexJoinHint(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestInapplicableIndexJoinHint(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`drop table if exists t1, t2;`)
tk.MustExec(`create table t1(a bigint, b bigint);`)
tk.MustExec(`create table t2(a bigint, b bigint);`)
Expand Down Expand Up @@ -168,8 +193,13 @@ func (s *testSuite1) TestInapplicableIndexJoinHint(c *C) {
tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_MERGE_JOIN(t2) */ is inapplicable`))
}

func (s *testSuite) TestIndexJoinOverflow(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIndexJoinOverflow(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`drop table if exists t1, t2`)
tk.MustExec(`create table t1(a int)`)
tk.MustExec(`insert into t1 values (-1)`)
Expand All @@ -179,8 +209,13 @@ func (s *testSuite) TestIndexJoinOverflow(c *C) {
tk.MustQuery(`select /*+ INL_MERGE_JOIN(t2) */ * from t1 join t2 on t1.a = t2.a;`).Check(testkit.Rows())
}

func (s *testSuite5) TestIssue11061(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIssue11061(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1(c varchar(30), index ix_c(c(10)))")
tk.MustExec("insert into t1 (c) values('7_chars'), ('13_characters')")
Expand All @@ -189,8 +224,13 @@ func (s *testSuite5) TestIssue11061(c *C) {
tk.MustQuery("SELECT /*+ INL_MERGE_JOIN(t1) */ SUM(LENGTH(c)) FROM t1 WHERE c IN (SELECT t1.c FROM t1)").Check(testkit.Rows("20"))
}

func (s *testSuite5) TestIndexJoinPartitionTable(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIndexJoinPartitionTable(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int not null, c int, key idx(c)) partition by hash(b) partitions 30")
tk.MustExec("insert into t values(1, 27, 2)")
Expand All @@ -199,8 +239,12 @@ func (s *testSuite5) TestIndexJoinPartitionTable(c *C) {
tk.MustQuery("SELECT /*+ INL_MERGE_JOIN(t1) */ count(1) FROM t t1 INNER JOIN (SELECT a, max(c) AS c FROM t WHERE b = 27 AND a = 1 GROUP BY a) t2 ON t1.a = t2.a AND t1.c = t2.c WHERE t1.b = 27").Check(testkit.Rows("1"))
}

func (s *testSuite5) TestIndexJoinMultiCondition(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestIndexJoinMultiCondition(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1(a int not null, b int not null, key idx_a_b(a,b))")
Expand All @@ -210,22 +254,30 @@ func (s *testSuite5) TestIndexJoinMultiCondition(c *C) {
tk.MustQuery("select /*+ TIDB_INLJ(t1) */ count(*) from t1, t2 where t1.a = t2.a and t1.b < t2.b").Check(testkit.Rows("3"))
}

func (s *testSuite5) TestIssue16887(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestIssue16887(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists admin_roles, admin_role_has_permissions")
tk.MustExec("CREATE TABLE `admin_role_has_permissions` (`permission_id` bigint(20) unsigned NOT NULL, `role_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`permission_id`,`role_id`), KEY `admin_role_has_permissions_role_id_foreign` (`role_id`))")
tk.MustExec("CREATE TABLE `admin_roles` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '角色名称', `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`))")
tk.MustExec("INSERT INTO `admin_roles` (`id`, `name`, `created_at`, `updated_at`) VALUES(1, 'admin','2020-04-27 02:40:03', '2020-04-27 02:40:03'),(2, 'developer','2020-04-27 02:40:03', '2020-04-27 02:40:03'),(3, 'analyst','2020-04-27 02:40:03', '2020-04-27 02:40:03'),(4, 'channel_admin','2020-04-27 02:40:03', '2020-04-27 02:40:03'),(5, 'test','2020-04-27 02:40:08', '2020-04-27 02:40:08')")
tk.MustExec("INSERT INTO `admin_role_has_permissions` (`permission_id`, `role_id`) VALUES(1, 1),(2, 1),(3, 1),(4, 1),(5, 1),(6, 1),(7, 1),(8, 1),(9, 1),(10, 1),(11, 1),(12, 1),(13, 1),(14, 1),(15, 1),(16, 1),(17, 1),(18, 1),(19, 1),(20, 1),(21, 1),(22, 1),(23, 1),(24, 1),(25, 1),(26, 1),(27, 1),(28, 1),(29, 1),(30, 1),(31, 1),(32, 1),(33, 1),(34, 1),(35, 1),(36, 1),(37, 1),(38, 1),(39, 1),(40, 1),(41, 1),(42, 1),(43, 1),(44, 1),(45, 1),(46, 1),(47, 1),(48, 1),(49, 1),(50, 1),(51, 1),(52, 1),(53, 1),(54, 1),(55, 1),(56, 1),(57, 1),(58, 1),(59, 1),(60, 1),(61, 1),(62, 1),(63, 1),(64, 1),(65, 1),(66, 1),(67, 1),(68, 1),(69, 1),(70, 1),(71, 1),(72, 1),(73, 1),(74, 1),(75, 1),(76, 1),(77, 1),(78, 1),(79, 1),(80, 1),(81, 1),(82, 1),(83, 1),(5, 4),(6, 4),(7, 4),(84, 5),(85, 5),(86, 5)")
rows := tk.MustQuery("SELECT /*+ inl_merge_join(admin_role_has_permissions) */ `admin_roles`.* FROM `admin_roles` INNER JOIN `admin_role_has_permissions` ON `admin_roles`.`id` = `admin_role_has_permissions`.`role_id` WHERE `admin_role_has_permissions`.`permission_id`\n IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67)").Rows()
c.Assert(len(rows), Equals, 70)
require.Len(t, rows, 70)
rows = tk.MustQuery("show warnings").Rows()
c.Assert(len(rows) > 0, Equals, true)
require.Less(t, 0, len(rows))
}

func (s *testSuite5) TestIndexJoinEnumSetIssue19233(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestIndexJoinEnumSetIssue19233(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("drop table if exists i;")
Expand Down Expand Up @@ -253,18 +305,22 @@ func (s *testSuite5) TestIndexJoinEnumSetIssue19233(c *C) {
for _, hint := range []string{"INL_HASH_JOIN", "INL_JOIN"} {
sql := fmt.Sprintf(`select /*+ %s(%s) */ * from i, %s where i.objectType = %s.type;`, hint, table, table, table)
rows := tk.MustQuery(sql).Rows()
c.Assert(len(rows), Equals, 64)
require.Len(t, rows, 64)
for i := 0; i < len(rows); i++ {
c.Assert(fmt.Sprint(rows[i][0]), Equals, "HOST_PORT")
require.Equal(t, "HOST_PORT", rows[i][0])
}
rows = tk.MustQuery("show warnings").Rows()
c.Assert(len(rows), Equals, 0)
require.Len(t, rows, 0)
}
}
}

func (s *testSuite5) TestIssue19411(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestIssue19411(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t1 (c_int int, primary key (c_int))")
tk.MustExec("create table t2 (c_int int, primary key (c_int)) partition by hash (c_int) partitions 4")
Expand All @@ -279,8 +335,12 @@ func (s *testSuite5) TestIssue19411(c *C) {
tk.MustExec("commit")
}

func (s *testSuite5) TestIssue23653(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestIssue23653(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1 (c_int int, c_str varchar(40), primary key(c_str), unique key(c_int), unique key(c_str))")
Expand All @@ -291,8 +351,12 @@ func (s *testSuite5) TestIssue23653(c *C) {
"2 reverent keller 2 reverent keller"))
}

func (s *testSuite5) TestIssue23656(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestIssue23656(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1 (c_int int, c_str varchar(40), primary key(c_int, c_str(4)))")
Expand All @@ -304,8 +368,12 @@ func (s *testSuite5) TestIssue23656(c *C) {
"2 blissful aryabhata 2 blissful aryabhata"))
}

func (s *testSuite5) TestIssue23722(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestIssue23722(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a int, b char(10), c blob, primary key (c(5)) clustered);")
Expand Down Expand Up @@ -337,8 +405,12 @@ func (s *testSuite5) TestIssue23722(c *C) {
"order by col_15 , col_16 , col_17 , col_18 , col_19;").Check(testkit.Rows("38799.400 20301 KETeFZhkoxnwMAhA Charlie zyhXEppZdqyqNV"))
}

func (s *testSuite5) TestIssue24547(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestIssue24547(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists a")
tk.MustExec("drop table if exists b")
Expand All @@ -349,8 +421,12 @@ func (s *testSuite5) TestIssue24547(c *C) {
tk.MustExec("delete a from a inner join b on a.k1 = b.k1 and a.k2 = b.k2 where b.k2 <> '333'")
}

func (s *testSuite5) TestIssue27138(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestIssue27138(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1,t2")

Expand Down Expand Up @@ -394,8 +470,12 @@ PARTITIONS 1`)
tk.MustQuery("select /* +INL_JOIN(t1,t2) */ t1.id, t1.pc from t1 where id in ( select prefiller from t2 where t2.postfiller = 1 )").Check(testkit.Rows())
}

func (s *testSuite5) TestIssue27893(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestIssue27893(t *testing.T) {
hawkingrei marked this conversation as resolved.
Show resolved Hide resolved
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
tk.MustExec("drop table if exists t2")
Expand All @@ -407,11 +487,15 @@ func (s *testSuite5) TestIssue27893(c *C) {
tk.MustQuery("select /*+ inl_hash_join(t2) */ count(*) from t1 join t2 on t1.a = t2.a").Check(testkit.Rows("1"))
}

func (s *testSuite5) TestPartitionTableIndexJoinAndIndexReader(c *C) {
func TestPartitionTableIndexJoinAndIndexReader(t *testing.T) {
hawkingrei marked this conversation as resolved.
Show resolved Hide resolved
if israce.RaceEnabled {
c.Skip("exhaustive types test, skip race test")
t.Skip("exhaustive types test, skip race test")
}
tk := testkit.NewTestKit(c, s.store)
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set @@tidb_partition_prune_mode='dynamic'")
tk.MustExec(`create table t (a int, b int, key(a)) partition by hash(a) partitions 4`)
Expand Down