public CostEstimate estimateCost(IndexScan index) {
return estimateCost(index, queryGoal.getLimit());
}
public CostEstimate estimateCost(IndexScan index, long limit) {
PlanCostEstimator estimator = newEstimator();
Set<TableSource> requiredTables = index.getRequiredTables();
estimator.indexScan(index);
if (!index.isCovering()) {
estimator.flatten(tables,
index.getLeafMostTable(), requiredTables);
}
Collection<ConditionExpression> unhandledConditions =
new HashSet<>(requiredConditions);
if (index.getConditions() != null)
unhandledConditions.removeAll(index.getConditions());
if (!unhandledConditions.isEmpty()) {
estimator.select(unhandledConditions,
selectivityConditions(unhandledConditions, requiredTables));
}
if (queryGoal.needSort(index.getOrderEffectiveness())) {
estimator.sort(queryGoal.sortFields());
}
estimator.setLimit(limit);
return estimator.getCostEstimate();
}