Skip to content

Commit a72691c

Browse files
SOLR-17985: Speed up no-rows distributed queries (#3849)
1 parent 05823a1 commit a72691c

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
2+
title: Make distributed no-rows queries fast again
3+
type: fixed # added, changed, fixed, deprecated, removed, dependency_update, security, other
4+
authors:
5+
- name: Houston Putman
6+
nick: HoustonPutman
7+
url: https://home.apache.org/phonebook.html?uid=houston
8+
links:
9+
- name: SOLR-17985
10+
url: https://issues.apache.org/jira/browse/SOLR-17985

solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -832,20 +832,24 @@ protected void createMainQuery(ResponseBuilder rb) {
832832
// perhaps we shouldn't attempt to parse the query at this level?
833833
// Alternate Idea: instead of specifying all these things at the upper level,
834834
// we could just specify that this is a shard request.
835+
int shardRows;
835836
if (rb.shards_rows > -1) {
836837
// if the client set shards.rows set this explicity
837-
sreq.params.set(CommonParams.ROWS, rb.shards_rows);
838+
shardRows = rb.shards_rows;
838839
} else {
839-
// what if rows<0 as it is allowed for grouped request??
840-
sreq.params.set(
841-
CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
840+
shardRows = rb.getSortSpec().getCount();
841+
// If rows = -1 (grouped requests) or rows = 0, then there is no need to add the offset.
842+
if (shardRows > 0) {
843+
shardRows += rb.getSortSpec().getOffset();
844+
}
842845
}
846+
sreq.params.set(CommonParams.ROWS, shardRows);
843847

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

846850
boolean shardQueryIncludeScore =
847851
(rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0
848-
|| rb.getSortSpec().includesScore();
852+
|| (shardRows != 0 && rb.getSortSpec().includesScore());
849853
StringBuilder additionalFL = new StringBuilder();
850854
boolean additionalAdded = false;
851855
if (rb.onePassDistributedQuery) {

solr/core/src/test/org/apache/solr/TestDistributedSearch.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,7 @@ public void test() throws Exception {
15501550
// Check Info is added to for each shard
15511551
ModifiableSolrParams q = new ModifiableSolrParams();
15521552
q.set("q", "*:*");
1553+
q.set("rows", "0");
15531554
q.set(ShardParams.SHARDS_INFO, true);
15541555
setDistributedParams(q);
15551556
rsp = queryRandomShard(q);
@@ -1560,6 +1561,13 @@ public void test() throws Exception {
15601561
assertNotNull("missing shard info", sinfo);
15611562
assertEquals(
15621563
"should have an entry for each shard [" + sinfo + "] " + shards, cnt, sinfo.size());
1564+
// We are setting rows=0, so scores should not be collected
1565+
for (int i = 0; i < cnt; i++) {
1566+
String shard = sinfo.getName(i);
1567+
assertNull(
1568+
"should not have any score information (maxScore) in the shard info: " + shard,
1569+
((Map<String, Object>) sinfo.get(shard)).get("maxScore"));
1570+
}
15631571

15641572
// test shards.tolerant=true
15651573

0 commit comments

Comments
 (0)