You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Davide Giannella (JIRA)" <ji...@apache.org> on 2015/10/22 14:08:27 UTC

[jira] [Commented] (OAK-2733) Option to convert "like" queries to range queries

    [ https://issues.apache.org/jira/browse/OAK-2733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14969017#comment-14969017 ] 

Davide Giannella commented on OAK-2733:
---------------------------------------

With OAK-1617 we added a second layer of optimisations on the Query. In it we could generate both like as range and like as like and let the cost calculation decide whether it will be cheaper to run one versus the other.

> Option to convert "like" queries to range queries
> -------------------------------------------------
>
>                 Key: OAK-2733
>                 URL: https://issues.apache.org/jira/browse/OAK-2733
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: query
>            Reporter: Thomas Mueller
>            Assignee: Thomas Mueller
>              Labels: performance
>
> Queries with "like" conditions of the form "x like 'abc%'" are currently always converted to range queries. With Apache Lucene, using "like" in some cases is a bit faster (but not much, according to our tests).
> Converting "like" to range queries should be disabled by default.
> Potential patch:
> {noformat}
> --- src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java	(revision 1672070)
> +++ src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java	(working copy)
> @@ -31,11 +31,21 @@
>  import org.apache.jackrabbit.oak.query.fulltext.LikePattern;
>  import org.apache.jackrabbit.oak.query.index.FilterImpl;
>  import org.apache.jackrabbit.oak.spi.query.PropertyValues;
> +import org.slf4j.Logger;
> +import org.slf4j.LoggerFactory;
>  
>  /**
>   * A comparison operation (including "like").
>   */
>  public class ComparisonImpl extends ConstraintImpl {
> +    
> +    static final Logger LOG = LoggerFactory.getLogger(ComparisonImpl.class);
> +    
> +    private final static boolean CONVERT_LIKE_TO_RANGE = Boolean.getBoolean("oak.convertLikeToRange");
> +    
> +    static {
> +        LOG.info("Converting like to range queries is " + (CONVERT_LIKE_TO_RANGE ? "enabled" : "disabled"));
> +    }
>  
>      private final DynamicOperandImpl operand1;
>      private final Operator operator;
> @@ -193,7 +203,7 @@
>                      if (lowerBound.equals(upperBound)) {
>                          // no wildcards
>                          operand1.restrict(f, Operator.EQUAL, v);
> -                    } else if (operand1.supportsRangeConditions()) {
> +                    } else if (operand1.supportsRangeConditions() && CONVERT_LIKE_TO_RANGE) {
>                          if (lowerBound != null) {
>                              PropertyValue pv = PropertyValues.newString(lowerBound);
>                              operand1.restrict(f, Operator.GREATER_OR_EQUAL, pv);
> @@ -203,7 +213,7 @@
>                              operand1.restrict(f, Operator.LESS_OR_EQUAL, pv);
>                          }
>                      } else {
> -                        // path conditions
> +                        // path conditions, or conversion is disabled
>                          operand1.restrict(f, operator, v);
>                      }
>                  } else {
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)