Solved

need to optimize the query- pls help

Posted on 2012-03-28
5
161 Views
Last Modified: 2012-06-11
SELECT  VH.Carrier_Description AS Carrier, MH.shipped_VIA AS [Service], MH.Country AS CountyShippedTo,
 CONVERT(VARCHAR, PA.[Length]) + ',' + CONVERT(VARCHAR, PA.[Width]) + ',' + CONVERT(VARCHAR, PA.[Height]) AS BoxDimensions, MH.[Weight],  MH.Reference as
 [SaleNumber/BidderNumber], MH.totalvalue AS Value, MH.Customer_No AS CustomerNumber, MH.Shipping_Cost AS ShippingCharges
  FROM DSDEV.He.dbo.Ml_HCC_Ship_Info MH
  INNER JOIN WORLD.wldb.dbo.vw_heCI VH on MH.Tracking_Number = VH.TrackingNumber
  INNER JOIN WORLD.wldb.dbo.Packages PA ON MH.Tracking_Number = PA.TrackingNumber
  WHERE [status] = 'ship' and MH.[TimeStamp] > Dateadd(m, -6, Getdate()) and MH.Country NOT IN('UNITED STATES', 'US', 'USA')
  ORDER BY MH.Customer_No
0
Comment
Question by:sqlcurious
5 Comments
 
LVL 9

Expert Comment

by:OCDan
Comment Utility
The query itself seems perfectly fine, nothing complicated there to cause problems.

What are the indexes on those tables?
Any chance you could post the execution plan?
0
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
Comment Utility
In my opinion you can't do much as it is accros diferent servers by the statement below from your whole query above:

...
FROM DSDEV.He.dbo.Ml_HCC_Ship_Info MH
  INNER JOIN WORLD.wldb.dbo.vw_heCI VH on MH.Tracking_Number
...

What I would do if possible - bring data set you need into a "staging" working table on eiter side of the linked servers and re-write the code to use that one instead. This way you can add indexes that SQL optimizer can actualy use.
0
 
LVL 25

Expert Comment

by:jogos
Comment Utility
There is not much to optimise in the script itself.

Status theres no table-alias given, The 'not in' for MH.count is something that is not so optimal.
Can you post the execution plan so we can see if there are indexes failing, I think there is the problem.  And tell aprox how many rows per table and the duration of query.
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
Are you running the query from "DSDEV" instance or from "WORLD" instance?

[Or, yikes, an entirely different instance.]

Which table is column "[status]" in?
0
 

Author Closing Comment

by:sqlcurious
Comment Utility
thanks
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now