Search in sources :

Example 1 with ByteCountVisitor

use of org.apache.phoenix.execute.visitor.ByteCountVisitor in project phoenix by apache.

the class CorrelatePlan method getCost.

@Override
public Cost getCost() {
    Double lhsByteCount = delegate.accept(new ByteCountVisitor());
    Double rhsRowCount = rhs.accept(new RowCountVisitor());
    if (lhsByteCount == null || rhsRowCount == null) {
        return Cost.UNKNOWN;
    }
    Cost cost = new Cost(0, 0, lhsByteCount * rhsRowCount);
    Cost lhsCost = delegate.getCost();
    return cost.plus(lhsCost).plus(rhs.getCost());
}
Also used : ByteCountVisitor(org.apache.phoenix.execute.visitor.ByteCountVisitor) RowCountVisitor(org.apache.phoenix.execute.visitor.RowCountVisitor) Cost(org.apache.phoenix.optimize.Cost)

Example 2 with ByteCountVisitor

use of org.apache.phoenix.execute.visitor.ByteCountVisitor in project phoenix by apache.

the class ClientAggregatePlan method getCost.

@Override
public Cost getCost() {
    Double outputBytes = this.accept(new ByteCountVisitor());
    Double inputRows = this.getDelegate().accept(new RowCountVisitor());
    Double rowWidth = this.accept(new AvgRowWidthVisitor());
    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(false, context.getConnection().getQueryServices());
    Cost cost = CostUtil.estimateAggregateCost(inputBytes, bytesBeforeHaving, groupBy, parallelLevel);
    if (!orderBy.getOrderByExpressions().isEmpty()) {
        Cost orderByCost = CostUtil.estimateOrderByCost(bytesAfterHaving, outputBytes, parallelLevel);
        cost = cost.plus(orderByCost);
    }
    return super.getCost().plus(cost);
}
Also used : ByteCountVisitor(org.apache.phoenix.execute.visitor.ByteCountVisitor) RowCountVisitor(org.apache.phoenix.execute.visitor.RowCountVisitor) AvgRowWidthVisitor(org.apache.phoenix.execute.visitor.AvgRowWidthVisitor) Cost(org.apache.phoenix.optimize.Cost)

Example 3 with ByteCountVisitor

use of org.apache.phoenix.execute.visitor.ByteCountVisitor 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 4 with ByteCountVisitor

use of org.apache.phoenix.execute.visitor.ByteCountVisitor 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 5 with ByteCountVisitor

use of org.apache.phoenix.execute.visitor.ByteCountVisitor 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)

Aggregations

ByteCountVisitor (org.apache.phoenix.execute.visitor.ByteCountVisitor)6 Cost (org.apache.phoenix.optimize.Cost)6 SQLException (java.sql.SQLException)2 AvgRowWidthVisitor (org.apache.phoenix.execute.visitor.AvgRowWidthVisitor)2 RowCountVisitor (org.apache.phoenix.execute.visitor.RowCountVisitor)2