You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2013/11/28 15:15:56 UTC

svn commit: r1546369 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java

Author: thomasm
Date: Thu Nov 28 14:15:55 2013
New Revision: 1546369

URL: http://svn.apache.org/r1546369
Log:
OAK-1155 PropertyIndex cost calculation is faulty

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java?rev=1546369&r1=1546368&r2=1546369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java Thu Nov 28 14:15:55 2013
@@ -343,20 +343,7 @@ public class ContentMirrorStoreStrategy 
          * The current depth (number of parent nodes).
          */
         int depth;
-        
-        /**
-         * The total number of child nodes per node, for those nodes that were
-         * fully traversed and do have child nodes. This value is used to
-         * calculate the average width.
-         */
-        long widthTotal;
-        
-        /**
-         * The number of nodes that were fully traversed and do have child
-         * nodes. This value is used to calculate the average width.
-         */
-        int widthCount;
-        
+
         /**
          * The sum of the depth of all matching nodes. This value is used to
          * calculate the average depth.
@@ -375,20 +362,12 @@ public class ContentMirrorStoreStrategy 
             }
             if (count < maxCount) {
                 depth++;
-                int width = 0;
-                boolean finished = true;
                 for (ChildNodeEntry entry : state.getChildNodeEntries()) {
                     if (count >= maxCount) {
-                        finished = false;
                         break;
                     }
-                    width++;
                     visit(entry.getNodeState());
                 }
-                if (finished && width > 0) {
-                    widthTotal += width;
-                    widthCount++;
-                }
                 depth--;
             }
         }
@@ -415,15 +394,9 @@ public class ContentMirrorStoreStrategy 
                 return count;
             }
             double averageDepth = (int) (depthTotal / count);
-            double averageWidth = 2;
-            if (widthCount > 0) {
-                averageWidth = (int) (widthTotal / widthCount);
-            }
-            // calculate with an average width of at least 2
-            averageWidth = Math.max(2, averageWidth);
-            // the number of estimated matches is calculated as the
-            // of a estimated
-            long estimatedNodes = (long) Math.pow(averageWidth, 2 * averageDepth);
+            // the number of estimated matches is higher
+            // the higher the average depth of the first hits
+            long estimatedNodes = (long) (count * Math.pow(1.1, averageDepth));
             estimatedNodes = Math.min(estimatedNodes, Integer.MAX_VALUE);
             return Math.max(count, (int) estimatedNodes);
         }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java?rev=1546369&r1=1546368&r2=1546369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java Thu Nov 28 14:15:55 2013
@@ -105,7 +105,6 @@ public class PropertyIndexTest {
     }
 
     @Test
-    @Ignore("OAK-1155")
     public void costMaxEstimation() throws Exception {
         NodeState root = EmptyNodeState.EMPTY_NODE;
 
@@ -116,20 +115,20 @@ public class PropertyIndexTest {
         NodeState before = builder.getNodeState();
 
         // 100 nodes in the index:
-        // with a single level /content cost is 6250000
-        // adding a second level /content/data cost jumps to 1.544804416E9
+        // with a single level /content cost is 121
+        // adding a second level /content/data cost is133
 
         // 101 nodes in the index:
-        // with a single level /content cost is 100
-        // adding a second level /content/data stays at 100
+        // with a single level /content cost is 121
+        // adding a second level /content/data cost is 133
 
-        // 100 nodes, 12 levels deep, cost is 2.147483647E9
-        // 101 nodes, 12 levels deep, cost is 6.7108864E7
+        // 100 nodes, 12 levels deep, cost is 345
+        // 101 nodes, 12 levels deep, cost is 345
 
         // threshold for estimation (PropertyIndexLookup.MAX_COST) is at 100
-        int nodes = 100;
+        int nodes = 101;
         int levels = 12;
-
+        
         NodeBuilder data = builder;
         for (int i = 0; i < levels; i++) {
             data = data.child("l" + i);