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 index_lookup_merge_join_test #32283

Merged
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
105 changes: 67 additions & 38 deletions executor/index_lookup_merge_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,40 @@ package executor_test

import (
"strings"
"testing"

. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/testdata"
"github.com/pingcap/tidb/util/plancodec"
"github.com/pingcap/tidb/util/testkit"
"github.com/stretchr/testify/require"
)

func (s *testSerialSuite) TestIndexLookupMergeJoinHang(c *C) {
c.Assert(failpoint.Enable("github.com/pingcap/tidb/executor/IndexMergeJoinMockOOM", `return(true)`), IsNil)
func TestIndexLookupMergeJoinHang(t *testing.T) {
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/IndexMergeJoinMockOOM", `return(true)`))
defer func() {
c.Assert(failpoint.Disable("github.com/pingcap/tidb/executor/IndexMergeJoinMockOOM"), IsNil)
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/executor/IndexMergeJoinMockOOM"))
}()

tk := testkit.NewTestKitWithInit(c, s.store)
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,b int,index idx(a))")
tk.MustExec("create table t2 (a int,b int,index idx(a))")
tk.MustExec("insert into t1 values (1,1),(2,2),(3,3),(2000,2000)")
tk.MustExec("insert into t2 values (1,1),(2,2),(3,3),(2000,2000)")
// Do not hang in index merge join when OOM occurs.
err := tk.QueryToErr("select /*+ INL_MERGE_JOIN(t1, t2) */ * from t1, t2 where t1.a = t2.a")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "OOM test index merge join doesn't hang here.")
require.Error(t, err)
require.Equal(t, "OOM test index merge join doesn't hang here.", err.Error())
}

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

tk.MustExec("use test")
tk.MustExec("drop table if exists t")
Expand All @@ -58,13 +64,15 @@ func (s *testSerialSuite) TestIssue28052(c *C) {
tk.MustQuery("select /*+ inl_merge_join(t1, t2) */ count(*) from t t1 right join t t2 on t1. `col_year_key_signed` = t2. `col_tinyint_key_signed`").Check(testkit.Rows("1"))
}

func (s *testSerialSuite) TestIssue18068(c *C) {
c.Assert(failpoint.Enable("github.com/pingcap/tidb/executor/testIssue18068", `return(true)`), IsNil)
func TestIssue18068(t *testing.T) {
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/testIssue18068", `return(true)`))
defer func() {
c.Assert(failpoint.Disable("github.com/pingcap/tidb/executor/testIssue18068"), IsNil)
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/executor/testIssue18068"))
}()

tk := testkit.NewTestKitWithInit(c, s.store)
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t, s")
tk.MustExec("create table t (a int, index idx(a))")
tk.MustExec("create table s (a int, index idx(a))")
Expand All @@ -81,23 +89,29 @@ func (s *testSerialSuite) TestIssue18068(c *C) {
tk.MustExec("select /*+ inl_merge_join(s)*/ 1 from t join s on t.a = s.a limit 1")
}

func (s *testSuite9) TestIssue18631(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIssue18631(t *testing.T) {
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, b int, c int, d int, primary key(a,b,c))")
tk.MustExec("create table t2(a int, b int, c int, d int, primary key(a,b,c))")
tk.MustExec("insert into t1 values(1,1,1,1),(2,2,2,2),(3,3,3,3)")
tk.MustExec("insert into t2 values(1,1,1,1),(2,2,2,2)")
firstOperator := tk.MustQuery("explain format = 'brief' select /*+ inl_merge_join(t1,t2) */ * from t1 left join t2 on t1.a = t2.a and t1.c = t2.c and t1.b = t2.b order by t1.a desc").Rows()[0][0].(string)
c.Assert(strings.Index(firstOperator, plancodec.TypeIndexMergeJoin), Equals, 0)
require.Equal(t, 0, strings.Index(firstOperator, plancodec.TypeIndexMergeJoin))
tk.MustQuery("select /*+ inl_merge_join(t1,t2) */ * from t1 left join t2 on t1.a = t2.a and t1.c = t2.c and t1.b = t2.b order by t1.a desc").Check(testkit.Rows(
"3 3 3 3 <nil> <nil> <nil> <nil>",
"2 2 2 2 2 2 2 2",
"1 1 1 1 1 1 1 1"))
}

func (s *testSuite9) TestIssue19408(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIssue19408(t *testing.T) {
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, primary key(c_int))")
tk.MustExec("create table t2 (c_int int, unique key (c_int)) partition by hash (c_int) partitions 4")
Expand All @@ -123,8 +137,11 @@ func (s *testSuite9) TestIssue19408(c *C) {
tk.MustExec("commit")
}

func (s *testSuite9) TestIssue20137(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIssue20137(t *testing.T) {
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 (id bigint(20) unsigned, primary key(id))")
tk.MustExec("create table t2 (id bigint(20) unsigned)")
Expand All @@ -136,9 +153,12 @@ func (s *testSuite9) TestIssue20137(c *C) {
testkit.Rows("8738875760185212610 8738875760185212610", "9814441339970117597 9814441339970117597"))
}

func (s *testSuiteWithData) TestIndexJoinOnSinglePartitionTable(c *C) {
func TestIndexJoinOnSinglePartitionTable(t *testing.T) {
// For issue 19145
tk := testkit.NewTestKitWithInit(c, s.store)
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
for _, val := range []string{string(variable.Static), string(variable.Dynamic)} {
tk.MustExec("set @@tidb_partition_prune_mode= '" + val + "'")
tk.MustExec("drop table if exists t1, t2")
Expand All @@ -148,25 +168,28 @@ func (s *testSuiteWithData) TestIndexJoinOnSinglePartitionTable(c *C) {
tk.MustExec("insert into t2 values (1, 'Bob')")
sql := "select /*+ INL_MERGE_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str"
tk.MustQuery(sql).Check(testkit.Rows("1 Alice 1 Bob"))
rows := s.testData.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + sql).Rows())
rows := testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + sql).Rows())
// Partition table can't be inner side of index merge join, because it can't keep order.
c.Assert(strings.Index(rows[0], "IndexMergeJoin"), Equals, -1)
c.Assert(len(tk.MustQuery("show warnings").Rows()) > 0, Equals, true)
require.Equal(t, -1, strings.Index(rows[0], "IndexMergeJoin"))
require.Equal(t, true, len(tk.MustQuery("show warnings").Rows()) > 0)

sql = "select /*+ INL_HASH_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str"
tk.MustQuery(sql).Check(testkit.Rows("1 Alice 1 Bob"))
rows = s.testData.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + sql).Rows())
c.Assert(strings.Index(rows[0], "IndexHashJoin"), Equals, 0)
rows = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + sql).Rows())
require.Equal(t, 0, strings.Index(rows[0], "IndexHashJoin"))

sql = "select /*+ INL_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str"
tk.MustQuery(sql).Check(testkit.Rows("1 Alice 1 Bob"))
rows = s.testData.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + sql).Rows())
c.Assert(strings.Index(rows[0], "IndexJoin"), Equals, 0)
rows = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + sql).Rows())
require.Equal(t, 0, strings.Index(rows[0], "IndexJoin"))
}
}

func (s *testSuite9) TestIssue20400(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIssue20400(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t, s")
tk.MustExec("create table s(a int, index(a))")
tk.MustExec("create table t(a int)")
Expand All @@ -177,8 +200,11 @@ func (s *testSuite9) TestIssue20400(c *C) {
testkit.Rows("1 <nil>"))
}

func (s *testSuite9) TestIssue20549(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIssue20549(t *testing.T) {
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` (`id` bigint(20) NOT NULL AUTO_INCREMENT, `t2id` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`), KEY `t2id` (`t2id`));")
tk.MustExec("INSERT INTO `t1` VALUES (1,NULL);")
Expand All @@ -189,8 +215,11 @@ func (s *testSuite9) TestIssue20549(c *C) {
testkit.Rows("1"))
}

func (s *testSuite9) TestIssue24473AndIssue25669(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
func TestIssue24473AndIssue25669(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists x, t2, t3")
tk.MustExec("CREATE TABLE `x` ( `a` enum('y','b','1','x','0','null') DEFAULT NULL, KEY `a` (`a`));")
tk.MustExec("insert into x values(\"x\"),(\"x\"),(\"b\"),(\"y\");")
Expand Down