Skip to content

PromQL label/series discovery materialises the whole series to collect distinct tag values #7371

Closed

Description

@robfrank

Summary

Two PromQL discovery endpoints answer a question about tag columns by materialising every
sample of every matching type and then throwing the rows away:

server/src/main/java/com/arcadedb/server/http/handler/GetPromQLLabelValuesHandler.java:93

final List<Object[]> rows = engine.query(Long.MIN_VALUE, Long.MAX_VALUE, null, null);
for (final Object[] row : rows) {
  if (colIdx < row.length && row[colIdx] != null)
    values.add(row[colIdx].toString());
}

server/src/main/java/com/arcadedb/server/http/handler/GetPromQLSeriesHandler.java:103

final List<Object[]> rows = engine.query(startMs, endMs, null, null);
for (final Object[] row : rows) { /* builds a label map, dedupes on a key */ }

TimeSeriesEngine.query merges every shard's range into one ArrayList and sorts it, so both
allocate O(N) Object[] for an answer whose size is the tag cardinality - typically a handful of
strings. The label-values handler does it over [Long.MIN_VALUE, Long.MAX_VALUE], i.e. the whole
series, and it does it once per matching type.

Consequence

GET /api/v1/prom/{database}/label/{name}/values and GET /api/v1/prom/{database}/series are
discovery calls: Grafana hits them on every dashboard load and on every label-picker interaction.
On a database with millions of samples each call is a large, short-lived allocation, and the sort
is O(N log N) on top.

Suggested fix

TimeSeriesEngine.iterateQuery(...) already exists and is what the aggregation path, the PromQL
evaluator, the exporter and the gRPC streaming query use: it merges shard iterators through a
min-heap at O(shards x max(blockSize, pageSize)) heap instead of O(totalRows). Both loops are
single-pass and order-independent, so swapping query for iterateQuery is a local change with
no behavioural difference. Projecting only the tag column (columnIndices) would cut it further.

Context

Found by the completeness sweep on #7322, which moved TimeSeriesGateway.latest off the same
unbounded engine.query onto queryDescending(..., 1, ...). Those two handlers are the remaining
engine.query call sites in main sources that discard the rows they materialise; the others
(/ts/query, /ts/grafana, Prometheus remote-read) return them, so the materialisation there is
the answer rather than waste.

Activity

  1. added
    server
    timeseries
    on Sep 10, 2026
  2. added this to the 26.10.1 milestone on Sep 10, 2026
  3. self-assigned this
    on Sep 11, 2026
  4. added
    in progress
    on Sep 16, 2026
  5. added a commit that references this issue on Sep 16, 2026
  6. robfrank commented on Sep 16, 2026

    @robfrank
    CollaboratorAuthor

    Fixed in #7666, merged to main.

    Half of what this issue asked for had already landed under the closed duplicate #7354, which swapped the eager engine.query for a lazy forEachRow scan. #7666 delivers the remaining half, the column projection: both PromQL discovery endpoints now scan only the TAG columns they answer questions about instead of the whole row. In the sealed layer that is the larger saving, because each column lives in its own byte range and the projection means the DOUBLE value column every Prometheus metric carries is no longer read off disk or Gorilla-decoded just to enumerate label sets. In the mutable layer only the projected columns get decoded and boxed.

    A latent bug went with it: both handlers used to locate a tag value by its schema index, which was correct only because the TIMESTAMP column happens to be declared first - an assumption nothing in TimeSeriesTypeBuilder enforces, and one both files already flagged. They now read the slot from TimeSeriesGateway.selectedColumns(), the engine's own statement of the row layout, so the assumption is gone rather than documented.

    Still open


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugperformanceservertimeseries

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions