Exemple #1
0
 // 两表Join查询,右表连接键为主键,右表为主键查询
 // 开启了join merge join
 // 右表主键索引的查询,Join列也索引列,应该选择IndexNestLoop
 // 会是一个(table1 join table2 index ) join table2 key 的多级join
 @Test
 public void test_两表Join_主键索引_存在主键索引条件() {
   TableNode table = new TableNode("TABLE1");
   JoinNode join = table.join("TABLE2", "ID", "ID");
   join.query("TABLE2.ID IN (1,2)");
   IQueryTree qc = (IQueryTree) optimizer.optimizeAndAssignment(join, null, extraCmd);
   Assert.assertTrue(qc instanceof IMerge);
   Assert.assertTrue(((IMerge) qc).getSubNodes().get(0) instanceof IJoin);
   IJoin subJoin = (IJoin) ((IMerge) qc).getSubNodes().get(0);
   Assert.assertEquals(JoinStrategy.INDEX_NEST_LOOP, subJoin.getJoinStrategy());
 }
Exemple #2
0
 // 两表Join查询,右表连接键为主键,右表为二级索引查询
 // 开启了join merge join
 // 右表二级索引的查询,Join列也是二级索引索引,应该选择NestLoop
 // 会是一个(table1 index join table1 index ) join (table2 index join table2
 // key)的多级join
 @Test
 public void test_两表Join_二级索引_存在二级索引条件() {
   TableNode table = new TableNode("TABLE1");
   JoinNode join = table.join("TABLE2", "NAME", "NAME");
   join.query("TABLE2.NAME = 1");
   IQueryTree qc = (IQueryTree) optimizer.optimizeAndAssignment(join, null, extraCmd);
   Assert.assertTrue(qc instanceof IJoin);
   Assert.assertTrue(((IJoin) qc).getLeftNode() instanceof IJoin);
   Assert.assertTrue(((IJoin) qc).getRightNode() instanceof IMerge);
   Assert.assertEquals(JoinStrategy.INDEX_NEST_LOOP, ((IJoin) qc).getJoinStrategy());
   IJoin subJoin = (IJoin) ((IJoin) qc).getLeftNode();
   Assert.assertTrue(((IJoin) subJoin).getLeftNode() instanceof IMerge);
   Assert.assertTrue(((IJoin) subJoin).getRightNode() instanceof IMerge);
   Assert.assertEquals(JoinStrategy.INDEX_NEST_LOOP, subJoin.getJoinStrategy());
 }