Esempio n. 1
0
  /** 把query中的avg换成count,sum */
  @Override
  public IDataNodeExecutor optimize(
      IDataNodeExecutor dne,
      Map<Integer, ParameterContext> parameterSettings,
      Map<String, Object> extraCmd) {
    if (dne instanceof IMerge && ((IMerge) dne).getSubNode().size() > 1) {
      for (IDataNodeExecutor sub : ((IMerge) dne).getSubNode()) {
        expendAvgFunction(sub);
      }

      for (IDataNodeExecutor sub : ((IMerge) dne).getSubNode()) {
        this.optimize(sub, parameterSettings, extraCmd);
      }
    } else if (dne instanceof IJoin) {
      IJoin join = (IJoin) dne;
      // join函数,采取map模式,不需要处理avg展开
      // 递归处理子节点
      this.optimize(join.getLeftNode(), parameterSettings, extraCmd);
      this.optimize(join.getRightNode(), parameterSettings, extraCmd);
    } else if (dne instanceof IQuery) {
      IQuery query = (IQuery) dne;
      // 如果是子查询,采取map模式,不需要处理avg展开
      if (query.isSubQuery()) {
        this.optimize(query.getSubQuery(), parameterSettings, extraCmd); // 递归处理子节点
      }
    }

    return dne;
  }
  @Override
  public IBlockNestedLoopCursor blockNestedLoopJoinCursor(
      ExecutionContext executionContext,
      ISchematicCursor left_cursor,
      ISchematicCursor right_cursor,
      List left_columns,
      List right_columns,
      List columns,
      IJoin join)
      throws TddlException {

    try {
      return new BlockNestedtLoopCursor(
          left_cursor,
          right_cursor,
          left_columns,
          right_columns,
          columns,
          this,
          join,
          executionContext,
          join.getLeftNode().getColumns(),
          join.getRightNode().getColumns());
    } catch (Exception e) {
      closeParentCursor(left_cursor);
      closeParentCursor(right_cursor);
      throw new TddlException(e);
    }
  }
 @Override
 public IIndexNestLoopCursor indexNestLoopCursor(
     ExecutionContext executionContext,
     ISchematicCursor leftCursor,
     ISchematicCursor rightCursor,
     List leftColumns,
     List rightColumns,
     List columns,
     boolean prefix,
     IJoin executor)
     throws TddlException {
   try {
     return new IndexNestedLoopMgetImpCursor(
         leftCursor,
         rightCursor,
         leftColumns,
         rightColumns,
         columns,
         prefix,
         executor.getLeftNode().getColumns(),
         executor.getRightNode().getColumns(),
         executor,
         executionContext);
   } catch (Exception e) {
     closeParentCursor(leftCursor);
     closeParentCursor(rightCursor);
     throw new TddlException(e);
   }
 }
Esempio n. 4
0
 // 两表Join查询,右表连接键为主键,右表为主键查询
 // 开启了join merge join
 // 右表虽然为二级索引的查询,但Join列不是索引列,应该选择NestLoop
 // 会是一个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.NAME = 1");
   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.assertTrue(subJoin.getRightNode() instanceof IJoin);
   Assert.assertEquals(JoinStrategy.NEST_LOOP_JOIN, subJoin.getJoinStrategy());
 }