You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PromQL label/series discovery materialises the whole series to collect distinct tag values #7371
Two PromQL discovery endpoints answer a question about tag columns by materialising every sample of every matching type and then throwing the rows away:
finalList<Object[]> rows = engine.query(startMs, endMs, null, null);
for (finalObject[] 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.
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.
Not a regression, but unchanged: the mutable half of a shard's scan still materialises its matching range into a list before the visitor sees it, and GetPromQLLabelValuesHandler still walks every type in the database once per call.
❤️ 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.
Activity
fix(#7371): scan a column projection in the PromQL discovery endpoints (
robfrank commentedon Sep 16, 2026
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.queryfor a lazyforEachRowscan. #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 DOUBLEvaluecolumn 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
TimeSeriesTypeBuilderenforces, and one both files already flagged. They now read the slot fromTimeSeriesGateway.selectedColumns(), the engine's own statement of the row layout, so the assumption is gone rather than documented.Still open
label/{name}/valuesstill scans every sample rather than reading the distinct sets thatBlockEntry.tagDistinctValuesandTimeSeriesTagDictionaryalready hold. Deliberately not taken here: both structures over-approximate (a truncated block keeps its old distinct set, the tag dictionary is append-only with no prune path, and block metadata spells a null tag""), which is sound for the block-skipping they do today but would make a label endpoint name series that no longer exist. PromQL label-values still scans every sample although the distinct tag values are already recorded per sealed block #7660 carries the evidence and the decision that has to come first.GetPromQLLabelValuesHandlerstill walks every type in the database once per call.❤️ 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.