[META] PPL performance degrades as the number of mapped fields grows
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 8/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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()
- Dominant language
- Java
- Stars
- 176
- Forks
- 237
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 34
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from opensearch-project/sql
-
bug untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
opensearch-project/sql#5990 ·
Maintainers usually reply within 1 day
-
bug untriaged
Difficulty 1/5 Under an hour Newbie friendliness 85/100
opensearch-project/sql#5983 ·
Maintainers usually reply within 1 day
-
[BUG] PromQL queries fail with InvalidTypeIdException when metric has a label named "type"Possibly taken @nagendramohan claimed this 107 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
opensearch-project/sql#5684 · 4 comments ·
Maintainers usually reply within 1 day
-
[DOC] Calcite settings documentation missing examplesPossibly taken @AzazelSensei claimed this 64 days ago. Opendocumentation PPL
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
opensearch-project/sql#4806 · 1 comment ·
Maintainers usually reply within 1 day
-
bug duplicate untriaged
Difficulty 4/5 3-5 days Newbie friendliness 22/100
opensearch-project/sql#5989 · 1 comment ·
Maintainers usually reply within 1 day
All issues in opensearch-project/sql
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
PCL-Community/PCL-CE#3907 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 2 days
-
area/dependencies area/dependencies/quarkus backport/26.6 backport/26.8 kind/cve severity/critical source/scan-dependencies status/triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
docker-to-squash.py: check_dependencies should find mksquashfs on PATHPossibly taken @linzch3 claimed this today. Open
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
chore
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
lugassawan/swe-workbench#841 ·