Author: thomasm
Date: Fri Nov 13 10:22:42 2015
New Revision: 1714180

URL: http://svn.apache.org/viewvc?rev=1714180&view=rev
Log:
OAK-3589 Property index with declaringNodeTypes sometimes used by mistake

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java
    
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java?rev=1714180&r1=1714179&r2=1714180&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java
 Fri Nov 13 10:22:42 2015
@@ -146,6 +146,13 @@ public class PropertyIndexPlan {
                         // covering indexes are not currently supported
                         continue;
                     }
+                    if (depth != 1 && !matchesAllTypes) {
+                        // OAK-3589
+                        // index has a nodetype condition, and the property 
condition is
+                        // relative: can not use this index, as we don't know 
the nodetype
+                        // of the child node (well, we could, for some node 
types)
+                        continue;
+                    }
                     Set<String> values = getValues(restriction);
                     double cost = strategy.count(filter, root, definition, 
values, MAX_COST);
                     if (cost < bestCost) {

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java?rev=1714180&r1=1714179&r2=1714180&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
 Fri Nov 13 10:22:42 2015
@@ -19,9 +19,9 @@
 package org.apache.jackrabbit.oak.jcr.query;
 
 import static com.google.common.collect.Sets.newHashSet;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
@@ -277,6 +277,36 @@ public class QueryTest extends AbstractR
                 rit.nextRow().getValue("plan").getString());
         
     }
+    
+    @Test
+    public void propertyIndexWithDeclaringNodeTypeAndRelativQuery() throws 
RepositoryException {
+        Session session = getAdminSession();
+        RowIterator rit;
+        QueryResult r;
+        String query;
+        query = "//element(*, rep:Authorizable)[@rep:principalName = 'admin']";
+        r = session.getWorkspace().getQueryManager()
+                .createQuery("explain " + query, "xpath").execute();
+        rit = r.getRows();
+        assertEquals("[rep:Authorizable] as [a] /* property principalName = 
admin " + 
+                "where [a].[rep:principalName] = 'admin' */", 
+                rit.nextRow().getValue("plan").getString());
+        
+        query = "//element(*, rep:Authorizable)[admin/@rep:principalName = 
'admin']";
+        r = session.getWorkspace().getQueryManager()
+                .createQuery("explain " + query, "xpath").execute();
+        rit = r.getRows();
+        assertEquals("[rep:Authorizable] as [a] /* nodeType " + 
+                "Filter(query=explain select [jcr:path], [jcr:score], * " + 
+                "from [rep:Authorizable] as a " + 
+                "where [admin/rep:principalName] = 'admin' " + 
+                "/* xpath: //element(*, rep:Authorizable)[" + 
+                "admin/@rep:principalName = 'admin'] */, path=*, " + 
+                "property=[admin/rep:principalName=[admin]]) " + 
+                "where [a].[admin/rep:principalName] = 'admin' */", 
+                rit.nextRow().getValue("plan").getString());
+        
+    }
     
     @Test
     public void date() throws Exception {


Reply via email to