mirror of https://github.com/apache/lucene.git
SOLR-7239: improved performance of min & max in StatsComponent, as well as situations where local params disable all stats
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1666294 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f3bc0ad731
commit
c9d344f09d
|
@ -243,6 +243,9 @@ Optimizations
|
|||
* SOLR-7116: Distributed facet refinement requests would needlessly compute other types
|
||||
of faceting that have already been computed. (David Smiley, Hossman)
|
||||
|
||||
* SOLR-7239: improved performance of min & max in StatsComponent, as well as situations
|
||||
where local params disable all stats (hossman)
|
||||
|
||||
Other Changes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -346,6 +346,12 @@ public class StatsField {
|
|||
*/
|
||||
public StatsValues computeLocalStatsValues(DocSet base) throws IOException {
|
||||
|
||||
if (statsToCalculate.isEmpty()) {
|
||||
// perf optimization for the case where we compute nothing
|
||||
// ie: stats.field={!min=$domin}myfield&domin=false
|
||||
return StatsValuesFactory.createStatsValues(this);
|
||||
}
|
||||
|
||||
if (null != schemaField
|
||||
&& (schemaField.multiValued() || schemaField.getType().multiValuedFieldCache())) {
|
||||
|
||||
|
|
|
@ -347,6 +347,9 @@ class NumericStatsValues extends AbstractStatsValues<Number> {
|
|||
double sum;
|
||||
double sumOfSquares;
|
||||
|
||||
double minD; // perf optimization, only valid if (null != this.min)
|
||||
double maxD; // perf optimization, only valid if (null != this.max)
|
||||
|
||||
final protected boolean computeSum;
|
||||
final protected boolean computeSumOfSquares;
|
||||
|
||||
|
@ -405,13 +408,19 @@ class NumericStatsValues extends AbstractStatsValues<Number> {
|
|||
if (computeMin) { // nested if to encourage JIT to optimize aware final var?
|
||||
if (null != min) {
|
||||
double minD = min.doubleValue();
|
||||
this.min = (null == this.min) ? minD : Math.min(this.min.doubleValue(), minD);
|
||||
if (null == this.min || minD < this.minD) {
|
||||
// Double for result & cached primitive doulbe to minimize unboxing in future comparisons
|
||||
this.min = this.minD = minD;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (computeMax) { // nested if to encourage JIT to optimize aware final var?
|
||||
if (null != max) {
|
||||
double maxD = max.doubleValue();
|
||||
this.max = (null == this.max) ? maxD : Math.max(this.max.doubleValue(), maxD);
|
||||
if (null == this.max || this.maxD < maxD) {
|
||||
// Double for result & cached primitive doulbe to minimize unboxing in future comparisons
|
||||
this.max = this.maxD = maxD;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -494,6 +494,26 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {
|
|||
assertNull("expected null for sum", s.getSum());
|
||||
}
|
||||
|
||||
// request stats, but disable them all via param refs
|
||||
rsp = query("q","*:*", "sort",i1+" desc", "stats", "true", "doMin", "false",
|
||||
"stats.field", "{!min=$doMin}" + i1);
|
||||
{ // don't leak variables
|
||||
FieldStatsInfo s = rsp.getFieldStatsInfo().get(i1);
|
||||
// stats section should exist, even though stats should be null
|
||||
assertNotNull("no stats for " + i1, s);
|
||||
//
|
||||
assertNull("expected null for min", s.getMin() );
|
||||
assertNull("expected null for mean", s.getMean() );
|
||||
assertNull("expected null for stddev", s.getStddev() );
|
||||
//
|
||||
assertNull("expected null for count", s.getCount());
|
||||
assertNull("expected null for calcDistinct", s.getCountDistinct());
|
||||
assertNull("expected null for distinct vals", s.getDistinctValues());
|
||||
assertNull("expected null for max", s.getMax());
|
||||
assertNull("expected null for missing", s.getMissing());
|
||||
assertNull("expected null for sum", s.getSum());
|
||||
}
|
||||
|
||||
final String[] stats = new String[] {
|
||||
"min", "max", "sum", "sumOfSquares", "stddev", "mean", "missing", "count"
|
||||
};
|
||||
|
|
|
@ -1163,6 +1163,9 @@ public class StatsComponentTest extends AbstractSolrTestCase {
|
|||
"but since only local param is false no stats should be returned",
|
||||
req("q","*:*", "stats", "true",
|
||||
"stats.field", "{!key=k min=false}a_i")
|
||||
// section of stats for this field should exist ...
|
||||
, XPRE + "lst[@name='stats_fields']/lst[@name='k']"
|
||||
// ...but be empty
|
||||
, "count(" + kpre + "*)=0"
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue