DynamicOperandImpl op = o.getOperand();
if (!(op instanceof PropertyValueImpl)) {
// ordered by a function: currently not supported
break;
}
PropertyValueImpl p = (PropertyValueImpl) op;
SelectorImpl s = p.getSelectors().iterator().next();
if (!s.equals(filter.getSelector())) {
// ordered by a different selector
continue;
}
OrderEntry e = new OrderEntry(
p.getPropertyName(),
Type.UNDEFINED,
o.isDescending() ?
OrderEntry.Order.DESCENDING : OrderEntry.Order.ASCENDING);
sortOrder.add(e);
}
if (sortOrder.size() == 0) {
sortOrder = null;
}
}
long maxEntryCount = limit;
if (offset > 0) {
if (offset + limit < 0) {
// long overflow
maxEntryCount = Long.MAX_VALUE;
} else {
maxEntryCount = offset + limit;
}
}
List<IndexPlan> ipList = advIndex.getPlans(
filter, sortOrder, rootState);
cost = Double.POSITIVE_INFINITY;
for (IndexPlan p : ipList) {
// TODO limit is after all conditions
long entryCount = Math.min(maxEntryCount, p.getEstimatedEntryCount());
double c = p.getCostPerExecution() + entryCount * p.getCostPerEntry();
if (c < cost) {
cost = c;
indexPlan = p;
}
}