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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Dev vs Prod SQL Servers perform very differently o

Author  Topic 

Autofreak
Starting Member

9 Posts

Posted - 2012-04-03 : 13:53:37
Hello, we have a query that executes very differently in different environments.

Here are the stats:

Development: 2 sec

QA: 7 sec

Production: around 1 min (off the pick hours)

The longer execution times cause timeout and make the page of little use on Production. We have checked the execution plan, and optimization through indexing, no further improvements - it seems. And yet there must be a reason for a 1 min discrepancy. Actually, it may be that we miss something while comparing execution plans' among the servers. Where could we look for resolving this. All three servers use same SQL Server version and the prod machine seems to perform consistently on other queries/SP. Below is the query. We would also appreciate if someone could take a look at the execution plans, may be a clue could be found there. Thank you.


SELECT TOP (20)
[Project10].[C1] AS [C1],
[Project10].[ReviewID] AS [ReviewID],
[Project10].[BusinessID] AS [BusinessID], [Project10].[Name] AS [Name], [Project10].[Description] AS [Description], [Project10].[Rating] AS [Rating], [Project10].[C4] AS [C2], [Project10].[Reviewer] AS [Reviewer], [Project10].[City] AS [City], [Project10].[CreateDate] AS [CreateDate], [Project10].[UpdateDate] AS [UpdateDate], [Project10].[Name1] AS [Name1], [Project10].[C2] AS [C3], [Project10].[C3] AS [C4] FROM ( SELECT [Project10].[ReviewID] AS [ReviewID], [Project10].[Description] AS [Description], [Project10].[Rating] AS [Rating], [Project10].[Reviewer] AS [Reviewer], [Project10].[City] AS [City], [Project10].[CreateDate] AS [CreateDate], [Project10].[UpdateDate] AS [UpdateDate], [Project10].[BusinessID] AS [BusinessID], [Project10].[Name] AS [Name], [Project10].[Name1] AS [Name1], [Project10].[C1] AS [C1], [Project10].[C2] AS [C2], [Project10].[C3] AS [C3], [Project10].[C4] AS [C4], row_number() OVER (ORDER BY [Project10].[BusinessID] ASC) AS [row_number]
FROM ( SELECT
[Project9].[ReviewID] AS [ReviewID],
[Project9].[Description] AS [Description],
[Project9].[Rating] AS [Rating],
[Project9].[Reviewer] AS [Reviewer],
[Project9].[City] AS [City],
[Project9].[CreateDate] AS [CreateDate],
[Project9].[UpdateDate] AS [UpdateDate],
[Extent17].[BusinessID] AS [BusinessID],
[Extent18].[Name] AS [Name],
[Extent19].[Name] AS [Name1],
1 AS [C1],
[Project9].[C1] AS [C2],
[Project9].[C2] AS [C3],
[Project9].[C3] AS [C4]
FROM (SELECT
[Project5].[ReviewID] AS [ReviewID],
[Project5].[Description] AS [Description],
[Project5].[Rating] AS [Rating],
[Project5].[Reviewer] AS [Reviewer],
[Project5].[City] AS [City],
[Project5].[CreateDate] AS [CreateDate],
[Project5].[UpdateDate] AS [UpdateDate],
[Project5].[BusinessID] AS [BusinessID],
[Project5].[IsMain] AS [IsMain],
[Project5].[TypeID] AS [TypeID],
[Project5].[C1] AS [C1],
[Project5].[C2] AS [C2],
(SELECT TOP (1)
[Extent10].[DisplayValue] AS [DisplayValue]
FROM [gb_business].[BusinessContacts] AS [Extent9]
LEFT OUTER JOIN [gb_business].[PersonalCommunication] AS [Extent10] ON EXISTS (SELECT
cast(1 as bit) AS [C1]
FROM ( SELECT cast(1 as bit) AS X ) AS [SingleRowTable2]
LEFT OUTER JOIN (SELECT
[Extent11].[PersonID] AS [PersonID]
FROM [gb_business].[Person] AS [Extent11]
WHERE [Extent9].[PersonID] = [Extent11].[PersonID] ) AS [Project6] ON 1 = 1
INNER JOIN [gb_business].[Person] AS [Extent12] ON [Project6].[PersonID] = [Extent12].[PersonID]
WHERE [Extent10].[PersonID] = [Extent12].[PersonID]
)
LEFT OUTER JOIN [gb_business].[ContactType] AS [Extent13] ON [Extent9].[ContactTypeID] = [Extent13].[ContactTypeID]
LEFT OUTER JOIN [gb_business].[CommunicationType] AS [Extent14] ON [Extent10].[CommunicationTypeID] = [Extent14].[CommunicationTypeID]
LEFT OUTER JOIN [gb_business].[Business] AS [Extent15] ON [Extent9].[BusinessID] = [Extent15].[BusinessID]
INNER JOIN [gb_business].[Business] AS [Extent16] ON [Extent15].[BusinessID] = [Extent16].[BusinessID]
WHERE ([Extent13].[ContactTypeID] = 1) AND ([Extent14].[CommunicationTypeID] = 4) AND ([Project5].[BusinessID] = [Extent16].[BusinessID])) AS [C3]
FROM ( SELECT
[Project4].[ReviewID] AS [ReviewID],
[Project4].[Description] AS [Description],
[Project4].[Rating] AS [Rating],
[Project4].[Reviewer] AS [Reviewer],
[Project4].[City] AS [City],
[Project4].[CreateDate] AS [CreateDate],
[Project4].[UpdateDate] AS [UpdateDate],
[Project4].[BusinessID] AS [BusinessID],
[Project4].[IsMain] AS [IsMain],
[Project4].[TypeID] AS [TypeID],
[Project4].[C1] AS [C1],
(SELECT
COUNT([Extent7].[ReviewHistoryID]) AS [A1]
FROM [gb_business].[ReviewHistory] AS [Extent7]
LEFT OUTER JOIN [gb_business].[ReviewStatus] AS [Extent8] ON [Extent7].[ReviewStatusID] = [Extent8].[ReviewStatusID]
WHERE ([Project4].[ReviewID] = [Extent7].[ReviewID]) AND ([Extent8].[ReviewStatusID] = 1)) AS [C2]
FROM ( SELECT
[Extent1].[ReviewID] AS [ReviewID],
[Extent1].[Description] AS [Description],
[Extent1].[Rating] AS [Rating],
[Extent1].[Reviewer] AS [Reviewer],
[Extent1].[City] AS [City],
[Extent1].[CreateDate] AS [CreateDate],
[Extent1].[UpdateDate] AS [UpdateDate],
[Extent1].[BusinessID] AS [BusinessID],
[Extent2].[IsMain] AS [IsMain],
[Extent2].[TypeID] AS [TypeID],
(SELECT TOP (1) [Project3].[StatusDate] AS [StatusDate]
FROM ( SELECT
[Extent5].[StatusDate] AS [StatusDate]
FROM [gb_business].[ReviewHistory] AS [Extent5]
LEFT OUTER JOIN [gb_business].[ReviewStatus] AS [Extent6] ON [Extent5].[ReviewStatusID] = [Extent6].[ReviewStatusID]
WHERE ([Extent1].[ReviewID] = [Extent5].[ReviewID]) AND ([Extent6].[ReviewStatusID] = 1)
) AS [Project3]
ORDER BY [Project3].[StatusDate] DESC) AS [C1]
FROM [gb_business].[Review] AS [Extent1]
LEFT OUTER JOIN [gb_listing].[RegionalService] AS [Extent2] ON EXISTS (SELECT
cast(1 as bit) AS [C1]
FROM ( SELECT cast(1 as bit) AS X ) AS [SingleRowTable1]
LEFT OUTER JOIN (SELECT
[Extent3].[BusinessID] AS [BusinessID]
FROM [gb_business].[Business] AS [Extent3]
WHERE [Extent1].[BusinessID] = [Extent3].[BusinessID] ) AS [Project1] ON 1 = 1
INNER JOIN [gb_business].[Business] AS [Extent4] ON [Project1].[BusinessID] = [Extent4].[BusinessID]
WHERE [Extent2].[BusinessID] = [Extent4].[BusinessID]
)
) AS [Project4]
) AS [Project5] ) AS [Project9]
LEFT OUTER JOIN [gb_business].[Business] AS [Extent17] ON [Project9].[BusinessID] = [Extent17].[BusinessID]
LEFT OUTER JOIN [gb_business].[Business] AS [Extent18] ON [Project9].[BusinessID] = [Extent18].[BusinessID]
LEFT OUTER JOIN [gb_listing].[RegionalServiceType] AS [Extent19] ON [Project9].[TypeID] = [Extent19].[RegionalServiceTypeID]
WHERE [Project9].[IsMain] = 1
) AS [Project10]
) AS [Project10]
WHERE [Project10].[row_number] > 0
ORDER BY [Project10].[BusinessID] ASC

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-04-03 : 14:34:45
your sub sub sub sub sub sub queries will kill you. Was this human generated query or auto generated query.
do you have the same data set in all environs. production will most always have more data and your scary query is not scaling. backup and restore in a lab environment
and test things out. looks like scaling testing was not done in dev

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page
   

- Advertisement -