Search in sources :

Example 11 with DrillCostFactory

use of org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory in project drill by apache.

the class DrillAggregateRelBase method computeHashAggCost.

/**
   * Estimate cost of hash agg. Called by DrillAggregateRel.computeSelfCost() and HashAggPrel.computeSelfCost()
  */
protected RelOptCost computeHashAggCost(RelOptPlanner planner, RelMetadataQuery mq) {
    if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) {
        return super.computeSelfCost(planner, mq).multiplyBy(.1);
    }
    RelNode child = this.getInput();
    double inputRows = mq.getRowCount(child);
    int numGroupByFields = this.getGroupCount();
    int numAggrFields = this.aggCalls.size();
    // cpu cost of hashing each grouping key
    double cpuCost = DrillCostBase.HASH_CPU_COST * numGroupByFields * inputRows;
    // add cpu cost for computing the aggregate functions
    cpuCost += DrillCostBase.FUNC_CPU_COST * numAggrFields * inputRows;
    // assume in-memory for now until we enforce operator-level memory constraints
    double diskIOCost = 0;
    // TODO: use distinct row count
    // + hash table template stuff
    double factor = PrelUtil.getPlannerSettings(planner).getOptions().getOption(ExecConstants.HASH_AGG_TABLE_FACTOR_KEY).float_val;
    long fieldWidth = PrelUtil.getPlannerSettings(planner).getOptions().getOption(ExecConstants.AVERAGE_FIELD_WIDTH_KEY).num_val;
    // table + hashValues + links
    double memCost = ((fieldWidth * numGroupByFields) + IntHolder.WIDTH + IntHolder.WIDTH) * inputRows * factor;
    DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
    return costFactory.makeCost(inputRows, cpuCost, diskIOCost, 0, /* network cost */
    memCost);
}
Also used : DrillCostFactory(org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory) RelNode(org.apache.calcite.rel.RelNode)

Example 12 with DrillCostFactory

use of org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory in project drill by apache.

the class DrillScanRel method computeSelfCost.

/// TODO: this method is same as the one for ScanPrel...eventually we should consolidate
/// this and few other methods in a common base class which would be extended
/// by both logical and physical rels.
@Override
public RelOptCost computeSelfCost(final RelOptPlanner planner, RelMetadataQuery mq) {
    final ScanStats stats = groupScan.getScanStats(settings);
    int columnCount = getRowType().getFieldCount();
    double ioCost = 0;
    boolean isStarQuery = Iterables.tryFind(getRowType().getFieldNames(), new Predicate<String>() {

        @Override
        public boolean apply(String input) {
            return Preconditions.checkNotNull(input).equals("*");
        }
    }).isPresent();
    if (isStarQuery) {
        columnCount = STAR_COLUMN_COST;
    }
    // double rowCount = RelMetadataQuery.getRowCount(this);
    double rowCount = stats.getRecordCount();
    if (rowCount < 1) {
        rowCount = 1;
    }
    if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) {
        return planner.getCostFactory().makeCost(rowCount * columnCount, stats.getCpuCost(), stats.getDiskCost());
    }
    // for now, assume cpu cost is proportional to row count.
    double cpuCost = rowCount * columnCount;
    // Even though scan is reading from disk, in the currently generated plans all plans will
    // need to read the same amount of data, so keeping the disk io cost 0 is ok for now.
    // In the future we might consider alternative scans that go against projections or
    // different compression schemes etc that affect the amount of data read. Such alternatives
    // would affect both cpu and io cost.
    DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
    return costFactory.makeCost(rowCount, cpuCost, ioCost, 0);
}
Also used : DrillCostFactory(org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory) ScanStats(org.apache.drill.exec.physical.base.ScanStats) Predicate(com.google.common.base.Predicate)

Example 13 with DrillCostFactory

use of org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory in project drill by apache.

the class UnionDistinctPrel method computeSelfCost.

@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
    if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) {
        return super.computeSelfCost(planner, mq).multiplyBy(.1);
    }
    double totalInputRowCount = 0;
    for (int i = 0; i < this.getInputs().size(); i++) {
        totalInputRowCount += mq.getRowCount(this.getInputs().get(i));
    }
    double cpuCost = totalInputRowCount * DrillCostBase.BASE_CPU_COST;
    DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
    return costFactory.makeCost(totalInputRowCount, cpuCost, 0, 0);
}
Also used : DrillCostFactory(org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory)

Example 14 with DrillCostFactory

use of org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory in project drill by apache.

the class NestedLoopJoinPrel method computeSelfCost.

@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
    if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) {
        return super.computeSelfCost(planner, mq).multiplyBy(.1);
    }
    double leftRowCount = mq.getRowCount(this.getLeft());
    double rightRowCount = mq.getRowCount(this.getRight());
    double nljFactor = PrelUtil.getSettings(getCluster()).getNestedLoopJoinFactor();
    // cpu cost of evaluating each expression in join condition
    int exprNum = RelOptUtil.conjunctions(getCondition()).size() + RelOptUtil.disjunctions(getCondition()).size();
    double joinConditionCost = DrillCostBase.COMPARE_CPU_COST * exprNum;
    double cpuCost = joinConditionCost * (leftRowCount * rightRowCount) * nljFactor;
    DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
    return costFactory.makeCost(leftRowCount * rightRowCount, cpuCost, 0, 0, 0);
}
Also used : DrillCostFactory(org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory)

Example 15 with DrillCostFactory

use of org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory in project drill by apache.

the class DrillFilterRelBase method computeSelfCost.

@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
    if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) {
        return super.computeSelfCost(planner, mq).multiplyBy(.1);
    }
    RelNode child = this.getInput();
    double inputRows = mq.getRowCount(child);
    double cpuCost = estimateCpuCost(mq);
    DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
    return costFactory.makeCost(inputRows, cpuCost, 0, 0);
}
Also used : DrillCostFactory(org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory) RelNode(org.apache.calcite.rel.RelNode)

Aggregations

DrillCostFactory (org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory)21 RelNode (org.apache.calcite.rel.RelNode)10 ScanStats (org.apache.drill.exec.physical.base.ScanStats)2 Predicate (com.google.common.base.Predicate)1 DrillCostBase (org.apache.drill.exec.planner.cost.DrillCostBase)1