Skip to content

A refused time-series aggregation still pays for every bucket it will never return #7724

Closed

Description

@robfrank

Found by claude-review on PR #7720 (issue #7663).

Summary

#7663 gave the Grafana aggregation branch the hard row ceiling it never consulted, but the ceiling is
enforced on the RESULT, not on the work:

final MultiColumnAggregationResult aggResult = engine.aggregateMulti(fromTs, toTs, requests, bucketInterval, tagFilter);
final List<Long> timestamps = aggResult.getBucketTimestamps();

if (!budget.charge(timestamps.size()))
  throw resultSetTooLarge(budget.ceiling());

aggregateMulti visits the whole range to fill the buckets it returns, so a request with a small
bucketInterval over a wide range pays the full scan and the full bucket allocation, and is THEN refused.
The refusal bounds the response; it does not bound the cost of producing it.

PostTimeSeriesQueryHandler.executeAggregation has the identical shape, and so does the gRPC
aggregated path's ceiling (#7390) - all three charge after the fact.

Why it was out of scope for #7663

#7663 is the row-cap push-down: a read carrying a row bound must bound its FETCH by it. A bucket count is
a different bound with a different mechanism - the row count of the answer is not the row count of the
input, and aggregateMulti has no limit parameter to push anything into. Adding one is a change to the
aggregation engine and its shard merge (MultiColumnAggregationResult.mergeFrom), not to the handlers,
and it needs its own test for what a partially-filled bucket set means.

The raw branches of all three surfaces ARE now bounded in the fetch; this is the aggregated half.

Consequence

The ceiling stops an oversized RESPONSE, which is what #5719 asked of it. It does not stop an operator
(or a dashboard auto-refreshing every 5s with a one-millisecond bucketInterval) from making the server
do the whole scan repeatedly and throw the result away. The cheapest shape of the request is the one the
ceiling already recognises as abusive.

Suggested fix

The bucket count is knowable BEFORE the scan whenever the range and the interval are both bounded:
(toTs - fromTs) / bucketInterval + 1. Refusing on that arithmetic, before calling aggregateMulti,
costs nothing and turns the refusal from O(range) into O(1). An unbounded range (Long.MIN_VALUE to
Long.MAX_VALUE) cannot be pre-computed that way and would keep the after-the-fact check.

Apply it to all three: PostGrafanaQueryHandler.executeAggregation,
PostTimeSeriesQueryHandler.executeAggregation, and the gRPC bucket-streaming ceiling.

Verification

  • A request whose bucket count exceeds the ceiling over a WIDE range is refused without the scan -
    assert with AggregationMetrics that no block was touched.
  • The existing ceiling tests stay green, in particular
    Issue7663GrafanaPrometheusRowCeilingIT.theGrafanaAggregationBranchIsBoundedByTheSameCeiling and
    Issue7390GrpcTimeSeriesRowCeilingIT.theAggregatedPathUsesTheSameCeiling: the refusal and its wording
    are unchanged, only its cost.

Activity

  1. added
    server
    timeseries
    on Sep 16, 2026
  2. added
    grpc
    on Sep 16, 2026
  3. added
    in progress
    on Sep 16, 2026
  4. self-assigned this
    on Sep 16, 2026
  5. added this to the 26.10.1 milestone on Sep 16, 2026
  6. added 5 commits that reference this issue on Sep 16, 2026
  7. lvca commented on Sep 16, 2026

    @lvca
    Member

    Fixed in #7728, released in 26.10.1.

    A time-series aggregation that asks for more buckets than a single response may carry is refused. Until now the server produced the whole answer first and then threw it away, so the cheapest way to make it do a lot of work was to send a request it was always going to reject - a small bucketInterval over a wide range, which a dashboard on a short refresh interval can repeat every few seconds.

    The limit is now applied while the data is being read: the scan stops as soon as the answer is known to be too large. The refusal itself is unchanged - same status, same message naming the setting that decided - only its cost.

    This applies to /api/v1/ts/{database}/query, the Grafana query route, and the gRPC bucket stream. Requests that fit within the limit are unaffected.


    ❤️ 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.

  8. 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

buggrpcperformanceservertimeseries

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions