dsmiley commented on code in PR #5298:
URL: https://github.com/apache/solr/pull/5298#discussion_r4725182576


##########
solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java:
##########
@@ -931,4 +896,64 @@ private SolrDocument getSolrDoc(int luceneDocId) {
       return sdoc;
     }
   }
+
+  /**
+   * Returns the stored fields selected by the response and its transformers, 
before DocValues
+   * substitution. A null result means all stored fields; otherwise the 
returned set is mutable.
+   */
+  public Set<String> getStoredFieldsToLoad(ReturnFields returnFields) {
+    final Set<String> storedFields = new HashSet<>();
+    Set<String> fnames = returnFields.getLuceneFieldNames();
+    if (returnFields.returnsAllFields()) {
+      return null;
+    } else if (returnFields.hasPatternMatching()) {
+      for (String s : getAllStored()) {
+        if (returnFields.loadsField(s)) {
+          storedFields.add(s);
+        }
+      }
+    } else if (fnames != null) {
+      storedFields.addAll(fnames);
+      storedFields.removeIf(
+          (String name) -> {
+            SchemaField schemaField = 
searcher.getSchema().getFieldOrNull(name);
+            if (schemaField == null) {
+              // Get it from the stored fields if, for some reason, we can't 
get the schema.
+              return false;
+            }
+            if (schemaField.stored() && schemaField.multiValued()) {
+              // must return multivalued fields from stored data if possible.
+              return false;
+            }
+            if (schemaField.stored() == false) {
+              // if it's not stored, no choice but to return from DV.
+              return true;
+            }
+            return false;
+          });
+    }
+    storedFields.remove(SolrReturnFields.SCORE);
+    return storedFields;
+  }
+
+  /**
+   * Returns a mutable field filter for prefetch, or null to skip prefetch. 
Preserve the original
+   * explicit-field filter; only pattern selections expand stored fields and 
apply DocValues
+   * substitution. An empty pattern filter can still gain fields from 
highlighting.
+   */
+  public Set<String> getStoredFieldsToPrefetch(ReturnFields returnFields) {
+    if (!returnFields.hasPatternMatching()) {

Review Comment:
   The prefetch filter is asymmetric between explicit and glob `fl`:
   
   - **Explicit `fl`**: copies `getLuceneFieldNames()` as before. Non-stored 
(DV-only) names stay in, there's no DV-substitution, and prefetch runs even 
when every field could come from DocValues.
   - **Glob `fl`**: goes through `getStoredFieldsToLoad`, so only stored fields 
are kept, the filter is cleared if all can be substituted by DV, and 
`optimizePreFetchDocs` skips prefetch when the filter is empty (that check also 
only applies to globs).
   
   So `fl=price` and `fl=pri*` do different prefetch work for the same logical 
request. For example, with a DV-only single-valued `price` and no highlighting, 
the explicit form still warms a cache entry made up only of lazy placeholders, 
while the glob form skips prefetch.
   
   I see the javadoc says this is deliberate, presumably to keep explicit-`fl` 
behavior unchanged. Could we route both through `getStoredFieldsToLoad` 
instead? That would remove the special case and fix the same inefficiency for 
explicit `fl`. The tradeoff is a behavior change on the common path, which 
would need test coverage.
   
   🤖 This comment was AI-generated.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to