示例#1
0
  AbstractPlanNode inlineAggregationApply(AbstractPlanNode plan) {
    // check for an aggregation of the right form
    if ((plan instanceof AggregatePlanNode) == false || (plan instanceof WindowFunctionPlanNode)) {
      return plan;
    }
    assert (plan.getChildCount() == 1);
    AggregatePlanNode aggplan = (AggregatePlanNode) plan;

    // Assuming all AggregatePlanNode has not been inlined before this microoptimization
    AbstractPlanNode child = aggplan.getChild(0);

    // EE Currently support: seqscan + indexscan
    if (child.getPlanNodeType() != PlanNodeType.SEQSCAN
        && child.getPlanNodeType() != PlanNodeType.INDEXSCAN
        && child.getPlanNodeType() != PlanNodeType.NESTLOOP
        && child.getPlanNodeType() != PlanNodeType.NESTLOOPINDEX) {
      return plan;
    }

    if (child.getPlanNodeType() == PlanNodeType.INDEXSCAN) {
      // Currently do not conflict with the optimized MIN/MAX
      // because of the big amount of tests changed.

      IndexScanPlanNode isp = (IndexScanPlanNode) child;
      LimitPlanNode limit = (LimitPlanNode) isp.getInlinePlanNode(PlanNodeType.LIMIT);
      if (limit != null && (aggplan.isTableMin() || aggplan.isTableMax())) {
        // Optimized MIN/MAX
        if (limit.getLimit() == 1 && limit.getOffset() == 0) {
          return plan;
        }
      }
    }

    // Inline aggregate node
    AbstractPlanNode parent = null;
    if (aggplan.getParentCount() == 1) {
      parent = aggplan.getParent(0);
    }
    child.addInlinePlanNode(aggplan);
    child.clearParents();
    if (parent != null) {
      parent.replaceChild(aggplan, child);
    }
    return child;
  }