Solved

need to optimize the query- pls help

Posted on 2012-03-28
5
167 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
[X]
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
5 Comments
 
LVL 9

Expert Comment

by:OCDan
ID: 37778797
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 40

Accepted Solution

by:
lcohan earned 500 total points
ID: 37778803
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
ID: 37778824
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:Scott Pletcher
ID: 37783482
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
ID: 38071939
thanks
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! 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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

615 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