Search in sources :

Example 41 with DrillCostFactory

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

the class RowKeyJoinPrel method computeSelfCost.

@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
    if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) {
        return super.computeSelfCost(planner).multiplyBy(.1);
    }
    double rowCount = mq.getRowCount(this.getRight());
    DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
    // it is not making any extra copy of either the left or right batches, so the memory cost is 0
    return costFactory.makeCost(rowCount, 0, 0, 0, 0);
}
Also used : DrillCostFactory(org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory)

Example 42 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 43 with DrillCostFactory

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

the class MapRDBIndexDescriptor method getCost.

@Override
public RelOptCost getCost(IndexProperties indexProps, RelOptPlanner planner, int numProjectedFields, GroupScan primaryTableGroupScan) {
    Preconditions.checkArgument(primaryTableGroupScan instanceof DbGroupScan);
    DbGroupScan dbGroupScan = (DbGroupScan) primaryTableGroupScan;
    DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
    double totalRows = indexProps.getTotalRows();
    double leadRowCount = indexProps.getLeadingSelectivity() * totalRows;
    double avgRowSize = indexProps.getAvgRowSize();
    if (indexProps.isCovering()) {
        // covering index
        // int numIndexCols = allFields.size();
        // for disk i/o, all index columns are going to be read into memory
        double numBlocks = Math.ceil((leadRowCount * avgRowSize) / pluginCost.getBlockSize(primaryTableGroupScan));
        double diskCost = numBlocks * pluginCost.getSequentialBlockReadCost(primaryTableGroupScan);
        // cpu cost is cost of filter evaluation for the remainder condition
        double cpuCost = 0.0;
        if (indexProps.getTotalRemainderFilter() != null) {
            cpuCost = leadRowCount * DrillCostBase.COMPARE_CPU_COST;
        }
        // TODO: add network cost once full table scan also considers network cost
        double networkCost = 0.0;
        return costFactory.makeCost(leadRowCount, cpuCost, diskCost, networkCost);
    } else {
        // non-covering index
        // int numIndexCols = allFields.size();
        double numBlocksIndex = Math.ceil((leadRowCount * avgRowSize) / pluginCost.getBlockSize(primaryTableGroupScan));
        double diskCostIndex = numBlocksIndex * pluginCost.getSequentialBlockReadCost(primaryTableGroupScan);
        // for the primary table join-back each row may belong to a different block, so in general num_blocks = num_rows;
        // however, num_blocks cannot exceed the total number of blocks of the table
        double totalBlocksPrimary = Math.ceil((dbGroupScan.getColumns().size() * pluginCost.getAverageColumnSize(primaryTableGroupScan) * totalRows) / pluginCost.getBlockSize(primaryTableGroupScan));
        double diskBlocksPrimary = Math.min(totalBlocksPrimary, leadRowCount);
        double diskCostPrimary = diskBlocksPrimary * pluginCost.getRandomBlockReadCost(primaryTableGroupScan);
        double diskCostTotal = diskCostIndex + diskCostPrimary;
        // cpu cost of remainder condition evaluation over the selected rows
        double cpuCost = 0.0;
        if (indexProps.getTotalRemainderFilter() != null) {
            cpuCost = leadRowCount * DrillCostBase.COMPARE_CPU_COST;
        }
        // TODO: add network cost once full table scan also considers network cost
        double networkCost = 0.0;
        return costFactory.makeCost(leadRowCount, cpuCost, diskCostTotal, networkCost);
    }
}
Also used : DrillCostFactory(org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory) DbGroupScan(org.apache.drill.exec.physical.base.DbGroupScan)

Example 44 with DrillCostFactory

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

the class DrillScreenRelBase method computeSelfCost.

@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
    if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) {
        return super.computeSelfCost(planner, mq).multiplyBy(.1);
    }
    // by default, assume cost is proportional to number of rows
    double rowCount = mq.getRowCount(this);
    DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
    return costFactory.makeCost(rowCount, rowCount, 0, 0).multiplyBy(0.1);
}
Also used : DrillCostFactory(org.apache.drill.exec.planner.cost.DrillCostBase.DrillCostFactory)

Example 45 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)46 RelNode (org.apache.calcite.rel.RelNode)21 ScanStats (org.apache.drill.exec.physical.base.ScanStats)4 DrillCostBase (org.apache.drill.exec.planner.cost.DrillCostBase)2 DbGroupScan (org.apache.drill.exec.physical.base.DbGroupScan)1