You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by kr...@apache.org on 2024/01/24 19:12:04 UTC

(solr) branch optimize-rows-zero created (now 841defcaf8e)

This is an automated email from the ASF dual-hosted git repository.

krisden pushed a change to branch optimize-rows-zero
in repository https://gitbox.apache.org/repos/asf/solr.git


      at 841defcaf8e optimize-rows-zero

This branch includes the following new commits:

     new 841defcaf8e optimize-rows-zero

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(solr) 01/01: optimize-rows-zero

Posted by kr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch optimize-rows-zero
in repository https://gitbox.apache.org/repos/asf/solr.git

commit 841defcaf8ebf57ddc74340b23d1fd06cab5ac79
Author: Kevin Risden <kr...@apache.org>
AuthorDate: Wed Jan 24 13:52:24 2024 -0500

    optimize-rows-zero
---
 .../org/apache/solr/search/SolrIndexSearcher.java  | 15 +++++++++++-
 .../apache/solr/search/TestMainQueryCaching.java   | 27 ++--------------------
 2 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
index 9c3a2fbc2f3..01ea3d4d3c5 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -1617,9 +1617,16 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
     // check if we should try and use the filter cache
     final boolean needSort;
     final boolean useFilterCache;
+    final boolean useFilterCacheForQuery;
     if ((flags & (GET_SCORES | NO_CHECK_FILTERCACHE)) != 0 || filterCache == null) {
       needSort = true; // this value should be irrelevant when `useFilterCache=false`
       useFilterCache = false;
+      useFilterCacheForQuery = useFilterCache;
+    } else if (cmd.getLen() == 0) {
+      // No rows are being returned so no need to sort and can use the filterCache
+      needSort = false;
+      useFilterCache = true;
+      useFilterCacheForQuery = false;
     } else if (q instanceof MatchAllDocsQuery
         || (useFilterForSortedQuery && QueryUtils.isConstantScoreQuery(q))) {
       // special-case MatchAllDocsQuery: implicit default useFilterForSortedQuery=true;
@@ -1643,10 +1650,12 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
         useFilterCache =
             Arrays.stream(sort.getSort()).noneMatch((sf) -> sf.getType() == SortField.Type.SCORE);
       }
+      useFilterCacheForQuery = useFilterCache;
     } else {
       // for non-constant-score queries, must sort unless no docs requested
       needSort = cmd.getLen() > 0;
       useFilterCache = useFilterCacheForDynamicScoreQuery(needSort, cmd);
+      useFilterCacheForQuery = useFilterCache;
     }
 
     if (useFilterCache) {
@@ -1654,7 +1663,11 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
       // for large filters that match few documents, this may be
       // slower than simply re-executing the query.
       if (out.docSet == null) {
-        out.docSet = getDocSet(cmd.getQuery());
+        if (useFilterCacheForQuery) {
+          out.docSet = getDocSet(cmd.getQuery());
+        } else {
+          out.docSet = getDocSetNC(QueryUtils.getAbs(cmd.getQuery()), null);
+        }
         List<Query> filterList = cmd.getFilterList();
         if (filterList != null && !filterList.isEmpty()) {
           out.docSet = DocSetUtil.getDocSet(out.docSet.intersection(getDocSet(filterList)), this);
diff --git a/solr/core/src/test/org/apache/solr/search/TestMainQueryCaching.java b/solr/core/src/test/org/apache/solr/search/TestMainQueryCaching.java
index 8a298be2cb1..184eade8b3e 100644
--- a/solr/core/src/test/org/apache/solr/search/TestMainQueryCaching.java
+++ b/solr/core/src/test/org/apache/solr/search/TestMainQueryCaching.java
@@ -184,13 +184,7 @@ public class TestMainQueryCaching extends SolrTestCaseJ4 {
                 "0",
                 "sort",
                 (random().nextBoolean() ? "id asc" : "score desc")));
-    final int insertAndSkipCount = USE_FILTER_FOR_SORTED_QUERY ? 1 : 0;
-    assertMetricCounts(
-        response,
-        false,
-        insertAndSkipCount,
-        USE_FILTER_FOR_SORTED_QUERY ? 0 : 1,
-        insertAndSkipCount);
+    assertMetricCounts(response, false, 0, 0, 1);
   }
 
   @Test
@@ -363,24 +357,7 @@ public class TestMainQueryCaching extends SolrTestCaseJ4 {
                 "0",
                 "sort",
                 random().nextBoolean() ? "id asc" : "score desc,id asc"));
-    final boolean consultMatchAllDocs;
-    final boolean insertFilterCache;
-    final boolean skipSort;
-    if (MATCH_ALL_DOCS_QUERY.equals(q)) {
-      consultMatchAllDocs = true;
-      insertFilterCache = false;
-      skipSort = true;
-    } else {
-      consultMatchAllDocs = false;
-      insertFilterCache = USE_FILTER_FOR_SORTED_QUERY;
-      skipSort = USE_FILTER_FOR_SORTED_QUERY;
-    }
-    assertMetricCounts(
-        response,
-        consultMatchAllDocs,
-        insertFilterCache ? 1 : 0,
-        skipSort ? 0 : 1,
-        skipSort ? 1 : 0);
+    assertMetricCounts(response, MATCH_ALL_DOCS_QUERY.equals(q), 0, 0, 1);
   }
 
   private static void assertMetricCounts(