Query running slower on 2005 than 2000

Posted on 2008-10-21
Medium Priority
Last Modified: 2012-05-05
I have SQL 2000 and SQL 2005 running on the same (Dev) server. The attached query will run in 5 secs on 2000 and 3:54 on SQL 2005 - Same DB restored from backup.

Worse still it takes 15minutes on Production.

What have I missed?

SELECT o.OrderDate, o.OrderRef, c.ClientCode, oi.Quantity, sno.Snos
FROM tblOrders o
	INNER JOIN tblOrderItems oi ON o.OrderID = oi.OrderID
		SELECT CatID, ClientCode FROM tblCatalogue WHERE TrackSerialNumbers = 1
		) c ON oi.CatID = c.CatID 
		SELECT a.OrderID, s.CatID, COUNT(s.SerialNumber) AS Snos
			FROM tblSerialNumbers s 
			INNER JOIN tblAirwayBills a ON s.AirwayBillID = a.AirwayBillID
			GROUP BY OrderID, CatID
	) sno ON o.OrderID = sno.OrderID AND sno.CatID = oi.CatID
WHERE o.OrderID > 184876
AND (oi.Quantity <> sno.Snos)
Order By o.OrderID Desc

Open in new window

Question by:mdalemail
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 450 total points
ID: 22771860
after restore, you need to
? update statistics
? check the execution plan of the query

-> is the hardware specs the same on both machines? I guess the "old" machine was single-cpu, and the new one multi-cpu?
try to append this to your query.
LVL 39

Assisted Solution

BrandonGalderisi earned 900 total points
ID: 22771867

Author Comment

ID: 22771973
Thanks for the posts - I'll have a look.
One bizarre twist - if I change the WHERE clause to search for o.OrderID > 172666 instead of 184876, which of course brings back a greater results set, the query takes 1 second!
What may be relevant is that this takes the Query back to include records created prior to the uupgrade to 2005.

Any thoughts?
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

LVL 39

Assisted Solution

BrandonGalderisi earned 900 total points
ID: 22771982
Indexes.  When you copied your DB over did you create an indexing maintenance plan?

Author Comment

ID: 22772002
Hmmm. No.
I guess I should re-rate myself to beginner.
So... Indexing maintenance plans. Any good links?

Author Comment

ID: 22772061
Should I be Reorganising or Reindexing?

Author Comment

ID: 22772237
Disgusted Eh?
Thanks anyway - Ran a reorganise followed by rebuild - down to 8 seconds.

Better, but still not as good as when running from older files.
LVL 39

Expert Comment

ID: 22772850
Not abandoned, just traveling home from work.

SSMS (management studio) should have a pretty good wizard mode for creating an indexing maintenance plan.
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 150 total points
ID: 22782509
Don't make the assumption that what ran fine in SQL Server 2000 will work as well in 2005.  Sometimes queries will not even run.  Every query needs to be inspected.  In my experience, the queries that did not execute as well or failed to compile were using lousy code and should be re-written in any case.  Your miles may vary.
LVL 39

Assisted Solution

BrandonGalderisi earned 900 total points
ID: 22782767
but 4 minutes to 8 seconds after a a defrag is a smoking gun to at least EQUALIZE performance based upon environment, not optimization.  

That sounds confusing.  So I guess what I'm saying is that getting it from 4 minutes to 8 seconds, when it took 5 before, is probably as good as it's going to get WITHOUT rewriting the process.  So many things change from version to version that make certain things faster.  I swear that M$ must put in speedbumps to functionality when they don't want you using it any more.

And by speedbump I mean something that serves no purpose other than slowing something down.

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question