[BUG] PPL aggregate pushdown planning is O(fields²) on wide index patterns (pushDownAggregate uses List.contains)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- java
- Lĩnh vực
- backend, performance
Hướng nghiên cứu
Kiểm tra bậc hai nằm trong pushDownAggregate ở CalciteLogicalIndexScan.java, khoảng dòng 388, nơi schema.contains chạy bên trong một bộ lọc stream trên osIndex.getAllFieldTypes(). Hãy bắt đầu từ đó và so sánh với bản sửa pushDownFilter được nhắc tới trong #4825. Thay List bằng một HashSet được xây dựng từ buildSchema(), sau đó xác nhận pushdown aggregate vẫn trả về cùng các kiểu trường. Hoàn thành khi kế hoạch cho mẫu rộng stats count() không còn tăng theo số trường và các test pushdown aggregate hiện có đều pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 176
- Fork
- 237
- Merge trung bình
- 2 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 34
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của opensearch-project/sql
-
bug untriaged
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
opensearch-project/sql#5983 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"Có thể đã có người làm @nagendramohan đã nhận 106 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
opensearch-project/sql#5684 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[DOC] Calcite settings documentation missing examplesCó thể đã có người làm @AzazelSensei đã nhận 64 ngày trước. Đang mởdocumentation PPL
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
opensearch-project/sql#4806 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
calcite enhancement Meta performance PPL untriaged
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 8/100
opensearch-project/sql#5991 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug duplicate untriaged
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
opensearch-project/sql#5989 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của opensearch-project/sql
Issue tương tự
-
Document the isv:HDFGroup Linux package repositories and signing keyCó thể đã có người làm @brtnfld đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
checkstyle/checkstyle#23174 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug follow-up lane:backlog
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Sanne/incus-spawn#2620 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Execute API reports every non-400 error, including 404 "not found", with reason "System Error"Đang mởuntriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
opensearch-project/ml-commons#5296 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày