Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 52C4CDA5A for ; Tue, 16 Oct 2012 11:24:28 +0000 (UTC) Received: (qmail 56252 invoked by uid 500); 16 Oct 2012 11:24:27 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 56049 invoked by uid 500); 16 Oct 2012 11:24:21 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 56003 invoked by uid 99); 16 Oct 2012 11:24:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Oct 2012 11:24:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Oct 2012 11:24:17 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4FDBA23888EA for ; Tue, 16 Oct 2012 11:23:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1398737 - /directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java Date: Tue, 16 Oct 2012 11:23:33 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121016112333.4FDBA23888EA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Tue Oct 16 11:23:32 2012 New Revision: 1398737 URL: http://svn.apache.org/viewvc?rev=1398737&view=rev Log: Fix for DIRSERVER-1751 : a substring filter now uses the index to speed up a search Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java?rev=1398737&r1=1398736&r2=1398737&view=diff ============================================================================== --- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java (original) +++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java Tue Oct 16 11:23:32 2012 @@ -45,6 +45,7 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.model.filter.ScopeNode; import org.apache.directory.shared.ldap.model.filter.SimpleNode; import org.apache.directory.shared.ldap.model.filter.SubstringNode; +import org.apache.directory.shared.util.Strings; /** @@ -157,7 +158,7 @@ public class DefaultOptimizer impleme else if ( node instanceof SubstringNode ) { /** Cannot really say so we presume the total index count */ - count = getFullScan( leaf ); + count = getSubstringScan( ( SubstringNode ) leaf ); } else if ( node instanceof ExtensibleNode ) { @@ -305,6 +306,7 @@ public class DefaultOptimizer impleme if ( db.hasIndexOn( node.getAttributeType() ) ) { Index idx = ( Index ) db.getIndex( node.getAttributeType() ); + if ( isGreaterThan ) { return idx.greaterThanCount( node.getValue().getValue() ); @@ -318,6 +320,42 @@ public class DefaultOptimizer impleme // count for non-indexed attribute is unknown so we presume da worst return Long.MAX_VALUE; } + + + /** + * Get a scan count based on a Substring node : we will count the entries that are greater + * than ABC where the filter is (attr=ABC*). Any other filter won't be evaluated (for instance, + * a filter like (attr=*ABC) will resolve to a full scan atm - we could have created a reverted + * index for such a case -, and filters like (attr=*ABC*) also esolve to a full scan). + * + * @param node The substring node + * @return The number of candidates + * @throws Exception If there is an error accessing an index + */ + private long getSubstringScan( SubstringNode node ) throws Exception + { + if ( db.hasIndexOn( node.getAttributeType() ) ) + { + Index idx = ( Index ) db.getIndex( node.getAttributeType() ); + + String initial = node.getInitial(); + + if ( Strings.isEmpty( initial ) ) + { + // Not a (attr=ABC*) filter : full scan + return Long.MAX_VALUE; + } + else + { + return idx.greaterThanCount( initial ); + } + } + else + { + // count for non-indexed attribute is unknown so we presume da worst + return Long.MAX_VALUE; + } + } /**