# Stream Aggregate: Efficiency with Ordered Data
> [!Note]
> `**Stream Aggregate** delivers high performance by leveraging **sequential processing** on **pre-sorted data**, minimizing memory overhead but requiring an explicit **order** or an added **Sort** operator when the input is unordered.`
The Stream Aggregate operator processes rows in strict order, detecting transitions in the grouping key and emitting each group’s result immediately upon completion. By reading the input sequentially, it avoids the need to materialize all rows or construct elaborate in-memory structures. This **order requirement** means that the underlying data must be sorted—ideally via an index—so that group boundaries align with the incoming stream.
In terms of **resource efficiency**, Stream Aggregate sidesteps the overhead of hashing by not loading every row into memory at once nor building complex hash tables. However, when the data is not already sorted, SQL Server automatically introduces a **Sort** operator to impose the necessary ordering, which can incur its own CPU and memory costs. Understanding this trade-off is crucial for designing execution plans that balance speed and resource consumption.
---
## References
- Korotkevitch, D. (2022). _SQL Server advanced troubleshooting and performance tuning: Best practices and techniques_. O’Reilly Media.
- Nevarez, B. (2022). _SQL Server query tuning and optimization: Optimize Microsoft SQL Server 2022 queries and applications_. Packt Publishing.