Query cost estimation: ordering by an unindexed property not reflected
@@ -1011,8 +1011,12 @@ public class QueryImpl implements Query {
if (p.getSupportsPathRestriction()) {
entryCount = scaleEntryCount(rootState, filter, entryCount);
}
-
+ if (sortOrder == null || p.getSortOrder() != null) {
+ // if the query is unordered, or
+ // if the query contains "order by" and the index can sort on that,
+ // then we don't need to read all entries from the index
entryCount = Math.min(maxEntryCount, entryCount);
+ }
double c = p.getCostPerExecution() + entryCount * p.getCostPerEntry();
if (LOG.isDebugEnabled()) {
