Dela via


Stream Aggregate Showplan Operator

The Stream Aggregate operator groups rows by one or more columns and then calculates one or more aggregate expressions returned by the query. The output of this operator can be referenced by later operators in the query, returned to the client, or both. The Stream Aggregate operator requires input ordered by the columns within its groups. The optimizer will use a Sort operator prior to this operator if the data is not already sorted due to a prior Sort operator or due to an ordered index seek or scan. In the SHOWPLAN_ALL statement or the graphical execution plan in SQL Server Management Studio, the columns in the GROUP BY predicate are listed in the Argument column, and the aggregate expressions are listed in the Defined Values column.

Stream Aggregate is a physical operator.

Stream aggregate operator iconGraphical execution plan icon

Examples

The following example selects data from the SalesPerson table and aggregates the values for the Bonus and SalesYTD columns by territory. The output of the execution plan shows that the query optimizer uses the Stream Aggregate operator to group the rows in the SalesPerson table by the TerritoryID column and then calculate the values for the AVG(Bonus) and SUM(SalesYTD) columns based on that grouping.

USE AdventureWorks2008R2;
GO
SET NOCOUNT ON;
GO
SET SHOWPLAN_ALL ON;
GO
SELECT TerritoryID, 
    AVG(Bonus) AS 'Average bonus', 
    SUM(SalesYTD) AS'YTD sales'
FROM Sales.SalesPerson
GROUP BY TerritoryID;
GO
SET SHOWPLAN_ALL OFF;

The execution plan output of the Stream Aggregate operator appears below.

StmtText

------------------------------------------------------------------------------------------------

|--Stream Aggregate(GROUP BY:([AdventureWorks2008R2].[Sales].[SalesPerson].[TerritoryID]) )

DEFINE:([Expr1011]=Count(*),

[Expr1012]= SUM([AdventureWorks2008R2].[Sales].[SalesPerson].[Bonus]),

[Expr1004]=SUM([AdventureWorks2008R2].[Sales].[SalesPerson].[SalesYTD])))

Argument

-----------------------------------------------------------------------------------------------

GROUP BY:([AdventureWorks2008R2].[Sales].[SalesPerson].[TerritoryID]

DefinedValues

----------------------------------------------------------------------------------------------

[Expr1011]=Count(*),

[Expr1012]=SUM([AdventureWorks2008R2].[Sales].[SalesPerson].[Bonus]),

[Expr1004]=SUM([AdventureWorks2008R2].[Sales].[SalesPerson].[SalesYTD])