[META] PPL performance degrades as the number of mapped fields grows
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 8/100
调研方向
This is a tracking meta-issue, not a single task: it lists cases where PPL planning and execution cost grows with mapped field count, with links to #5969, #5990 and #5962 among others. Start with the Appendix generator and reproduce one open entry, such as stats count() on otel-logs-<n>, to measure the growth. Done means a specific sub-issue is fixed and its timing stays roughly linear as n grows; pick one linked sub-issue rather than this meta-issue.
由索引模型根据 Issue 内容生成。
描述
Overview
Log indices and index patterns often map many more fields than any one document uses. With OpenTelemetry data, the dynamic keys under attributes alone can add tens of thousands. A query usually touches only a few of them, but several code paths still do work for every mapped field, and some of that work scans every field again. Their cost then grows with the square of the field count or worse, so a query that takes milliseconds on a narrow index takes seconds to minutes on a wide one.
Goal: planning and running a PPL query costs at most linear time in the number of mapped fields.
This issue tracks every known case, fixed or open, with a sample query on OpenTelemetry-shaped data. Measurements are in the appendix.
Common causes
| Cause | Seen in |
|---|---|
One RelBuilder.field(String) call per field; each call scans all fields |
#5913, #5956, #5958, #5959, #5969 |
List.contains per field |
#4825, #5990 |
Metadata computed per field (RelMdCollation) |
#5952 |
| A column-name scan per cell while building the response | #5939 |
| Generated scripts that carry every field | #4597 |
| A response that holds every populated nested key of every row | #5962 |
Sample data
otel-logs holds 100 OpenTelemetry log documents with @timestamp, observedTimestamp, severityText, severityNumber, body, traceId, spanId, resource.attributes.service.name, resource.attributes.host.name, attributes.http.* and attributes.duration_ms, plus n generated keyword keys attributes.attr_00000, attributes.attr_00001, ... Each document uses about 20 fields. otel-logs-* is five such indices with disjoint keys, n in total. In otel-logs-nested, attributes is a nested field and every document populates all of its keys. The generator in the appendix names them otel-logs-<n>, otel-logs-pat<n>-* and otel-nested-<n>.
Sub-tasks
Fixed
- #4597, fixed by #4615:
source=otel-logs | bin @timestamp span=1m | stats count() by @timestamp - #4825:
source=otel-logs | where severityText = 'ERROR' - #5913:
source=otel-logs | sort - @timestamp | head 10 - #5939, fixed by #5940:
source=otel-logs | fields attributes.attr_00* | head 100 - #5952, fixed by #5953:
source=otel-logs | where severityText = 'ERROR' | where severityText = 'WARN' | head 10 - #5956:
source=otel-logs | fields severityText, * | head 10 - #5958, fixed by #5960:
source=otel-logs | convert num(attributes.http.status_code) | head 10 - #5959, fixed by #5961:
source=otel-logs | replace "ERROR" WITH "error" IN severityText | head 10
Open
- #5962:
source=otel-logs-nested | head 100 - #5969:
source=otel-logs | eval attributes = 'redacted' | head 10; alsoflatten,transpose,appendcolandaddtotals - #5990:
source=otel-logs-* | stats count(); alsodedup severityText
Upstream (Apache Calcite)
- CALCITE-7953, apache/calcite#5434:
RelBuilder.fields(Iterable<String>)looks names up in one pass. Merged; it should ship in the next Calcite release, likely 1.43.0. #5969 tracks adopting it.
Related
- #5766 prunes indices by a request-level time range before the schema is resolved, so an index pattern merges fewer mappings.
Appendix: measurements
Local single node built from main (c7e2cea), 4 GB heap, JVM assertions off, Calcite and pushdown enabled. Each time is the whole request, best of two or three runs after a warm-up. "Planning only" uses _plugins/_ppl/_explain.
Fixed
| Entry | Query, after source=otel-logs | |
n = 5,000 | 10,000 | 20,000 |
|---|---|---|---|---|
| Baseline | fields `@timestamp`, severityText | head 10 |
23 ms | 25 ms | 42 ms |
| #4597 | bin @timestamp span=1m | stats count() by @timestamp |
23 ms | 36 ms | 56 ms |
| #4825 | where severityText = 'ERROR' |
19 ms | 22 ms | 37 ms |
| #5913 | sort - @timestamp | head 10 |
14 ms | 20 ms | 33 ms |
| #5952 | where severityText = 'ERROR' | where severityText = 'WARN' | head 10 |
12 ms | 17 ms | 28 ms |
| #5956 | fields severityText, * | head 10, planning only |
24 ms | 52 ms | 130 ms |
| #5958 | convert num(attributes.http.status_code) | head 10 |
18 ms | 22 ms | 36 ms |
| #5959 | replace "ERROR" WITH "error" IN severityText | head 10 |
17 ms | 24 ms | 41 ms |
The planning-only baseline is 10, 15 and 27 ms. Running the #5956 query itself fails at fetch once it projects more than about 2,000 to 3,000 subfields (TooComplexToDeterminizeException); an issue for that will follow.
#5939 depends on the number of columns returned, m, rather than n. With n = 20,000 and 100 rows: m = 250, 500 and 1,000 take 81, 122 and 217 ms.
Open: the time grows about 4 times as n doubles. For comparison, stats count() by severityText takes 20 to 37 ms.
| Entry | Query, after source=otel-logs | |
n = 5,000 | 10,000 | 20,000 |
|---|---|---|---|---|
| #5969 | eval attributes = 'redacted' | head 10 |
114 ms | 407 ms | 1,599 ms |
| #5969 | flatten attributes | head 10, planning only |
126 ms | 444 ms | 1,659 ms |
| #5969 | addtotals |
242 ms | 872 ms | 3,439 ms |
| #5990 | stats count() |
37 ms | 117 ms | 536 ms |
| #5990 | stats count() on otel-logs-* |
41 ms | 135 ms | 512 ms |
| #5990 | dedup severityText |
40 ms | 125 ms | 563 ms |
#5962 grows with rows times populated nested keys: head 100 returns 2.8, 5.6 and 11.2 MB for 1,000, 2,000 and 4,000 keys.
Generator
"""Create OTel-shaped log indices with n dynamic attribute keys.
otel-logs-<n> one index, n keyword keys under `attributes`
otel-logs-pat<n>-<k> 5 indices with disjoint keys; the pattern otel-logs-pat<n>-* merges n keys
otel-nested-<n> `attributes` is nested and every document populates all n keys
Usage: python3 -I otel_fixture.py 5000 10000 20000
"""
import json
import random
import sys
import urllib.request
BASE = "http://localhost:9200"
def req(method, path, body=None, ndjson=False):
data = None
headers = {"Content-Type": "application/x-ndjson" if ndjson else "application/json"}
if body is not None:
data = body.encode() if isinstance(body, str) else json.dumps(body).encode()
r = urllib.request.Request(BASE + path, data=data, method=method, headers=headers)
try:
with urllib.request.urlopen(r, timeout=600) as resp:
return json.loads(resp.read() or b"{}")
except urllib.error.HTTPError as e:
return {"error": e.read().decode()[:300], "status": e.code}
def otel_props(keys, nested=False):
attrs = {
"http": {"properties": {"method": {"type": "keyword"},
"status_code": {"type": "long"},
"url": {"type": "keyword"}}},
"duration_ms": {"type": "long"},
}
for k in keys:
attrs[k] = {"type": "keyword"}
attributes = {"properties": attrs}
if nested:
attributes = {"type": "nested", "properties": {k: {"type": "keyword"} for k in keys}}
return {
"@timestamp": {"type": "date"},
"observedTimestamp": {"type": "date"},
"severityText": {"type": "keyword"},
"severityNumber": {"type": "integer"},
"body": {"type": "text"},
"traceId": {"type": "keyword"},
"spanId": {"type": "keyword"},
"resource": {"properties": {"attributes": {"properties": {
"service": {"properties": {"name": {"type": "keyword"}}},
"host": {"properties": {"name": {"type": "keyword"}}}}}}},
"attributes": attributes,
}
def create(name, keys, docs, nested=False):
req("DELETE", "/" + name)
body = {
"settings": {"index.mapping.total_fields.limit": len(keys) + 500,
"index.mapping.nested_fields.limit": 100,
"number_of_shards": 1, "number_of_replicas": 0},
"mappings": {"properties": otel_props(keys, nested)},
}
r = req("PUT", "/" + name, body)
if "error" in r:
raise SystemExit(f"create {name}: {r}")
lines = []
for d in docs:
lines.append(json.dumps({"index": {"_index": name}}))
lines.append(json.dumps(d))
r = req("POST", "/_bulk?refresh=true", "\n".join(lines) + "\n", ndjson=True)
if r.get("errors"):
raise SystemExit(f"bulk {name}: {json.dumps(r)[:400]}")
print(f"{name}: {len(keys)} keys, {len(docs)} docs")
def log_doc(rnd, i, keys, dense=False):
sev = rnd.choice([("INFO", 9), ("WARN", 13), ("ERROR", 17)])
attrs = {"http": {"method": rnd.choice(["GET", "POST"]),
"status_code": rnd.choice([200, 404, 500]),
"url": f"/api/v1/items/{i}"},
"duration_ms": rnd.randint(1, 900)}
picked = keys if dense else rnd.sample(keys, min(10, len(keys)))
for k in picked:
attrs[k] = f"v{rnd.randint(0, 99)}"
doc = {
"@timestamp": f"2026-11-25T10:{i % 60:02d}:{(i * 7) % 60:02d}Z",
"observedTimestamp": f"2026-11-25T10:{i % 60:02d}:{(i * 7) % 60:02d}Z",
"severityText": sev[0],
"severityNumber": sev[1],
"body": f"request {i} handled",
"traceId": f"{rnd.getrandbits(128):032x}",
"spanId": f"{rnd.getrandbits(64):016x}",
"resource": {"attributes": {"service": {"name": rnd.choice(["cart", "checkout", "frontend"])},
"host": {"name": f"host-{i % 4}"}}},
}
if dense:
doc["attributes"] = [{k: attrs[k] for k in keys}]
else:
doc["attributes"] = attrs
return doc
def main():
rnd = random.Random(5990)
for n in map(int, sys.argv[1:]):
keys = [f"attr_{i:05d}" for i in range(n)]
create(f"otel-logs-{n}", keys, [log_doc(rnd, i, keys) for i in range(100)])
part = n // 5
for k in range(5):
ks = keys[k * part:(k + 1) * part]
create(f"otel-logs-pat{n}-{k}", ks, [log_doc(rnd, i, ks) for i in range(20)])
for n in (1000, 2000, 4000):
keys = [f"k_{i:05d}" for i in range(n)]
create(f"otel-nested-{n}", keys, [log_doc(rnd, i, keys, dense=True) for i in range(100)],
nested=True)
if __name__ == "__main__":
main()
- 主要语言
- Java
- 星标
- 176
- 派生
- 237
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 34
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
opensearch-project/sql 的其他 Issue
-
bug untriaged
难度 2/5 1-3 小时 新手友好度 78/100
opensearch-project/sql#5990 ·
维护者通常 1 天内回复
-
bug untriaged
难度 1/5 1 小时以内 新手友好度 85/100
opensearch-project/sql#5983 ·
维护者通常 1 天内回复
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"可能已有人在做 @nagendramohan 于 106 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 74/100
opensearch-project/sql#5684 · 4 条评论 ·
维护者通常 1 天内回复
-
[DOC] Calcite settings documentation missing examples可能已有人在做 @AzazelSensei 于 64 天前认领。 未关闭documentation PPL
难度 2/5 1-3 小时 新手友好度 72/100
opensearch-project/sql#4806 · 1 条评论 ·
维护者通常 1 天内回复
-
bug duplicate untriaged
难度 4/5 3-5 天 新手友好度 22/100
opensearch-project/sql#5989 · 1 条评论 ·
维护者通常 1 天内回复
查看 opensearch-project/sql 的全部 Issue
相似的 Issue
-
Document the isv:HDFGroup Linux package repositories and signing key可能已有人在做 @brtnfld 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
checkstyle/checkstyle#23174 ·
维护者通常 1 天内回复
-
bug follow-up lane:backlog
难度 2/5 1-3 小时 新手友好度 62/100
Sanne/incus-spawn#2620 · 1 条评论 ·
维护者通常 1 天内回复
-
[BUG] Execute API reports every non-400 error, including 404 "not found", with reason "System Error"未关闭untriaged
难度 2/5 1-3 小时 新手友好度 72/100
opensearch-project/ml-commons#5296 · 1 条评论 ·
维护者通常 1 天内回复