Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog/unreleased/SOLR-17985-fix-slow-no-rows-queries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
title: Make distributed no-rows queries fast again
type: fixed # added, changed, fixed, deprecated, removed, dependency_update, security, other
authors:
- name: Houston Putman
nick: HoustonPutman
url: https://home.apache.org/phonebook.html?uid=houston
links:
- name: SOLR-17985
url: https://issues.apache.org/jira/browse/SOLR-17985
Original file line number Diff line number Diff line change
Expand Up @@ -832,20 +832,24 @@ protected void createMainQuery(ResponseBuilder rb) {
// perhaps we shouldn't attempt to parse the query at this level?
// Alternate Idea: instead of specifying all these things at the upper level,
// we could just specify that this is a shard request.
int shardRows;
if (rb.shards_rows > -1) {
// if the client set shards.rows set this explicity
sreq.params.set(CommonParams.ROWS, rb.shards_rows);
shardRows = rb.shards_rows;
} else {
// what if rows<0 as it is allowed for grouped request??
sreq.params.set(
CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
shardRows = rb.getSortSpec().getCount();
// If rows = -1 (grouped requests) or rows = 0, then there is no need to add the offset.
if (shardRows > 0) {
shardRows += rb.getSortSpec().getOffset();
}
}
sreq.params.set(CommonParams.ROWS, shardRows);

sreq.params.set(ResponseBuilder.FIELD_SORT_VALUES, "true");

boolean shardQueryIncludeScore =
(rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0
|| rb.getSortSpec().includesScore();
|| (shardRows != 0 && rb.getSortSpec().includesScore());
StringBuilder additionalFL = new StringBuilder();
boolean additionalAdded = false;
if (rb.onePassDistributedQuery) {
Expand Down
8 changes: 8 additions & 0 deletions solr/core/src/test/org/apache/solr/TestDistributedSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ public void test() throws Exception {
// Check Info is added to for each shard
ModifiableSolrParams q = new ModifiableSolrParams();
q.set("q", "*:*");
q.set("rows", "0");
q.set(ShardParams.SHARDS_INFO, true);
setDistributedParams(q);
rsp = queryRandomShard(q);
Expand All @@ -1560,6 +1561,13 @@ public void test() throws Exception {
assertNotNull("missing shard info", sinfo);
assertEquals(
"should have an entry for each shard [" + sinfo + "] " + shards, cnt, sinfo.size());
// We are setting rows=0, so scores should not be collected
for (int i = 0; i < cnt; i++) {
String shard = sinfo.getName(i);
assertNull(
"should not have any score information (maxScore) in the shard info: " + shard,
((Map<String, Object>) sinfo.get(shard)).get("maxScore"));
}

// test shards.tolerant=true

Expand Down