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 2017/08/18 12:16:44 UTC

svn commit: r1805407 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/ test/java/org/apache/jackrabbit/oak/plugins/index/property/ test/resources/org/apache/jackrabbit/oak/query/

Author: thomasm
Date: Fri Aug 18 12:16:44 2017
New Revision: 1805407

URL: http://svn.apache.org/viewvc?rev=1805407&view=rev
Log:
OAK-937 Query engine index selection tweaks: shortcut and hint

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OptionIndexTagTests.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
    jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java?rev=1805407&r1=1805406&r2=1805407&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java Fri Aug 18 12:16:44 2017
@@ -180,7 +180,7 @@ public class SQL2Parser {
                     if (readIf("NAME")) {
                         options.indexName = readName();
                     } else if (readIf("TAG")) {
-                        options.indexTag = readName();
+                        options.indexTag = readLabel();
                     }
                 } else {
                     break;
@@ -290,6 +290,14 @@ public class SQL2Parser {
 
         return factory.selector(nodeTypeInfo, selectorName);
     }
+    
+    private String readLabel() throws ParseException {
+        String label = readName();
+        if (!label.matches("[a-zA-Z0-9_]*") || label.isEmpty() || label.length() > 128) {
+            throw getSyntaxError("a-z, A-Z, 0-9, _");
+        }
+        return label;
+    }
 
     private String readName() throws ParseException {
         if (currentTokenType == END) {

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OptionIndexTagTests.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OptionIndexTagTests.java?rev=1805407&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OptionIndexTagTests.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OptionIndexTagTests.java Fri Aug 18 12:16:44 2017
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.index.property;
+
+import static org.junit.Assert.assertTrue;
+
+import javax.jcr.query.Query;
+
+import org.apache.jackrabbit.oak.InitialContent;
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider;
+import org.apache.jackrabbit.oak.query.AbstractQueryTest;
+import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
+import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
+import org.junit.Test;
+
+public class OptionIndexTagTests extends AbstractQueryTest {
+    
+    Whiteboard wb;
+    
+    @Override
+    protected ContentRepository createRepository() {
+        Oak oak = new Oak().with(new InitialContent())
+            .with(new OpenSecurityProvider())
+            .with(new NodeTypeIndexProvider())
+            .with(new PropertyIndexProvider())
+            .with(new PropertyIndexEditorProvider());
+        return oak.createContentRepository();
+    }
+
+    @Test
+    public void optionIndexTag() throws Exception {
+        // disable the counter index, so that traversal is normally not used
+        // (only used if there is no index)
+        Tree index = root.getTree("/oak:index/counter");
+        index.remove();
+        index = root.getTree("/oak:index/uuid");
+        index.setProperty("tags", "x");
+        root.commit();
+        String statement, result;
+        statement = "explain select * from [mix:versionable] where [jcr:uuid] = 1 option(index tag x)";
+        result = executeQuery(statement, Query.JCR_SQL2, false, false).toString();
+        assertTrue(result, result.indexOf("/* property uuid") >= 0);
+        statement = "explain select * from [mix:versionable] where [jcr:uuid] = 1 option(index tag x, index name uuid)";
+        result = executeQuery(statement, Query.JCR_SQL2, false, false).toString();
+        assertTrue(result, result.indexOf("/* property uuid") >= 0);
+        statement = "explain select * from [mix:versionable] where [jcr:uuid] = 1 option(index tag y, index name uuid)";
+        result = executeQuery(statement, Query.JCR_SQL2, false, false).toString();
+        assertTrue(result, result.indexOf("/* property uuid") >= 0);
+        statement = "explain select * from [mix:versionable] where [jcr:uuid] = 1 option(index tag x, index name nodetype)";
+        result = executeQuery(statement, Query.JCR_SQL2, false, false).toString();
+        assertTrue(result, result.indexOf("/* property uuid") >= 0);
+        
+        statement = "explain select * from [mix:versionable] where [jcr:uuid] = 1 option(index tag y, index name nodetype)";
+        result = executeQuery(statement, Query.JCR_SQL2, false, false).toString();
+        assertTrue(result, result.indexOf("/* nodeType ") >= 0);
+        statement = "explain select * from [mix:versionable] where [jcr:uuid] = 1 option(index name nodetype)";
+        result = executeQuery(statement, Query.JCR_SQL2, false, false).toString();
+        assertTrue(result, result.indexOf("/* nodeType ") >= 0);
+        
+        statement = "explain select * from [mix:versionable] where [jcr:uuid] = 1 option(index tag y)";
+        result = executeQuery(statement, Query.JCR_SQL2, false, false).toString();
+        assertTrue(result, result.indexOf("/* traverse ") >= 0);
+    }
+
+    @Test
+    public void optionIndexName() throws Exception {
+        // disable the counter index, so that traversal is never used
+        Tree index = root.getTree("/oak:index/counter");
+        index.remove();
+        root.commit();
+        String statement, result;
+        statement = "explain select * from [mix:versionable] where [jcr:uuid] = 1 option(index name uuid)";
+        result = executeQuery(statement, Query.JCR_SQL2, false, false).toString();
+        assertTrue(result, result.indexOf("/* property uuid") >= 0);
+        statement = "explain select * from [mix:versionable] where [jcr:uuid] = 1 option(index name nodetype)";
+        result = executeQuery(statement, Query.JCR_SQL2, false, false).toString();
+        assertTrue(result, result.indexOf("/* nodeType ") >= 0);
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt?rev=1805407&r1=1805406&r2=1805407&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt Fri Aug 18 12:16:44 2017
@@ -31,7 +31,10 @@ select [jcr:path], [jcr:score], *
   from [nt:base] as a
   where isdescendantnode(a, '/content') option(index name [b], index tag [a])
   /* xpath ... */
-  
+
+select [jcr:path], [jcr:score], * from [nt:base] as a where isdescendantnode(a, '/content') option(index tag [a-b])
+java.text.ParseException: Query: select [jcr:path], [jcr:score], * from [nt:base] as a where isdescendantnode(a, '/content') option(index tag [a-b](*)); expected: a-z, A-Z, 0-9, _
+
 # OAK-5949
 
 xpath2sql /jcr:root/home//element(*,rep:Authorizable)[jcr:like(@rep:authorizableId,'@')]