question

getforpramod avatar image
getforpramod asked

Need SQL Query tuning solution

Hi all, Can anyone provide me simple solution for query written below:- I have written the following query to find All data fromt able dbo.RecommendationTypesTranslation where DefaultLanguage is fectched from RecommendationTypes & RecommendationProvider if there is no DefaultLanguage then fetch data for Default language "en" for RecommendationTypesID. SELECT DL.RecommendationTypesID, RTT.ShortName, RTT.LongName, DL.DefaultLanguage FROM dbo.RecommendationTypesTranslation RTT INNER JOIN ( SELECT R1.RecommendationTypesID, IsNull(DefaultLanguage, 'en') AS DefaultLanguage FROM RecommendationTypes R1 LEFT OUTER JOIN ( SELECT RT.RecommendationTypesID, DefaultLanguage AS DefaultLanguage FROM RecommendationTypes RT INNER JOIN RecommendationProvider RP on RT.Source = RP.ProviderSource INNER JOIN RecommendationTypesTranslation RTT ON RTT.RecommendationTypesID = RT.RecommendationTypesID AND RTT.LanguageCode = RP.DefaultLanguage) T ON R1.RecommendationTypesID = T.RecommendationTypesID) DL ON DL.RecommendationTypesID = RTT.RecommendationTypesID AND DL.DefaultLanguage = RTT.LanguageCode
sql-server-2008
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image Fatherjack ♦♦ commented ·
can you post the query plan please? What indexes are there? Do all tables have PK-FK in place? Why do you think it is slow? How much faster do you want it to be - 10%, 100%, 1000%?
0 Likes 0 ·
ThomasRushton avatar image ThomasRushton ♦♦ commented ·
how big are the tables? How up-to-date are the index stats?
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
Without the exec plan... I can't see anything here.
0 Likes 0 ·

1 Answer

·
Oleg avatar image
Oleg answered
I might be completely wrong here, but it almost appears that the query in question was generated by some sort of tool. The downside of using those is that extra clicking and dragging tends to produce overly complicated queries. Without knowing the details about the data, it is not really possible to figure out how to best restate the query, but please try either this: select RTT.RecommendationTypesID, RTT.ShortName, RTT.LongName, isnull(RP.DefaultLanguage, 'en') DefaultLanguage from RecommendationTypesTranslation RTT left join RecommendationTypes RT on RTT.RecommendationTypesID = RT.RecommendationTypesID left join RecommendationProvider RP on RT.[Source] = RP.ProviderSource and RTT.LanguageCode = RP.DefaultLanguage; -- or even this because it is difficult to figure out the need to -- include the RecommendationProvider RP in the mix if the RTT -- already has the LanguageCode column which could be used select RTT.RecommendationTypesID, RTT.ShortName, RTT.LongName, RTT.LanguageCode DefaultLanguage from RecommendationTypesTranslation RTT left join RecommendationTypes RT on RTT.RecommendationTypesID = RT.RecommendationTypesID Oleg
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.