jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1564752 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
Date Wed, 05 Feb 2014 12:55:53 GMT
Author: thomasm
Date: Wed Feb  5 12:55:53 2014
New Revision: 1564752

URL: http://svn.apache.org/r1564752
Log:
Query: an index is used even where traversing is faster (WIP: improved cost estimation)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java?rev=1564752&r1=1564751&r2=1564752&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
Wed Feb  5 12:55:53 2014
@@ -22,6 +22,7 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.spi.query.Cursor;
 import org.apache.jackrabbit.oak.spi.query.Cursors;
 import org.apache.jackrabbit.oak.spi.query.Filter;
+import org.apache.jackrabbit.oak.spi.query.Filter.PathRestriction;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
@@ -40,15 +41,37 @@ public class TraversingIndex implements 
         if (filter.isAlwaysFalse()) {
             return 0;
         }
-        String path = filter.getPath();
-        // TODO estimate or read the node count
         double nodeCount = 10000000;
-        if (!PathUtils.denotesRoot(path)) {
-            for (int depth = PathUtils.getDepth(path); depth > 0; depth--) {
-                // estimate 10 child nodes per node
-                nodeCount /= 10;
+        String path = filter.getPath();
+        PathRestriction restriction = filter.getPathRestriction();
+        switch (restriction) {
+        case NO_RESTRICTION:
+            break;
+        case EXACT:
+            nodeCount = 1;
+            break;
+        case ALL_CHILDREN:
+            if (!PathUtils.denotesRoot(path)) {
+                for (int depth = PathUtils.getDepth(path); depth > 0; depth--) {
+                    // estimate 10 child nodes per node
+                    nodeCount /= 10;
+                }
             }
-        }
+            break;
+        case PARENT:
+            if (PathUtils.denotesRoot(path)) {
+                nodeCount = 1;
+            } else {
+                nodeCount = PathUtils.getDepth(path);
+            }
+            break;
+        case DIRECT_CHILDREN:
+            // we expect 1 million child nodes in the worst case
+            nodeCount = 1000000;
+            break;
+        default:
+            throw new IllegalArgumentException("Unknown restriction: " + restriction);
+        }        
         return nodeCount;
     }
 



Mime
View raw message