[BUG] PPL aggregate pushdown planning is O(fields²) on wide index patterns (pushDownAggregate uses List.contains)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- java
- Ambito
- backend, performance
Direzione di ricerca
Il controllo quadratico si trova in pushDownAggregate in CalciteLogicalIndexScan.java, intorno alla riga 388, dove schema.contains viene eseguito dentro un filtro di stream su osIndex.getAllFieldTypes(). Inizia da lì e confronta con la correzione di pushDownFilter citata in #4825. Sostituisci la List con un HashSet costruito da buildSchema(), quindi conferma che il pushdown dell'aggregazione restituisce ancora gli stessi tipi di campo. È completato quando il piano del pattern ampio stats count() non scala più con il numero di campi e i test esistenti del pushdown dell'aggregazione passano.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What is the bug?
PPL planning time grows quadratically with the number of fields in the index pattern for aggregations whose scan is not narrowed by a projection. On an index pattern with ~280K mapped fields (union across ~2,300 indices), source=logs-* | stats count() spends ~3–4 minutes in planning (_explain alone takes ~228 s), versus ~9 s when the same aggregation follows a where on one field.
The hot spot is CalciteLogicalIndexScan.pushDownAggregate:
List<String> schema = buildSchema();
Map<String, ExprType> fieldTypes =
this.osIndex.getAllFieldTypes().entrySet().stream()
.filter(entry -> schema.contains(entry.getKey())) // List.contains -> O(N × M)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
schema is a List<String> built from the scan's row type. When the scan still carries every field (e.g. stats count() with no referenced columns), both sides are ~N and the filter is O(N²). With a preceding where @timestamp >= ..., the scan is trimmed to one column before the aggregate rule fires ($102 in the logical plan becomes $0 in the pushed-down filter), so the loop is O(N) and the problem is hidden.
This is the same pattern that #4825 fixed in pushDownFilter; the copy in pushDownAggregate is still present on main.
Hot-threads sample on the coordinating node during a slow _explain:
java.util.ArrayList.indexOfRange(ArrayList.java:299)
java.util.ArrayList.indexOf(ArrayList.java:286)
java.util.ArrayList.contains(ArrayList.java:275)
org.opensearch.sql.opensearch.storage.scan.CalciteLogicalIndexScan.lambda$pushDownAggregate$11(CalciteLogicalIndexScan.java:388)
...
org.opensearch.sql.opensearch.storage.scan.CalciteLogicalIndexScan.pushDownAggregate(CalciteLogicalIndexScan.java:389)
org.opensearch.sql.opensearch.planner.rules.AggregateIndexScanRule.apply(AggregateIndexScanRule.java:100)
org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:525)
How can one reproduce the bug?
- Create an index pattern whose merged mapping has a very large number of distinct fields (we used ~2,300 indices, ~280K distinct leaf fields; 35 indices × 5,000 disjoint keyword fields is enough to show it).
- Run
POST /_plugins/_ppl/_explain {"query": "source=<pattern> | stats count()"}. - Compare with
source=<pattern> | where @timestamp >= '<recent>' | stats count().
Observed (Calcite enabled):
| Query | Planning / total time |
|---|---|
source=logs-* | stats count() (~77K fields) |
35 s total |
source=logs-* | stats count() (~280K fields) |
181 s total, _explain 228 s |
source=logs-gdfieldtest-* | stats count() (35 indices, 175K fields, 7K docs) |
_explain 91–198 s |
source=logs-* | where @timestamp >= ... | stats count() (~280K fields) |
_explain 9 s, 13–14 s total |
What is the expected behavior?
Planning cost should be roughly linear in the number of fields. Using a Set<String> for the membership check (as in #4825) should be sufficient:
Set<String> schema = new HashSet<>(buildSchema());
What is your host/environment?
- OpenSearch 3.5 (managed service), Calcite engine enabled
- Also present on
main(CalciteLogicalIndexScan.javaline 388)
Do you have any additional context?
- Related: #4825 (same O(N²) pattern in
pushDownFilter), #5953 (wide-index planning for always-false filters — does not touch this code path). - Requests that hit this without a time filter commonly exceed the 300 s HTTP gateway timeout on managed domains.
- Lingua principale
- Java
- Stelle
- 176
- Fork
- 237
- Merge medio
- 2g 12h
- PR unite (30g)
- 34
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di opensearch-project/sql
-
bug untriaged
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
opensearch-project/sql#5983 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"Forse già presa @nagendramohan l’ha presa 106 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
opensearch-project/sql#5684 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[DOC] Calcite settings documentation missing examplesForse già presa @AzazelSensei l’ha presa 64 giorni fa. Apertadocumentation PPL
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
opensearch-project/sql#4806 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
calcite enhancement Meta performance PPL untriaged
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
opensearch-project/sql#5991 ·
I maintainer di solito rispondono entro 1 giorno
-
bug duplicate untriaged
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
opensearch-project/sql#5989 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di opensearch-project/sql
Issue simili
-
Document the isv:HDFGroup Linux package repositories and signing keyForse già presa @brtnfld l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
checkstyle/checkstyle#23174 ·
I maintainer di solito rispondono entro 1 giorno
-
bug follow-up lane:backlog
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
Sanne/incus-spawn#2620 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] Execute API reports every non-400 error, including 404 "not found", with reason "System Error"Apertauntriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
opensearch-project/ml-commons#5296 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno