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
TimeSeries 'latest' scans the whole series to return one row, though queryDescending(limit 1) exists #7322
Reading the newest sample of a time-series type materializes the entire series and throws all of it
away but the last row. TimeSeriesGateway.latest (extracted from GetTimeSeriesLatestHandler in #7305, same code as before) is:
TimeSeriesEngine.query merges every shard's full range into one ArrayList and sorts it, so a type
holding N samples costs O(N) heap and O(N log N) time to answer a question about one row.
The engine already has the bounded form, added for exactly this shape in #5414/#5416:
whose javadoc says "an unbounded last-point query costs O(shards x blocks touched) instead of
O(series)". FetchFromTimeSeriesStep uses it; the latest path does not.
Consequence
GET /api/v1/ts/{database}/latest and, since #7305, the gRPC TimeSeriesLatest RPC both load the
whole series to return one row. On a type with millions of samples that is a large allocation per
call, on an endpoint whose whole purpose is to be cheap enough to poll - a Grafana single-stat panel
or a health check hits it on every refresh.
Swapping in queryDescending(..., 1, null) changes behaviour where several samples share the maximum
timestamp: the ascending merge takes the last of the ties in shard order, the descending scan takes
whichever trimToDescendingLimit keeps. Nothing specifies which row wins a tie today, so the change
is safe in substance but not a refactor, and #7305 needed the two protocols to answer identically
against a known baseline.
Suggested fix
Move TimeSeriesGateway.latest onto queryDescending(from, to, null, tagFilter, 1, null), decide and
document the tie-break, and add a test that pins it. Both protocols pick the change up at once, since
both already call that one method.
latest was asking the engine for the whole series (query(MIN, MAX)) and then taking the last row, which merged every shard's full range into one list and sorted it - O(series) heap for a one-row question. It now calls queryDescending(from, to, null, tagFilter, 1, null), the bounded form added for exactly this shape in #5414/#5416, so the engine stops after the first row. Both callers pick this up at once: GET /ts/{database}/latest and the gRPC TimeSeriesLatest RPC go through the same method.
One behaviour change worth knowing: when several rows share the newest timestamp, the two scans sort stably in opposite directions, so the old ascending scan returned the last of the tied rows and the bounded one returns the first. The timestamp is the guarantee; narrow with tags if you need to disambiguate. This is now stated in the javadoc and pinned by Issue7322LatestBoundedTest.
Still open
PromQL label/series discovery materialises the whole series to collect distinct tag values #7371 - GetPromQLLabelValuesHandler and GetPromQLSeriesHandler still materialise whole series to collect distinct tag values, then discard the rows. Found by this issue's completeness sweep; a different question (all rows vs. one row) on different endpoints, so it is filed rather than folded in.
A no-match tag filter still walks every block: with nothing matching, no shard ever collects a row so the running lower bound never tightens. That is queryDescending's own caveat from TIMESERIES: unbounded descending scan still reads the whole unsealed tail (follow-up to #5414) #5416, shared with the SQL path - not a regression (the old path walked everything and allocated per row), but fixing it needs a per-shard tag index.
❤️ 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
address review: assert against an independent oracle, not the express…
fix(#7322): TimeSeries 'latest' asks for one row instead of the whole…
robfrank commentedon Sep 10, 2026
Fixed in #7376.
latestwas asking the engine for the whole series (query(MIN, MAX)) and then taking the last row, which merged every shard's full range into one list and sorted it - O(series) heap for a one-row question. It now callsqueryDescending(from, to, null, tagFilter, 1, null), the bounded form added for exactly this shape in #5414/#5416, so the engine stops after the first row. Both callers pick this up at once:GET /ts/{database}/latestand the gRPCTimeSeriesLatestRPC go through the same method.One behaviour change worth knowing: when several rows share the newest timestamp, the two scans sort stably in opposite directions, so the old ascending scan returned the last of the tied rows and the bounded one returns the first. The timestamp is the guarantee; narrow with tags if you need to disambiguate. This is now stated in the javadoc and pinned by
Issue7322LatestBoundedTest.Still open
GetPromQLLabelValuesHandlerandGetPromQLSeriesHandlerstill materialise whole series to collect distinct tag values, then discard the rows. Found by this issue's completeness sweep; a different question (all rows vs. one row) on different endpoints, so it is filed rather than folded in.queryDescending's own caveat from TIMESERIES: unbounded descending scan still reads the whole unsealed tail (follow-up to #5414) #5416, shared with the SQL path - not a regression (the old path walked everything and allocated per row), but fixing it needs a per-shard tag index.❤️ 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.