Search in sources :

Example 6 with Cost

use of org.apache.phoenix.optimize.Cost in project phoenix by apache.

the class ClientScanPlan method getCost.

@Override
public Cost getCost() {
    Double inputBytes = this.getDelegate().accept(new ByteCountVisitor());
    Double outputBytes = this.accept(new ByteCountVisitor());
    if (inputBytes == null || outputBytes == null) {
        return Cost.UNKNOWN;
    }
    int parallelLevel = CostUtil.estimateParallelLevel(false, context.getConnection().getQueryServices());
    Cost cost = new Cost(0, 0, 0);
    if (!orderBy.getOrderByExpressions().isEmpty()) {
        Cost orderByCost = CostUtil.estimateOrderByCost(inputBytes, outputBytes, parallelLevel);
        cost = cost.plus(orderByCost);
    }
    return super.getCost().plus(cost);
}
Also used : ByteCountVisitor(org.apache.phoenix.execute.visitor.ByteCountVisitor) Cost(org.apache.phoenix.optimize.Cost)

Example 7 with Cost

use of org.apache.phoenix.optimize.Cost in project phoenix by apache.

the class ScanPlan method getCost.

@Override
public Cost getCost() {
    Long byteCount = null;
    try {
        byteCount = getEstimatedBytesToScan();
    } catch (SQLException e) {
    // ignored.
    }
    Double outputBytes = this.accept(new ByteCountVisitor());
    if (byteCount == null || outputBytes == null) {
        return Cost.UNKNOWN;
    }
    int parallelLevel = CostUtil.estimateParallelLevel(true, context.getConnection().getQueryServices());
    Cost cost = new Cost(0, 0, byteCount);
    if (!orderBy.getOrderByExpressions().isEmpty()) {
        Cost orderByCost = CostUtil.estimateOrderByCost(byteCount, outputBytes, parallelLevel);
        cost = cost.plus(orderByCost);
    }
    return cost;
}
Also used : ByteCountVisitor(org.apache.phoenix.execute.visitor.ByteCountVisitor) SQLException(java.sql.SQLException) Cost(org.apache.phoenix.optimize.Cost)

Example 8 with Cost

use of org.apache.phoenix.optimize.Cost in project phoenix by apache.

the class AggregatePlan method getCost.

@Override
public Cost getCost() {
    Double outputBytes = this.accept(new ByteCountVisitor());
    Double rowWidth = this.accept(new AvgRowWidthVisitor());
    Long inputRows = null;
    try {
        inputRows = getEstimatedRowsToScan();
    } catch (SQLException e) {
    // ignored.
    }
    if (inputRows == null || outputBytes == null || rowWidth == null) {
        return Cost.UNKNOWN;
    }
    double inputBytes = inputRows * rowWidth;
    double rowsBeforeHaving = RowCountVisitor.aggregate(RowCountVisitor.filter(inputRows.doubleValue(), RowCountVisitor.stripSkipScanFilter(context.getScan().getFilter())), groupBy);
    double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, having);
    double bytesBeforeHaving = rowWidth * rowsBeforeHaving;
    double bytesAfterHaving = rowWidth * rowsAfterHaving;
    int parallelLevel = CostUtil.estimateParallelLevel(true, context.getConnection().getQueryServices());
    Cost cost = new Cost(0, 0, inputBytes);
    Cost aggCost = CostUtil.estimateAggregateCost(inputBytes, bytesBeforeHaving, groupBy, parallelLevel);
    cost = cost.plus(aggCost);
    if (!orderBy.getOrderByExpressions().isEmpty()) {
        parallelLevel = CostUtil.estimateParallelLevel(false, context.getConnection().getQueryServices());
        Cost orderByCost = CostUtil.estimateOrderByCost(bytesAfterHaving, outputBytes, parallelLevel);
        cost = cost.plus(orderByCost);
    }
    return cost;
}
Also used : ByteCountVisitor(org.apache.phoenix.execute.visitor.ByteCountVisitor) AvgRowWidthVisitor(org.apache.phoenix.execute.visitor.AvgRowWidthVisitor) SQLException(java.sql.SQLException) Cost(org.apache.phoenix.optimize.Cost)

Example 9 with Cost

use of org.apache.phoenix.optimize.Cost in project phoenix by apache.

the class SortMergeJoinPlan method getCost.

@Override
public Cost getCost() {
    Double byteCount = this.accept(new ByteCountVisitor());
    if (byteCount == null) {
        return Cost.UNKNOWN;
    }
    Cost cost = new Cost(0, 0, byteCount);
    return cost.plus(lhsPlan.getCost()).plus(rhsPlan.getCost());
}
Also used : ByteCountVisitor(org.apache.phoenix.execute.visitor.ByteCountVisitor) Cost(org.apache.phoenix.optimize.Cost)

Aggregations

Cost (org.apache.phoenix.optimize.Cost)9 ByteCountVisitor (org.apache.phoenix.execute.visitor.ByteCountVisitor)6 SQLException (java.sql.SQLException)4 AvgRowWidthVisitor (org.apache.phoenix.execute.visitor.AvgRowWidthVisitor)3 RowCountVisitor (org.apache.phoenix.execute.visitor.RowCountVisitor)3 Scan (org.apache.hadoop.hbase.client.Scan)2 ParameterMetaData (java.sql.ParameterMetaData)1 List (java.util.List)1 Set (java.util.Set)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ColumnResolver (org.apache.phoenix.compile.ColumnResolver)1 ExplainPlan (org.apache.phoenix.compile.ExplainPlan)1 GroupBy (org.apache.phoenix.compile.GroupByCompiler.GroupBy)1 JoinTable (org.apache.phoenix.compile.JoinCompiler.JoinTable)1 Table (org.apache.phoenix.compile.JoinCompiler.Table)1 OrderBy (org.apache.phoenix.compile.OrderByCompiler.OrderBy)1 QueryPlan (org.apache.phoenix.compile.QueryPlan)1 RowProjector (org.apache.phoenix.compile.RowProjector)1 SequenceManager (org.apache.phoenix.compile.SequenceManager)1 StatementContext (org.apache.phoenix.compile.StatementContext)1