将数据库从本地服务器迁移到Azure后,查询出现性能问题,您可以在下面找到。
Azure的实际执行计划是: https://ufile.io/o0z6ve6q
Onprem的实际执行计划是: https://ufile.io/9kj3nc7d
Azure附带了Stream Aggregate,它需要对数据进行排序,因此在Stream Aggregate之前使用Sort。
有什么方法可以轻松解决此问题而无需重建查询本身?
以前的实例是SQL Server 2008,而azure是2016。
选择
[CommunicationId]
, CASE WHEN [SurveyPageName] like '%dystrybucja%' OR [SurveyPageName] LIKE '%pytania dodatkowe%' THEN [SurveyPageName] ELSE
ISNULL(LTRIM(RIGHT([SurveyPageName], LEN([SurveyPageName]) - CHARINDEX('-', [SurveyPageName]))),'')
END
+CASE WHEN [SurveyLineName] = 'Material range - Flexible Questions' THEN ''
WHEN [SurveyLineName] = 'Materials in catalogue - Products' THEN ''
WHEN [SurveyLineName] LIKE 'Zakres produktów%' THEN ''
ELSE '.'+ISNULL([SurveyLineName],'')
END
+CASE WHEN SurveyQuestion='ANS Y/N' THEN ''
ELSE '.'+ISNULL(SurveyQuestion,'.')
END
+CASE WHEN fac.SurveyProductId IS NULL THEN ''
WHEN SurveyProductName IS NULL THEN ''
WHEN SurveyProductName = SurveyLineName THEN ''
ELSE '.'+SurveyProductName
END AS [Question]
,MAX(CASE WHEN SurveyQuestion='Lost Since Last Visit' AND ISNULL([AnswerValue],[AnswerText]) < 0 THEN 0
ELSE ISNULL([AnswerValue],[AnswerText])
END) AS Answer
FROM FactSurvey fac with (nolock)
LEFT JOIN DimSurvey dim with (nolock) ON dim.[DimSurveyKey] = fac.[DimSurveyKey]
WHERE dim.IsText = 0
AND [SurveyPageName] NOT LIKE 'Wagi produktów%'
AND dim.SurveyQuestion NOT like '%RA'
AND [SurveyPageName] NOT LIKE 'Territory_KPI_Calculation'
AND [SurveyQuestion] NOT LIKE N'Szerokosc produktów%'
AND [SurveyQuestion] NOT LIKE N'Szer.%miej.%ekspo%'
AND [SurveyQuestion] NOT LIKE N'Weight'
AND [SurveyQuestion] NOT LIKE N'Only%for%'
AND [SurveyPageName] NOT LIKE N'KPI%'
AND ([SurveyPageName] NOT LIKE N'Report_Perfect Store%'
OR ([SurveyPageName]+[SurveyQuestion] LIKE N'Report_Perfect Store%' + N'%[%]%'
OR [SurveyPageName]+[SurveyQuestion] LIKE N'Report_Perfect Store%' + N'%decimal%'))
GROUP BY [CommunicationId]
,CASE WHEN [SurveyPageName] like '%dystrybucja%' OR [SurveyPageName] LIKE '%pytania dodatkowe%' THEN [SurveyPageName] ELSE
ISNULL(LTRIM(RIGHT([SurveyPageName], LEN([SurveyPageName]) - CHARINDEX('-', [SurveyPageName]))),'')
END
+CASE WHEN [SurveyLineName] = 'Material range - Flexible Questions' THEN ''
WHEN [SurveyLineName] = 'Materials in catalogue - Products' THEN ''
WHEN [SurveyLineName] LIKE 'Zakres produktów%' THEN ''
ELSE '.'+ISNULL([SurveyLineName],'')
END
+CASE WHEN SurveyQuestion='ANS Y/N' THEN ''
ELSE '.'+ISNULL(SurveyQuestion,'.')
END
+CASE WHEN fac.SurveyProductId IS NULL THEN ''
WHEN SurveyProductName IS NULL THEN ''
WHEN SurveyProductName = SurveyLineName THEN ''
ELSE '.'+SurveyProductName
END