jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1405746 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/old/ main/java/org/apache/jackrabbit/oak/plugins/index/property/ main/java/org/apache/jackrabbit/oak/query/ main/java/org/apache/jackrabbit/...
Date Mon, 05 Nov 2012 11:08:47 GMT
Author: thomasm
Date: Mon Nov  5 11:08:46 2012
New Revision: 1405746

URL: http://svn.apache.org/viewvc?rev=1405746&view=rev
Log:
OAK-404 Log (slow) queries (log queries with level "warn" if more than 100 nodes are traversed)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingCursor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java?rev=1405746&r1=1405745&r2=1405746&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java
Mon Nov  5 11:08:46 2012
@@ -134,5 +134,10 @@ public class PrefixContentIndex implemen
             return false;
         }
     }
+    
+    @Override
+    public String toString() {
+        return index.toString();
+    }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java?rev=1405746&r1=1405745&r2=1405746&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
Mon Nov  5 11:08:46 2012
@@ -138,7 +138,7 @@ public class PropertyIndex implements Qu
         if (paths != null) {
             return new PathCursor(paths);
         } else {
-            return new TraversingCursor(filter, root);
+            return new TraversingCursor("?", filter, root);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java?rev=1405746&r1=1405745&r2=1405746&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
Mon Nov  5 11:08:46 2012
@@ -77,6 +77,7 @@ public class Query {
     private static final Logger LOG = LoggerFactory.getLogger(QueryEngineImpl.class);
 
     final SourceImpl source;
+    final String statement;
     final ConstraintImpl constraint;
     final HashMap<String, PropertyValue> bindVariableMap = new HashMap<String, PropertyValue>();
     final HashMap<String, Integer> selectorIndexes = new HashMap<String, Integer>();
@@ -93,8 +94,9 @@ public class Query {
     private Root root;
     private NamePathMapper namePathMapper;
 
-    Query(SourceImpl source, ConstraintImpl constraint, OrderingImpl[] orderings,
+    Query(String statement, SourceImpl source, ConstraintImpl constraint, OrderingImpl[]
orderings,
           ColumnImpl[] columns) {
+        this.statement = statement;
         this.source = source;
         this.constraint = constraint;
         this.orderings = orderings;
@@ -566,7 +568,7 @@ public class Query {
     }
 
     public QueryIndex getBestIndex(Filter filter) {
-        return queryEngine.getBestIndex(filter);
+        return queryEngine.getBestIndex(this, filter);
     }
 
     public void setRoot(Root root) {
@@ -617,4 +619,8 @@ public class Query {
         return size;
     }
 
+    public String getStatement() {
+        return statement;
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java?rev=1405746&r1=1405745&r2=1405746&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
Mon Nov  5 11:08:46 2012
@@ -119,14 +119,14 @@ public class QueryEngineImpl {
         return q.executeQuery(this.root);
     }
 
-    public QueryIndex getBestIndex(Filter filter) {
+    public QueryIndex getBestIndex(Query query, Filter filter) {
         QueryIndex best = null;
         double bestCost = Double.MAX_VALUE;
         for (QueryIndex index : getIndexes()) {
             double cost = index.getCost(filter, root);
             if (LOG.isDebugEnabled()) {
                 LOG.debug("cost for " + index + " is " + cost);
-            }            
+            }
             if (cost < bestCost) {
                 bestCost = cost;
                 best = index;
@@ -136,7 +136,7 @@ public class QueryEngineImpl {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("no indexes found - using TraversingIndex; indexProvider: " + indexProvider);
             }
-            best = new TraversingIndex();
+            best = new TraversingIndex(query.getStatement());
         }
         return best;
     }

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=1405746&r1=1405745&r2=1405746&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
Mon Nov  5 11:08:46 2012
@@ -134,7 +134,7 @@ public class SQL2Parser {
         if (!currentToken.isEmpty()) {
             throw getSyntaxError("<end>");
         }
-        Query q = new Query(source, constraint, orderings, columnArray);
+        Query q = new Query(statement, source, constraint, orderings, columnArray);
         q.setExplain(explain);
         q.setMeasure(measure);
         try {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingCursor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingCursor.java?rev=1405746&r1=1405745&r2=1405746&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingCursor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingCursor.java
Mon Nov  5 11:08:46 2012
@@ -26,6 +26,9 @@ import org.apache.jackrabbit.oak.spi.que
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.google.common.collect.Iterators;
 import com.google.common.collect.Queues;
 
@@ -34,6 +37,10 @@ import com.google.common.collect.Queues;
  */
 public class TraversingCursor implements Cursor {
 
+    private static final Logger LOG = LoggerFactory.getLogger(TraversingIndex.class);
+
+    private final String statement;
+    
     private final Filter filter;
 
     private final Deque<Iterator<? extends ChildNodeEntry>> nodeIterators =
@@ -42,8 +49,11 @@ public class TraversingCursor implements
     private String parentPath;
 
     private String currentPath;
+    
+    private long readCount;
 
-    public TraversingCursor(Filter filter, NodeState root) {
+    public TraversingCursor(String statement, Filter filter, NodeState root) {
+        this.statement = statement;
         this.filter = filter;
 
         String path = filter.getPath();
@@ -100,6 +110,12 @@ public class TraversingCursor implements
             Iterator<? extends ChildNodeEntry> iterator = nodeIterators.getLast();
             if (iterator.hasNext()) {
                 ChildNodeEntry entry = iterator.next();
+                
+                readCount++;
+                if (readCount % 100 == 0) {
+                    LOG.warn("Traversed " + readCount + " nodes with filter " + filter +
" for query " + statement + "; consider creating an index or changing the query");
+                }
+                
                 NodeState node = entry.getNodeState();
 
                 String name = entry.getName();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java?rev=1405746&r1=1405745&r2=1405746&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
Mon Nov  5 11:08:46 2012
@@ -28,10 +28,16 @@ import org.apache.jackrabbit.oak.spi.sta
  * An index that traverses over a given subtree.
  */
 public class TraversingIndex implements QueryIndex {
+    
+    private final String statement;
+    
+    public TraversingIndex(String statement) {
+        this.statement = statement;
+    }
 
     @Override
     public Cursor query(Filter filter, NodeState root) {
-        return new TraversingCursor(filter, root);
+        return new TraversingCursor(statement, filter, root);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java?rev=1405746&r1=1405745&r2=1405746&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
Mon Nov  5 11:08:46 2012
@@ -64,7 +64,7 @@ public class TraversingIndexTest {
 
     @Test
     public void traverse() throws Exception {
-        TraversingIndex t = new TraversingIndex();
+        TraversingIndex t = new TraversingIndex("?");
 
         String head = mk.getHeadRevision();
         head = mk.commit("/", "+ \"parents\": { \"p0\": {\"id\": \"0\"}, \"p1\": {\"id\":
\"1\"}, \"p2\": {\"id\": \"2\"}}", head, "");



Mime
View raw message