[ 
https://issues.apache.org/jira/browse/OAK-4887?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16253245#comment-16253245
 ] 

Thomas Mueller commented on OAK-4887:
-------------------------------------

Actually I found Lucene returns all plans. It is true that right now, the order 
doesn't affect the cost. The following patch (not test yet) should resolve this 
issue:

{noformat}
--- src/main/java/org/apache/jackrabbit/oak/query/QueryImpl.java        
(revision 1814727)
+++ src/main/java/org/apache/jackrabbit/oak/query/QueryImpl.java        
(working copy)
@@ -1004,8 +1004,12 @@
                     if (p.getSupportsPathRestriction()) {
                         entryCount = scaleEntryCount(rootState, filter, 
entryCount);
                     }
-                    
-                    entryCount = Math.min(maxEntryCount, 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()) {
{noformat}


> Query cost estimation: ordering by an unindexed property not reflected
> ----------------------------------------------------------------------
>
>                 Key: OAK-4887
>                 URL: https://issues.apache.org/jira/browse/OAK-4887
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: query
>    Affects Versions: 1.4.2
>            Reporter: Alexander Klimetschek
>            Assignee: Thomas Mueller
>             Fix For: 1.8
>
>
> A query that orders by an unindexed property seems to have no effect on the 
> cost estimation, compared to the same query without the order by, although it 
> has a big impact on the execution performance for larger results/indexes.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to