Skip to content

Clustered aggregation: release retained capacity before failing or spilling when no group is complete #26911

Open

Description

@viirya

Is your feature request related to a problem or challenge?

When a clustered aggregate stream (partial, final or single, with full group clustering) fails to grow its reservation, it first emits the completed groups and then calls ClusteredAggregateTable::shrink_to_fit (#26726, #26782). If no group is complete, for example when one key spans the whole batch, the stream returns ResourcesExhausted (partial), or spills or errors (final/single) without shrinking. Shrinking alone could make the reservation fit, because the table still holds capacity it grew for the batch, such as the per-batch accumulator scratch.

For example, a partial APPROX_DISTINCT(v) GROUP BY k over three 8192-row batches of a single key fails a 64 KiB limit asking for 132.1 KB, although the table holds about 4.3 KB after shrink_to_fit.

Raised by @comphead in #26782.

Describe the solution you'd like

On a refused reservation with no completed group, call shrink_to_fit and retry the reservation before returning the error or spilling. The existing memory_pressure_without_completed_groups tests in the final and single streams would need to reflect this.

Describe alternatives you've considered

Bound the per-batch scratch itself, for example by hashing in fixed-size chunks in HllGroupsAccumulator, which also avoids regrowing the scratch for every batch under sustained pressure.

Activity

  1. self-assigned this
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions