If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Slow query missing indexes?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-24-08, 05:52
paul_anthony paul_anthony is offline
Registered User
 
Join Date: Sep 2005
Posts: 10
Slow query missing indexes?

Hi Guys,

I've a query that runs on two different machines with two different result. One machine it takes 12 seconds - the other it is almost instant. I think perhaps I have missing indexes on one server - anyone any advice on speeding the query up?

Alternatively any tools for mirroring database setups would be useful. Would the output of the execution plan make any sense to anyone?

I've attempting to script the indexes / primary / foreign keys between the two - to no avail.

Really tearing the hair out now as to where the bottle neck is.


PHP Code:
SELECT distinct top 8 dbo.tblProductDetail.EuroStopPLU As ssEuro,
newid(), dbo.tblProductDetail.PLU,  
dbo.tblProductDetail.ColourID,
dbo.tblProductDetail.id as ProductID 
FROM dbo
.tblOrderLines 
INNER JOIN dbo
.tblProductDetail ON dbo.tblOrderLines.ProductID dbo.tblProductDetail.ID INNER JOIN dbo.tblProductMaster ON tblProductMaster.ID=tblProductDetail.ProductMasterID INNER JOIN tblWebBrand ON tblProductMaster.WebBrandID=tblWebBrand.ID WHERE (dbo.tblOrderLines.OrderID IN (SELECT DISTINCT orderID FROM tblOrderLines WHERE productID 2548)) AND (dbo.tblOrderLines.ProductID <> 2548) AND (dbo.tblProductDetail.Active 1) AND (dbo.tblProductDetail.StockExceedsBuffer 1) AND tblWebBrand.Active=and tblWebBrand.Overrideactive AND tblProductDetail.sex=1 group by dbo.tblProductDetail.EuroStopPLU,tblProductDetail.sexdbo.tblProductDetail.id,dbo.tblProductDetail.PLUdbo.tblProductDetail.pricedbo.tblProductDetail.ColourIDdbo.tblProductDetail.Description order by newid() 
Reply With Quote
  #2 (permalink)  
Old 11-24-08, 06:59
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
just thought i'd point out that with NEWID() in the SELECT clause, every row returned will be distinct, so you don't need the DISTINCT keyword
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-24-08, 07:04
Thrasymachus Thrasymachus is offline
SQL Server Street Fighter
 
Join Date: Nov 2004
Location: Down The Rabbit Hole
Posts: 7,979
I do not know. Do you have any missing indices? Are they same on both tables? Do you have a lazy good fer nuthin' DBA hanging around? Does DBCC SHOWCONTIG show a high level of fragmentation on those indexes? Do both machines run similar hardware? Do both machines contain similar amounts of data? Yes, post the text version of the execution plan.
__________________
software development is where smart people go to waste their lives
Reply With Quote
  #4 (permalink)  
Old 11-24-08, 07:57
paul_anthony paul_anthony is offline
Registered User
 
Join Date: Sep 2005
Posts: 10
I have ran a stored proc to check indexes, both seem to be fine..(i.e. Identical on both systems) - hardware the same. Indexes have been rebuilt - and are unfragmented, its a relatively new DB. The fast machine has more data than the slow one. And the lazy good fer nuthin' DBA hanging around would be me. A junior dev - thanks for the support.


The text based execution for the slow query is here.

http://docs.google.com/Doc?id=dgvz75z2_0d4gcs5dk

Last edited by paul_anthony; 11-24-08 at 08:05.
Reply With Quote
  #5 (permalink)  
Old 11-24-08, 11:05
PMASchmed PMASchmed is offline
Registered User
 
Join Date: Jun 2004
Location: Long Island
Posts: 696
Stupid question, same version of SQL Server ?
Reply With Quote
  #6 (permalink)  
Old 11-25-08, 05:15
paul_anthony paul_anthony is offline
Registered User
 
Join Date: Sep 2005
Posts: 10
Fraid so. Yep.

Just used Red Gates SQL compare to test, and things are defo identical. The execution plans look very different between databases though. V Weird.
Reply With Quote
  #7 (permalink)  
Old 11-25-08, 06:00
aflorin27 aflorin27 is offline
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 317
Because one machine has more data than the other, it is normal that the execution plans will look different. And also, more data could mean a different distribution on columns.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On