Author: catholicon
Date: Thu Nov  2 21:19:04 2017
New Revision: 1814108

URL: http://svn.apache.org/viewvc?rev=1814108&view=rev
Log:
OAK-6735: Lucene Index: improved cost estimation by using document count per 
field

Incorporate Thomas' request to be more explicit in the field hard-coded
for testing

Modified:
    
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatistics.java
    
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlannerTest.java
    
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatisticsTest.java

Modified: 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatistics.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatistics.java?rev=1814108&r1=1814107&r2=1814108&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatistics.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatistics.java
 Thu Nov  2 21:19:04 2017
@@ -43,7 +43,9 @@ public class IndexStatistics {
     // For ease of tests as there didn't seem an easy way to make an 
IndexReader delegator
     // that would fail calls to reader on-demand.
     static boolean failReadingFields = false;
-    static boolean failReadingFieldJcrTitle = false;
+    static boolean failReadingSyntheticallyFalliableField = false;
+
+    static final String SYNTHETICALLY_FALLIABLE_FIELD = 
"synthetically-falliable-field";
 
     /**
      * @param reader {@link IndexReader} for which statistics need to be 
collected.
@@ -70,7 +72,7 @@ public class IndexStatistics {
                 if (isPropertyField(f)) {
                     int docCntForField = -1;
                     try {
-                        if (failReadingFieldJcrTitle && "jcr:title".equals(f)) 
{
+                        if (failReadingSyntheticallyFalliableField && 
SYNTHETICALLY_FALLIABLE_FIELD.equals(f)) {
                             throw new IOException("Synthetically fail to read 
count for field jcr:title");
                         }
                         docCntForField = reader.getDocCount(f);

Modified: 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlannerTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlannerTest.java?rev=1814108&r1=1814107&r2=1814108&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlannerTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlannerTest.java
 Thu Nov  2 21:19:04 2017
@@ -26,6 +26,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.api.Type.STRINGS;
 import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES;
 import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
+import static 
org.apache.jackrabbit.oak.plugins.index.lucene.IndexStatistics.SYNTHETICALLY_FALLIABLE_FIELD;
 import static 
org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.EVALUATE_PATH_RESTRICTION;
 import static 
org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INDEX_DATA_CHILD_NAME;
 import static 
org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INDEX_RULES;
@@ -66,7 +67,6 @@ import org.apache.jackrabbit.oak.plugins
 import 
org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReader;
 import org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader;
 import 
org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory;
-import 
org.apache.jackrabbit.oak.plugins.index.lucene.util.FunctionIndexProcessor;
 import 
org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyValues;
 import org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider;
@@ -1610,12 +1610,12 @@ public class IndexPlannerTest {
     @Test
     public void unableToReadCountForJcrTitle() throws Exception {
         try {
-            IndexStatistics.failReadingFieldJcrTitle = true;
+            IndexStatistics.failReadingSyntheticallyFalliableField = true;
             String indexPath = "/test";
             IndexDefinitionBuilder idxBuilder = new 
IndexDefinitionBuilder(child(builder, indexPath));
             idxBuilder.indexRule("nt:base").property("foo").propertyIndex();
             idxBuilder.indexRule("nt:base").property("foo1").propertyIndex();
-            
idxBuilder.indexRule("nt:base").property("jcr:title").propertyIndex();
+            
idxBuilder.indexRule("nt:base").property(SYNTHETICALLY_FALLIABLE_FIELD).propertyIndex();
             idxBuilder.indexRule("nt:base").property("bar").propertyIndex();
             NodeState defn = idxBuilder.build();
 
@@ -1624,7 +1624,7 @@ public class IndexPlannerTest {
             IndexDefinition idxDefn = new IndexDefinition(root, defn, 
indexPath);
             Document doc = new Document();
             doc.add(new StringField("foo1", "bar1", Field.Store.NO));
-            doc.add(new StringField("jcr:title", "title", Field.Store.NO));
+            doc.add(new StringField(SYNTHETICALLY_FALLIABLE_FIELD, 
"failingField", Field.Store.NO));
             Directory sampleDirectory = createSampleDirectory(numOfDocs, doc);
             IndexNode node = createIndexNode(idxDefn, sampleDirectory);
 
@@ -1636,16 +1636,16 @@ public class IndexPlannerTest {
             assertEquals(numOfDocs, plan.getEstimatedEntryCount());
 
             filter = createFilter("nt:base");
-            filter.restrictProperty("jcr:title", Operator.EQUAL, 
PropertyValues.newString("bar"));
+            filter.restrictProperty(SYNTHETICALLY_FALLIABLE_FIELD, 
Operator.EQUAL, PropertyValues.newString("bar"));
             planner = new IndexPlanner(node, indexPath, filter, 
Collections.emptyList());
             plan = planner.getPlan();
 
-            // jcr:title's count couldn't be read - so, fallback to numDocs
+            // falliable field's count couldn't be read - so, fallback to 
numDocs
             assertEquals(numOfDocs + 1, plan.getEstimatedEntryCount());
 
             filter = createFilter("nt:base");
             filter.restrictProperty("foo1", Operator.EQUAL, 
PropertyValues.newString("bar"));
-            filter.restrictProperty("jcr:title", Operator.EQUAL, 
PropertyValues.newString("bar"));
+            filter.restrictProperty(SYNTHETICALLY_FALLIABLE_FIELD, 
Operator.EQUAL, PropertyValues.newString("bar"));
             planner = new IndexPlanner(node, indexPath, filter, 
Collections.emptyList());
             plan = planner.getPlan();
 
@@ -1654,20 +1654,20 @@ public class IndexPlannerTest {
 
             filter = createFilter("nt:base");
             filter.restrictProperty("bar", Operator.EQUAL, 
PropertyValues.newString("bar"));
-            filter.restrictProperty("jcr:title", Operator.EQUAL, 
PropertyValues.newString("bar"));
+            filter.restrictProperty(SYNTHETICALLY_FALLIABLE_FIELD, 
Operator.EQUAL, PropertyValues.newString("bar"));
             planner = new IndexPlanner(node, indexPath, filter, 
Collections.emptyList());
             plan = planner.getPlan();
 
             // min() still comes into play even when one field's count 
couldn't be read
             assertEquals(0, plan.getEstimatedEntryCount());
         } finally {
-            IndexStatistics.failReadingFieldJcrTitle = false;
+            IndexStatistics.failReadingSyntheticallyFalliableField = false;
         }
     }
 
     @Test
     public void costForPathTransformation() throws Exception {
-        IndexStatistics.failReadingFieldJcrTitle = true;
+        IndexStatistics.failReadingSyntheticallyFalliableField = true;
         String indexPath = "/test";
         IndexDefinitionBuilder idxBuilder = new 
IndexDefinitionBuilder(child(builder, indexPath));
         idxBuilder.indexRule("nt:base").property("foo").propertyIndex();

Modified: 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatisticsTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatisticsTest.java?rev=1814108&r1=1814107&r2=1814108&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatisticsTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatisticsTest.java
 Thu Nov  2 21:19:04 2017
@@ -34,6 +34,7 @@ import java.io.IOException;
 import java.util.Collections;
 import java.util.List;
 
+import static 
org.apache.jackrabbit.oak.plugins.index.lucene.IndexStatistics.SYNTHETICALLY_FALLIABLE_FIELD;
 import static 
org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.VERSION;
 import static org.junit.Assert.assertEquals;
 
@@ -41,7 +42,7 @@ public class IndexStatisticsTest {
     @After
     public void resetFailFlags() {
         IndexStatistics.failReadingFields = false;
-        IndexStatistics.failReadingFieldJcrTitle = false;
+        IndexStatistics.failReadingSyntheticallyFalliableField = false;
     }
 
     @Test
@@ -132,17 +133,17 @@ public class IndexStatisticsTest {
 
     @Test
     public void unableToReadCountForJcrTitle() throws Exception {
-        IndexStatistics.failReadingFieldJcrTitle = true;
+        IndexStatistics.failReadingSyntheticallyFalliableField = true;
 
         Document doc = new Document();
         doc.add(new StringField("foo1", "bar1", Field.Store.NO));
-        doc.add(new StringField("jcr:title", "title", Field.Store.NO));
+        doc.add(new StringField(SYNTHETICALLY_FALLIABLE_FIELD, "title", 
Field.Store.NO));
         IndexStatistics stats = getStats(createSampleDirectory(doc));
 
         assertEquals(3, stats.numDocs());
         assertEquals(2, stats.getDocCountFor("foo"));
         assertEquals(1, stats.getDocCountFor("foo1"));
-        assertEquals(-1, stats.getDocCountFor("jcr:title"));
+        assertEquals(-1, stats.getDocCountFor(SYNTHETICALLY_FALLIABLE_FIELD));
         assertEquals(0, stats.getDocCountFor("bar"));
     }
 


Reply via email to