9

I have a simple SELECT statement.

USE [AdventureWorks2014]
GO

SELECT *
FROM Sales.SalesOrderDetail sod

The execution plan has two Compute Scalar.

Execution Plan showing Compute Scalars 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])

1 Answer 1

18

The Compute Scalars are related to the computed field LineTotal. Script out the table, and you'll see that field defined as:

[LineTotal]  AS (isnull(([UnitPrice]*((1.0)-[UnitPriceDiscount]))*[OrderQty],(0.0))),

SQL Server has two operations to perform. It has to first run the calculation of:

[UnitPrice]*((1.0)-[UnitPriceDiscount]))*[OrderQty]

Then it has to check to see if that value is null, and if so, substitute 0.0.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.