diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 0c057e6b9c7..86377c3acf9 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -27,6 +27,10 @@ New Features length computations, to avoid skew from documents that don't have the field. (Ahmet Arslan via Robert Muir) +* SOLR-7876: The QueryTimeout interface now has a isTimeoutEnabled method + that can return false to exit from ExitableDirectoryReader wrapping at + the point fields() is called. (yonik) + API Changes * LUCENE-3312: The API of oal.document was restructured to diff --git a/lucene/core/src/java/org/apache/lucene/index/ExitableDirectoryReader.java b/lucene/core/src/java/org/apache/lucene/index/ExitableDirectoryReader.java index 75cc7aa2641..96fbd2c5e0c 100644 --- a/lucene/core/src/java/org/apache/lucene/index/ExitableDirectoryReader.java +++ b/lucene/core/src/java/org/apache/lucene/index/ExitableDirectoryReader.java @@ -80,7 +80,13 @@ public class ExitableDirectoryReader extends FilterDirectoryReader { @Override public Fields fields() throws IOException { - return new ExitableFields(super.fields(), queryTimeout); + Fields fields = super.fields(); + if (queryTimeout.isTimeoutEnabled()) { + return new ExitableFields(fields, queryTimeout); + } + else { + return fields; // break out of wrapper as soon as possible + } } @Override diff --git a/lucene/core/src/java/org/apache/lucene/index/QueryTimeout.java b/lucene/core/src/java/org/apache/lucene/index/QueryTimeout.java index 09b0017afd5..e519ab787a8 100644 --- a/lucene/core/src/java/org/apache/lucene/index/QueryTimeout.java +++ b/lucene/core/src/java/org/apache/lucene/index/QueryTimeout.java @@ -29,5 +29,10 @@ public interface QueryTimeout { */ public abstract boolean shouldExit(); + /** Returns true if timeouts are enabled for this query (i.e. if shouldExit would ever return true) */ + public default boolean isTimeoutEnabled() { + return true; + } + } diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 9f4ac215121..19dba77cb9f 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -65,6 +65,11 @@ New Features * SOLR-7707: Add StreamExpression Support to RollupStream (Dennis Gove, Joel Bernstein) +Optimizations +---------------------- +* SOLR-7876: Speed up queries and operations that use many terms when timeAllowed has not been + specified. Speedups of up to 8% were observed. (yonik) + Other Changes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java b/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java index 998631cb4ca..919c773bb1e 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java +++ b/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java @@ -49,6 +49,11 @@ public class SolrQueryTimeoutImpl implements QueryTimeout { return timeoutAt.get(); } + @Override + public boolean isTimeoutEnabled() { + return get() != null; + } + /** * Return true if a timeoutAt value is set and the current time has exceeded the set timeOut. */