I have a simple SELECT
statement.
USE [AdventureWorks2014]
GO
SELECT *
FROM Sales.SalesOrderDetail sod
The execution plan has two Compute Scalar
.
Why is this? I was expecting to just get the Index Scan
or maybe a Table Scan
?
The first (rght-most) has
[[AdventureWorks2014].[Sales].[SalesOrderDetail].LineTotal] = Scalar Operator(isnull(CONVERT_IMPLICIT(numeric(19,4),[AdventureWorks2014].[Sales].[SalesOrderDetail].[UnitPrice] as [sod].[UnitPrice],0)*((1.0)-CONVERT_IMPLICIT(numeric(19,4),[AdventureWorks2014].[Sales].[SalesOrderDetail].[UnitPriceDiscount] as [sod].[UnitPriceDiscount],0))*CONVERT_IMPLICIT(numeric(5,0),[AdventureWorks2014].[Sales].[SalesOrderDetail].[OrderQty] as [sod].[OrderQty],0),(0.000000)))
When second has:
[[sod].LineTotal] = Scalar Operator([AdventureWorks2014].[Sales].[SalesOrderDetail].[LineTotal] as [sod].[LineTotal])
Best Answer
The Compute Scalars are related to the computed field LineTotal. Script out the table, and you'll see that field defined as:
SQL Server has two operations to perform. It has to first run the calculation of:
Then it has to check to see if that value is null, and if so, substitute 0.0.