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 ch...@apache.org on 2014/11/21 08:46:53 UTC

svn commit: r1640868 - in /jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene: IndexDefinition.java IndexPlanner.java LuceneIndexConstants.java LucenePropertyIndex.java

Author: chetanm
Date: Fri Nov 21 07:46:53 2014
New Revision: 1640868

URL: http://svn.apache.org/r1640868
Log:
OAK-2280 - Support path restriction in IndexPlanner

Make usage of path restrictions conditional via index config. Mostly enabled for getting existing testcase passed as it would not perform well for large index size as per current implementation.

So this feature should be considered experimental

Modified:
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java?rev=1640868&r1=1640867&r2=1640868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java Fri Nov 21 07:46:53 2014
@@ -65,6 +65,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.ENTRY_COUNT_PROPERTY_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_COUNT;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.BLOB_SIZE;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.EVALUATE_PATH_RESTRICTION;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.EXCLUDE_PROPERTY_NAMES;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.EXPERIMENTAL_STORAGE;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.FIELD_BOOST;
@@ -143,6 +144,8 @@ class IndexDefinition {
 
     private final boolean testMode;
 
+    private final boolean evaluatePathRestrictions;
+
     private final IndexFormatVersion version;
 
     public IndexDefinition(NodeState root, NodeState defn) {
@@ -180,6 +183,7 @@ class IndexDefinition {
 
         this.relativePropNames = collectRelPropertyNames(relativeProperties);
         this.relativePropsMaxLevels = getRelPropertyMaxLevels(relativeProperties);
+        this.evaluatePathRestrictions = getOptionalValue(defn, EVALUATE_PATH_RESTRICTION, false);
 
         String functionName = getOptionalValue(defn, LuceneIndexConstants.FUNC_NAME, null);
         if (fullTextEnabled && functionName == null){
@@ -277,6 +281,10 @@ class IndexDefinition {
         return testMode;
     }
 
+    public boolean evaluatePathRestrictions() {
+        return evaluatePathRestrictions;
+    }
+
     @Override
     public String toString() {
         return "IndexDefinition : " + indexName;
@@ -337,13 +345,13 @@ class IndexDefinition {
         return null;
     }
 
-        /**
-         * Returns the first indexing rule that applies to the given node
-         * <code>state</code>.
-         *
-         * @param state a node state.
-         * @return the indexing rule or <code>null</code> if none applies.
-         */
+    /**
+     * Returns the first indexing rule that applies to the given node
+     * <code>state</code>.
+     *
+     * @param state a node state.
+     * @return the indexing rule or <code>null</code> if none applies.
+     */
     @CheckForNull
     public IndexingRule getApplicableIndexingRule(Tree state) {
         //This method would be invoked for every node. So be as

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java?rev=1640868&r1=1640867&r2=1640868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java Fri Nov 21 07:46:53 2014
@@ -124,19 +124,20 @@ class IndexPlanner {
             }
         }
 
+        boolean evalPathRestrictions = canEvalPathRestrictions();
         //TODO For the full text case need to determine if all field names
         //used in fulltext expression are fulltext indexed or not
 
         //Fulltext expression can also be like jcr:contains(jcr:content/metadata/@format, 'image')
 
         List<OrderEntry> sortOrder = createSortOrder(indexingRule);
-        if (!indexedProps.isEmpty() || !sortOrder.isEmpty() || ft != null) {
+        if (!indexedProps.isEmpty() || !sortOrder.isEmpty() || ft != null || evalPathRestrictions) {
             //TODO Need a way to have better cost estimate to indicate that
             //this index can evaluate more propertyRestrictions natively (if more props are indexed)
             //For now we reduce cost per entry
             int costPerEntryFactor = indexedProps.size();
             costPerEntryFactor += sortOrder.size();
-            
+
             //this index can evaluate more propertyRestrictions natively (if more props are indexed)
             //For now we reduce cost per entry
             IndexPlan.Builder plan = defaultPlan();
@@ -156,6 +157,16 @@ class IndexPlanner {
         return null;
     }
 
+    private boolean canEvalPathRestrictions() {
+        if (filter.getPathRestriction() == Filter.PathRestriction.NO_RESTRICTION){
+            return false;
+        }
+        //TODO If no other restrictions is provided and query is pure
+        //path restriction based then need to be sure that index definition at least
+        //allows indexing all the path for given nodeType
+        return defn.evaluatePathRestrictions();
+    }
+
     private IndexPlan.Builder defaultPlan() {
         return new IndexPlan.Builder()
                 .setCostPerExecution(1) // we're local. Low-cost

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java?rev=1640868&r1=1640867&r2=1640868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java Fri Nov 21 07:46:53 2014
@@ -140,4 +140,6 @@ public interface LuceneIndexConstants {
      * and it should participate in every test
      */
     String TEST_MODE = "testMode";
+
+    String EVALUATE_PATH_RESTRICTION = "oak.experimental.evaluatePathRestrictions";
 }

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java?rev=1640868&r1=1640867&r2=1640868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java Fri Nov 21 07:46:53 2014
@@ -167,8 +167,6 @@ public class LucenePropertyIndex impleme
      */
     static final int LUCENE_QUERY_BATCH_SIZE = 50;
 
-    static final boolean USE_PATH_RESTRICTION = Boolean.getBoolean("oak.luceneUsePath");
-
     protected final IndexTracker tracker;
 
     private final Analyzer analyzer;
@@ -571,14 +569,16 @@ public class LucenePropertyIndex impleme
             IndexPlan plan, IndexReader reader) {
         Filter filter = plan.getFilter();
         PlanResult planResult = pr(plan);
+        IndexDefinition defn = planResult.indexDefinition;
         if (!filter.matchesAllTypes()) {
             addNodeTypeConstraints(planResult.indexingRule, qs, filter);
         }
 
         String path = filter.getPath();
+        //TODO Readjust path based on pathPrefix of the index
         switch (filter.getPathRestriction()) {
         case ALL_CHILDREN:
-            if (USE_PATH_RESTRICTION) {
+            if (defn.evaluatePathRestrictions()) {
                 if ("/".equals(path)) {
                     break;
                 }
@@ -589,7 +589,7 @@ public class LucenePropertyIndex impleme
             }
             break;
         case DIRECT_CHILDREN:
-            if (USE_PATH_RESTRICTION) {
+            if (defn.evaluatePathRestrictions()) {
                 if (!path.endsWith("/")) {
                     path += "/";
                 }