Skip to content

Commit b1eb32b

Browse files
authored
[8.13] ESQL: Fix count pushdown for unmapped fields (#106690) (#106710)
Backport #106690 but avoid introducing the same optimization regression by also including the fix from #106720.
1 parent a0ec31e commit b1eb32b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats.csv-spec

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,3 +1217,12 @@ FROM airports
12171217
c:l
12181218
891
12191219
;
1220+
1221+
countMV#[skip:-8.13.0,reason:fixed in 8.13.1]
1222+
FROM employees
1223+
| STATS vals = COUNT(salary_change.int)
1224+
;
1225+
1226+
vals:l
1227+
183
1228+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/stats/SearchStats.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,13 @@ public boolean isSingleValue(String field) {
195195
if (exists(field) == false) {
196196
stat.singleValue = true;
197197
} else {
198-
var sv = new boolean[] { true };
198+
// fields are MV per default
199+
var sv = new boolean[] { false };
199200
for (SearchContext context : contexts) {
200201
var sec = context.getSearchExecutionContext();
201-
MappedFieldType mappedType = sec.isFieldMapped(field) ? null : sec.getFieldType(field);
202+
MappedFieldType mappedType = sec.isFieldMapped(field) ? sec.getFieldType(field) : null;
202203
if (mappedType != null) {
204+
sv[0] = true;
203205
doWithContexts(r -> {
204206
sv[0] &= detectSingleValue(r, mappedType, field);
205207
return sv[0];

0 commit comments

Comments
 (0)