Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Optimized SQL Query.

Author  Topic 

hspatil31
Posting Yak Master

182 Posts

Posted - 2011-09-05 : 04:53:02
Dear All,

I am having following query, in following query each table having more that milions records. For executing this query it's taking to much time. On tables i don't want to set any index.

Can anybody please tell me how to optimize this query. Is there anyother way to optimize ?

SELECT
CTR.Code AS Country_Code
,CTR.Name AS Country_Name
,INRS.Dialed_Digits AS Dialed_Digits
,CAST(INRS.Rate as numeric(8,4)) As Rate
,C.Abbreviation AS Provider
,CAST(RDCR.Raw_Rate as numeric(8,4)) As Raw_Rate
,RDF.Overhead AS Overhead
,CAST(RDCR.Gross_Rate as numeric(8,4)) As Gross_Rate
,RDF.Margin AS Margin
,CAST(RDCR.Net_Rate as numeric(8,4)) As Net_Rate
,RDLCC.Rank AS Rank
FROM
aaa INRS (nolock)
INNER JOIN bbb RDLCC (nolock) ON INRS.ID = RDLCC.Normalized_Rate_Sheet_ID
INNER JOIN ccc RDCR (nolock) ON RDLCC.Rate_Deck_Created_Rate_ID = RDCR.ID
INNER JOIN ddd WS (nolock) ON WS.ID= INRS.Work_Sheet_ID
INNER JOIN eee RS (nolock) ON WS.Rate_Sheet_ID= RS.ID
INNER JOIN fff C (nolock) ON C.ID= RS.Carrier_ID
INNER JOIN ggg CTR (nolock) ON INRS.Country_ID = CTR.ID
INNER JOIN hhh RDF (nolock) ON RDF.Rate_Deck_Details_ID = RDCR.Rate_Deck_Details_ID AND RDF.Call_type_ID = @CallType_ID
WHERE
RDCR.Rate_Deck_Details_ID=@RateDeck_Detail_ID
AND RDCR.Call_type_ID = @CallType_ID
AND RDCR.Country_Code=@Country_Code
ORDER BY Country_Code,Dialed_Digits,Rank

Thanks and Ragard's
Harish Patil

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-05 : 05:08:38
we need some more info

did you analyse execution plan? what are costly steps? are there some table scans? are they some large tables involved?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

hspatil31
Posting Yak Master

182 Posts

Posted - 2011-09-05 : 05:16:14
Hello Friend,

Following are the tableshaing more data. These are the costly steps.
And one more thing if any other operation is going on this tables then my above query result taking more time.

aaa INRS (nolock)
INNER JOIN bbb RDLCC (nolock) ON INRS.ID = RDLCC.Normalized_Rate_Sheet_ID
INNER JOIN ccc RDCR (nolock) ON RDLCC.Rate_Deck_Created_Rate_ID = RDCR.ID

Please tell me how to solve this issue ?

Thnks,
Harish
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-05 : 05:30:26
did you see execution plan? are there any table scans?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gwilson67
Starting Member

42 Posts

Posted - 2011-09-05 : 11:34:32
Turn on the Actual Estimated Plan not the Estimated Plan. Based on the results, you can look to see if you can have any improvements like adding indexes.

Greg
http://www.freewebstore.org/tsqlcoderepository
Powerful tool for SQL Server development
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-05 : 13:04:46
"On tables i don't want to set any index."

Well pretty much all bets are off at improving it then.

Do you know the consequences of using NOLOCK as a hint? Are they accommodated in your application? Or is this report NOT used for any decision making process by managers etc?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-05 : 13:25:49
read this if you're using nolock

http://visakhm.blogspot.com/2010/02/avoiding-deadlocks-using-new.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-09-05 : 16:56:24
And if you can't be bothered to read the link.
Let me summarize it for you:

DON"T USE NOLOCK.

You can end up reading the same row twice (or not at all).
quote:

On tables i don't want to set any index.


Why not? There will be no way to get adequate performance if you don't want to index anything.

Do the join conditions even have keys and constraints?

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -