@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); }
@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); }
@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); }