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);
}
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;
}
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;
}
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());
}
Aggregations