jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1525573 - 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
Date Mon, 23 Sep 2013 12:57:43 GMT
Author: thomasm
Date: Mon Sep 23 12:57:42 2013
New Revision: 1525573

URL: http://svn.apache.org/r1525573
Log:
OAK-1035 Property Index: cost calculation is wrong (zero) when searching for many values

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=1525573&r1=1525572&r2=1525573&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
Mon Sep 23 12:57:42 2013
@@ -164,7 +164,9 @@ public class ContentMirrorStoreStrategy 
             int i = 0;
             for (String p : values) {
                 if (count > max && i > 3) {
-                    count = count / size / i;
+                    // the total count is extrapolated from the the number 
+                    // of values counted so far to the total number of values
+                    count = count * size / i;
                     break;
                 }
                 NodeState s = index.getChildNode(p);

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=1525573&r1=1525572&r2=1525573&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
Mon Sep 23 12:57:42 2013
@@ -36,7 +36,6 @@ import java.util.Set;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider;
-import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
 import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 import org.apache.jackrabbit.oak.spi.commit.EditorHook;
@@ -58,6 +57,49 @@ public class PropertyIndexTest {
 
     private static final EditorHook HOOK = new EditorHook(
             new IndexUpdateProvider(new PropertyIndexEditorProvider()));
+    
+    @Test
+    public void costEstimation() throws Exception {
+        NodeState root = INITIAL_CONTENT;
+
+        // Add index definition
+        NodeBuilder builder = root.builder();
+        createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo",
+                true, false, ImmutableSet.of("foo"), null);
+        NodeState before = builder.getNodeState();
+
+        // Add some content and process it through the property index hook
+        for (int i = 0; i < MANY; i++) {
+            builder.child("n" + i).setProperty("foo", "x" + i % 20);
+        }
+        NodeState after = builder.getNodeState();
+
+        NodeState indexed = HOOK.processCommit(before, after);
+
+        FilterImpl f = createFilter(indexed, NT_BASE);
+
+        // Query the index
+        PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
+        double cost;
+        
+        cost = lookup.getCost(f, "foo", PropertyValues.newString("x1"));
+        assertTrue("cost: " + cost, cost >= 4.5 && cost <= 5.5);
+        
+        cost = lookup.getCost(f, "foo", PropertyValues.newString(
+                Arrays.asList("x1", "x2")));
+        assertTrue("cost: " + cost, cost >= 9.5 && cost <= 10.5);
+        
+        cost = lookup.getCost(f, "foo", PropertyValues.newString(
+                Arrays.asList("x1", "x2", "x3", "x4", "x5")));
+        assertTrue("cost: " + cost, cost >= 24.5 && cost <= 25.5);
+
+        cost = lookup.getCost(f, "foo", PropertyValues.newString(
+                Arrays.asList("x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x0")));
+        assertTrue("cost: " + cost, cost >= 49.5 && cost <= 50.5);
+
+        cost = lookup.getCost(f, "foo", null);
+        assertTrue("cost: " + cost, cost >= MANY);
+    }
 
     @Test
     public void testPropertyLookup() throws Exception {



Mime
View raw message