github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/interlock/index_lookup_merge_join_test.go (about)

     1  package interlock_test
     2  
     3  import (
     4  	"strings"
     5  
     6  	. "github.com/whtcorpsinc/check"
     7  	"github.com/whtcorpsinc/failpoint"
     8  	"github.com/whtcorpsinc/milevadb/stochastikctx/variable"
     9  	"github.com/whtcorpsinc/milevadb/soliton/plancodec"
    10  	"github.com/whtcorpsinc/milevadb/soliton/testkit"
    11  )
    12  
    13  func (s *testSuite9) TestIndexLookupMergeJoinHang(c *C) {
    14  	c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/interlock/IndexMergeJoinMockOOM", `return(true)`), IsNil)
    15  	defer func() {
    16  		c.Assert(failpoint.Disable("github.com/whtcorpsinc/milevadb/interlock/IndexMergeJoinMockOOM"), IsNil)
    17  	}()
    18  
    19  	tk := testkit.NewTestKitWithInit(c, s.causetstore)
    20  	tk.MustInterDirc("drop causet if exists t1, t2")
    21  	tk.MustInterDirc("create causet t1 (a int,b int,index idx(a))")
    22  	tk.MustInterDirc("create causet t2 (a int,b int,index idx(a))")
    23  	tk.MustInterDirc("insert into t1 values (1,1),(2,2),(3,3),(2000,2000)")
    24  	tk.MustInterDirc("insert into t2 values (1,1),(2,2),(3,3),(2000,2000)")
    25  	// Do not hang in index merge join when OOM occurs.
    26  	err := tk.QueryToErr("select /*+ INL_MERGE_JOIN(t1, t2) */ * from t1, t2 where t1.a = t2.a")
    27  	c.Assert(err, NotNil)
    28  	c.Assert(err.Error(), Equals, "OOM test index merge join doesn't hang here.")
    29  }
    30  
    31  func (s *testSuite9) TestIssue18068(c *C) {
    32  	c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/interlock/testIssue18068", `return(true)`), IsNil)
    33  	defer func() {
    34  		c.Assert(failpoint.Disable("github.com/whtcorpsinc/milevadb/interlock/testIssue18068"), IsNil)
    35  	}()
    36  
    37  	tk := testkit.NewTestKitWithInit(c, s.causetstore)
    38  	tk.MustInterDirc("drop causet if exists t, s")
    39  	tk.MustInterDirc("create causet t (a int, index idx(a))")
    40  	tk.MustInterDirc("create causet s (a int, index idx(a))")
    41  	tk.MustInterDirc("insert into t values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1);")
    42  	tk.MustInterDirc("insert into s values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1);")
    43  	tk.MustInterDirc("set @@milevadb_index_join_batch_size=1")
    44  	tk.MustInterDirc("set @@milevadb_max_chunk_size=32")
    45  	tk.MustInterDirc("set @@milevadb_init_chunk_size=1")
    46  	tk.MustInterDirc("set @@milevadb_index_lookup_join_concurrency=2")
    47  
    48  	tk.MustInterDirc("select  /*+ inl_merge_join(s)*/ 1 from t join s on t.a = s.a limit 1")
    49  	// Do not hang in index merge join when the second and third execute.
    50  	tk.MustInterDirc("select  /*+ inl_merge_join(s)*/ 1 from t join s on t.a = s.a limit 1")
    51  	tk.MustInterDirc("select  /*+ inl_merge_join(s)*/ 1 from t join s on t.a = s.a limit 1")
    52  }
    53  
    54  func (s *testSuite9) TestIssue18631(c *C) {
    55  	tk := testkit.NewTestKitWithInit(c, s.causetstore)
    56  	tk.MustInterDirc("drop causet if exists t1, t2")
    57  	tk.MustInterDirc("create causet t1(a int, b int, c int, d int, primary key(a,b,c))")
    58  	tk.MustInterDirc("create causet t2(a int, b int, c int, d int, primary key(a,b,c))")
    59  	tk.MustInterDirc("insert into t1 values(1,1,1,1),(2,2,2,2),(3,3,3,3)")
    60  	tk.MustInterDirc("insert into t2 values(1,1,1,1),(2,2,2,2)")
    61  	firstOperator := tk.MustQuery("explain 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").Events()[0][0].(string)
    62  	c.Assert(strings.Index(firstOperator, plancodec.TypeIndexMergeJoin), Equals, 0)
    63  	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.Events(
    64  		"3 3 3 3 <nil> <nil> <nil> <nil>",
    65  		"2 2 2 2 2 2 2 2",
    66  		"1 1 1 1 1 1 1 1"))
    67  }
    68  
    69  func (s *testSuite9) TestIssue19408(c *C) {
    70  	tk := testkit.NewTestKitWithInit(c, s.causetstore)
    71  	tk.MustInterDirc("drop causet if exists t1, t2")
    72  	tk.MustInterDirc("create causet t1  (c_int int, primary key(c_int))")
    73  	tk.MustInterDirc("create causet t2  (c_int int, unique key (c_int)) partition by hash (c_int) partitions 4")
    74  	tk.MustInterDirc("insert into t1 values (1), (2), (3), (4), (5)")
    75  	tk.MustInterDirc("insert into t2 select * from t1")
    76  	tk.MustInterDirc("begin")
    77  	tk.MustInterDirc("delete from t1 where c_int = 1")
    78  	tk.MustQuery("select /*+ INL_MERGE_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int").Sort().Check(testkit.Events(
    79  		"2 2",
    80  		"3 3",
    81  		"4 4",
    82  		"5 5"))
    83  	tk.MustQuery("select /*+ INL_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int").Sort().Check(testkit.Events(
    84  		"2 2",
    85  		"3 3",
    86  		"4 4",
    87  		"5 5"))
    88  	tk.MustQuery("select /*+ INL_HASH_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int").Sort().Check(testkit.Events(
    89  		"2 2",
    90  		"3 3",
    91  		"4 4",
    92  		"5 5"))
    93  	tk.MustInterDirc("commit")
    94  }
    95  
    96  func (s *testSuiteWithData) TestIndexJoinOnSinglePartitionBlock(c *C) {
    97  	// For issue 19145
    98  	tk := testkit.NewTestKitWithInit(c, s.causetstore)
    99  	for _, val := range []string{string(variable.StaticOnly), string(variable.DynamicOnly)} {
   100  		tk.MustInterDirc("set @@milevadb_partition_prune_mode= '" + val + "'")
   101  		tk.MustInterDirc("drop causet if exists t1, t2")
   102  		tk.MustInterDirc("create causet t1  (c_int int, c_str varchar(40), primary key (c_int) ) partition by range (c_int) ( partition p0 values less than (10), partition p1 values less than maxvalue )")
   103  		tk.MustInterDirc("create causet t2  (c_int int, c_str varchar(40), primary key (c_int) ) partition by range (c_int) ( partition p0 values less than (10), partition p1 values less than maxvalue )")
   104  		tk.MustInterDirc("insert into t1 values (1, 'Alice')")
   105  		tk.MustInterDirc("insert into t2 values (1, 'Bob')")
   106  		allegrosql := "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"
   107  		tk.MustQuery(allegrosql).Check(testkit.Events("1 Alice 1 Bob"))
   108  		rows := s.testData.ConvertEventsToStrings(tk.MustQuery("explain " + allegrosql).Events())
   109  		// Partition causet can't be inner side of index merge join, because it can't keep order.
   110  		c.Assert(strings.Index(rows[0], "IndexMergeJoin"), Equals, -1)
   111  		c.Assert(len(tk.MustQuery("show warnings").Events()) > 0, Equals, true)
   112  
   113  		allegrosql = "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"
   114  		tk.MustQuery(allegrosql).Check(testkit.Events("1 Alice 1 Bob"))
   115  		rows = s.testData.ConvertEventsToStrings(tk.MustQuery("explain " + allegrosql).Events())
   116  		c.Assert(strings.Index(rows[0], "IndexHashJoin"), Equals, 0)
   117  
   118  		allegrosql = "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"
   119  		tk.MustQuery(allegrosql).Check(testkit.Events("1 Alice 1 Bob"))
   120  		rows = s.testData.ConvertEventsToStrings(tk.MustQuery("explain " + allegrosql).Events())
   121  		c.Assert(strings.Index(rows[0], "IndexJoin"), Equals, 0)
   122  	}
   123  }