Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Excution Plan

Status
Not open for further replies.

theresatan

Programmer
Mar 18, 2002
101
US
Hi,

I am reading an article about performence using Northwind as sample DB and the scripts at the bottom. It said:

Although the same data is returned by both queries, Query Analyzer indicated that the second version took around 40% less SQL Server resources to run than the first

I want to know where the '40%' come from

Code Example 1:
SELECT Ord.OrderID, Ord.OrderDate,
( SELECT MAX(OrdDet.UnitPrice)
FROM Northwind.dbo.[Order Details] AS OrdDet
WHERE Ord.OrderID = OrdDet.OrderID) AS MaxUnitPrice
FROM Northwind.dbo_Orders AS Ord

Code Example 2:
SELECT Ord.OrderID, Ord.OrderDate,
MAX(OrdDet.UnitPrice) as maxUnitPrice
FROM Northwind.dbo.[Order Details] AS OrdDet
inner join
Northwind.dbo_Orders AS Ord
on Ord.OrderID = OrdDet.OrderID
group by Ord.OrderID, Ord.OrderDate

Thanks!

Theresa
 
Good question. I looked at these in Query Analyzer. The execution plans differ by one operation, Compute Scalar is present in Example 1. The cost of this is miniscule, 0.000083 out of 0.117. Not 40%.

So maybe, the comment in the article was based on a Northwind database with different data, data affects QA cost estimates; or on a different version of SQL Server; or maybe it was simply a mistake.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top