jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r220022 - in /incubator/jackrabbit/trunk/core/src: grammar/sql/ java/org/apache/jackrabbit/core/query/lucene/ java/org/apache/jackrabbit/core/query/sql/ java/org/apache/jackrabbit/core/query/xpath/
Date Thu, 21 Jul 2005 08:13:19 GMT
Author: mreutegg
Date: Thu Jul 21 01:13:17 2005
New Revision: 220022

URL: http://svn.apache.org/viewcvs?rev=220022&view=rev
Log:
- Optimize query execution. document frequency for UUID and PARENT field can be served from
cache.
- Reuse query parsers. Results in much lower memory consumption

Modified:
    incubator/jackrabbit/trunk/core/src/grammar/sql/JCRSQL.jjt
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/CachingIndexReader.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java

Modified: incubator/jackrabbit/trunk/core/src/grammar/sql/JCRSQL.jjt
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/grammar/sql/JCRSQL.jjt?rev=220022&r1=220021&r2=220022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/grammar/sql/JCRSQL.jjt (original)
+++ incubator/jackrabbit/trunk/core/src/grammar/sql/JCRSQL.jjt Thu Jul 21 01:13:17 2005
@@ -65,7 +65,7 @@
   	return parser.Query();
   }
 
-  private void setNamespaceResolver(NamespaceResolver resolver) {
+  void setNamespaceResolver(NamespaceResolver resolver) {
         this.resolver = resolver;
   }
 

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/CachingIndexReader.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/CachingIndexReader.java?rev=220022&r1=220021&r2=220022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/CachingIndexReader.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/CachingIndexReader.java
Thu Jul 21 01:13:17 2005
@@ -146,6 +146,28 @@
     }
 
     /**
+     * Provides an efficient lookup of document frequency for terms with field
+     * {@link FieldNames#UUID} and {@link FieldNames#PARENT}. All other calles
+     * are handled by the base class.
+     *
+     * @param t the term to look up the document frequency.
+     * @return the document frequency of term <code>t</code>.
+     * @throws IOException if an error occurs while reading from the index.
+     */
+    public int docFreq(Term t) throws IOException {
+        synchronized (this) {
+            cacheInit();
+            if (t.field() == FieldNames.UUID) {
+                return idCache.containsKey(t.text()) ? 1 : 0;
+            } else if (t.field() == FieldNames.PARENT) {
+                List children = (List) parentCache.get(t.text());
+                return children == null ? 0 : children.size();
+            }
+        }
+        return super.docFreq(t);
+    }
+
+    /**
      * Removes the <code>TermEnum</code> from the idCache and calls the base
      * <code>IndexReader</code>.
      * @param n the number of the document to delete.

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java?rev=220022&r1=220021&r2=220022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
Thu Jul 21 01:13:17 2005
@@ -46,6 +46,9 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.io.StringReader;
 
 /**
  * Implements the query builder for the JCR SQL syntax.
@@ -64,6 +67,12 @@
     private static final String DATE_PATTERN = "yyyy-MM-dd";
 
     /**
+     * Map of reusable JCRSQL parser instances indexed by NamespaceResolver.
+     */
+    private static Map parsers = new WeakHashMap();
+
+
+    /**
      * The root node of the sql query syntax tree
      */
     private final ASTQuery stmt;
@@ -111,7 +120,23 @@
     public static QueryRootNode createQuery(String statement, NamespaceResolver resolver)
             throws InvalidQueryException {
         try {
-            JCRSQLQueryBuilder builder = new JCRSQLQueryBuilder(JCRSQLParser.parse(statement,
resolver), resolver);
+            // get parser
+            JCRSQLParser parser;
+            synchronized (parsers) {
+                parser = (JCRSQLParser) parsers.get(resolver);
+                if (parser == null) {
+                    parser = new JCRSQLParser(new StringReader(statement));
+                    parser.setNamespaceResolver(resolver);
+                    parsers.put(resolver, parser);
+                }
+            }
+
+            JCRSQLQueryBuilder builder;
+            // guard against concurrent use within same session
+            synchronized (parser) {
+                parser.ReInit(new StringReader(statement));
+                builder = new JCRSQLQueryBuilder(parser.Query(), resolver);
+            }
             return builder.getRootNode();
         } catch (ParseException e) {
             throw new InvalidQueryException(e.getMessage());

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java?rev=220022&r1=220021&r2=220022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
Thu Jul 21 01:13:17 2005
@@ -45,6 +45,8 @@
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
 
 /**
  * Query builder that translates a XPath statement into a query tree structure.
@@ -192,12 +194,17 @@
     private static final String OP_SIGN_LE = "<=";
 
     /**
+     * Map of reusable XPath parser instances indexed by NamespaceResolver.
+     */
+    private static Map parsers = new WeakHashMap();
+
+    /**
      * The root <code>QueryNode</code>
      */
     private final QueryRootNode root = new QueryRootNode();
 
     /**
-     * The {@link org.apache.jackrabbit.core.NamespaceResolver} in use
+     * The {@link NamespaceResolver} in use
      */
     private final NamespaceResolver resolver;
 
@@ -220,8 +227,23 @@
             // create an XQuery statement because we're actually using an
             // XQuery parser.
             statement = "for $v in " + statement + " return $v";
-            XPath query = new XPath(new StringReader(statement));
-            query.XPath2().jjtAccept(this, root);
+            // get parser
+            XPath parser;
+            synchronized (parsers) {
+                parser = (XPath) parsers.get(resolver);
+                if (parser == null) {
+                    parser = new XPath(new StringReader(statement));
+                    parsers.put(resolver, parser);
+                }
+            }
+
+            SimpleNode query;
+            // guard against concurrent use within same session
+            synchronized (parser) {
+                parser.ReInit(new StringReader(statement));
+                query = parser.XPath2();
+            }
+            query.jjtAccept(this, root);
         } catch (ParseException e) {
             throw new InvalidQueryException(e.getMessage(), e);
         } catch (Throwable t) {



Mime
View raw message