Skip to content

Commit

Permalink
Don't load global ordinals with the map execution_hint (#38158)
Browse files Browse the repository at this point in the history
The terms aggregator loads the global ordinals to retrieve the cardinality of the field to aggregate on. This information is then used to select the strategy to use for the aggregation (breadth_first or depth_first). However this should be avoided if the execution_hint is explicitly set to map since this mode doesn't really need the global ordinals. Since we still need the cardinality of the field this change picks the maximum cardinality in the segments as an estimation of the total cardinality to select the strategy to use (breadth_first or depth_first). This estimation is only used if the execution hint is set to map, otherwise the global ordinals are still used to retrieve the accurate cardinality.

Closes #37705
  • Loading branch information
jimczi authored Feb 1, 2019
1 parent 1094d3b commit 3d0e782
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -748,3 +748,70 @@ setup:
- is_false: aggregations.str_terms.buckets.1.key_as_string

- match: { aggregations.str_terms.buckets.1.doc_count: 2 }

---
"Global ordinals are not loaded with the map execution hint":

- skip:
version: " - 6.6.99"
reason: bug fixed in 6.7

- do:
index:
refresh: true
index: test_1
type: test
id: 1
routing: 1
body: { "str": "abc" }

- do:
index:
refresh: true
index: test_1
type: test
id: 2
routing: 1
body: { "str": "abc" }

- do:
index:
refresh: true
index: test_1
type: test
id: 3
routing: 1
body: { "str": "bcd" }

- do:
indices.refresh: {}

- do:
search:
index: test_1
body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str", "execution_hint" : "map" } } } }

- length: { aggregations.str_terms.buckets: 2 }

- do:
indices.stats:
index: test_1
metric: fielddata
fielddata_fields: str

- match: { indices.test_1.total.fielddata.memory_size_in_bytes: 0}

- do:
search:
index: test_1
body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str", "execution_hint" : "global_ordinals" } } } }

- length: { aggregations.str_terms.buckets: 2 }

- do:
indices.stats:
index: test_1
metric: fielddata
fielddata_fields: str

- gt: { indices.test_1.total.fielddata.memory_size_in_bytes: 0}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected Aggregator doCreateInternal(ValuesSource valuesSource, Aggregator pare
if (valuesSource instanceof ValuesSource.Bytes.WithOrdinals == false) {
execution = ExecutionMode.MAP;
}
final long maxOrd = getMaxOrd(valuesSource, context.searcher());
final long maxOrd = execution == ExecutionMode.GLOBAL_ORDINALS ? getMaxOrd(valuesSource, context.searcher()) : -1;
if (execution == null) {
execution = ExecutionMode.GLOBAL_ORDINALS;
}
Expand Down

0 comments on commit 3d0e782

Please sign in to comment.