我的数据集速度非常慢。很遗憾,我们目前无法进一步优化查询。然而,无论什么超时,我改变报告仍然在10分钟后超时。我已经尝试过报告数据集超时,报告执行超时以及sql server上的远程执行。似乎没有工作。
有点挖掘产生了以下资源,我也试着无济于事:
https://msdn.microsoft.com/en-us/library/ms155782.aspx
为什么我的报告会在10分钟后超时?
剧本:
DECLARE @SessionDateFrom DATETIME = '2016/11/01'
DECLARE @SessionDateTo DATETIME = '2016/12/01'
DECLARE @SiteNo INT = 1
SELECT DISTINCT [CS].[No] AS SiteNo
,[CS].[Name] AS SiteName
,TSE.[MediaNo] AS Media
,TSE.[MediaIndex]
,Sum(TSE.[Qty]) AS SalesQty
,Sum(TSE.[Value]) AS SalesValue
,TSE.[MediaGroup]
,TSE.[MediaName]
,TSE.SortOrder
,TSE.[ReasonNo]
,[R].[Name] AS ReasonName
,Convert(BIT, CASE
WHEN TSE.[MediaNo] NOT IN (
1001
,1002
,1003
,1004
,3002
,3004
,7002
,7004
,7006
)
THEN 1
ELSE 0
END) AS Clickable
FROM TSE
LEFT JOIN CS ON CS.No = TSE.SiteNo
LEFT JOIN R ON (R.No = TSE.ReasonNo)
WHERE EXISTS (
SELECT Descendant
FROM DescendantSites
WHERE Parent = @SiteNo
AND Descendant = TSE.SiteNo
)
AND (
Qty <> 0
OR Value <> 0
)
AND MediaNo <> 0
AND ExcludeFromReport <> 1
--AND (
-- MediaNo IN (@MediaNo)
-- OR MediaNo IS NULL
-- )
AND TermNo = 0
AND SessionDate BETWEEN @SessionDateFrom
AND @SessionDateTo
GROUP BY [CS].[No]
,[CS].[Name]
,TSE.[MediaNo]
,TSE.[MediaIndex]
,TSE.[MediaGroup]
,TSE.[MediaName]
,TSE.SortOrder
,TSE.[ReasonNo]
,[Reason].[Name]
ORDER BY TSE.[MediaGroup]
,TSE.[SortOrder]
,TSE.[MediaIndex]
OPTION (OPTIMIZE FOR UNKNOWN)
需要过滤媒体,但是如果它能在合理的时间内全部返回,那么应该没问题(如果逻辑错误,请纠正我。我是sql的新手。)
答案 0 :(得分:1)
我能够将查询重写为以下内容。它的速度大幅提升(从约40秒到约2)
SELECT [CfgSites].[No] AS SiteNo
,[CfgSites].[Name] AS SiteName
,[Media] AS Media
,[MediaIndex]
,Sum([Qty]) AS SalesQty
,Sum([Value]) AS SalesValue
,[MediaGroup]
,[MediaName]
,TSE.SortOrder
,TSE.[ReasonNo]
,[Reason].[Name] AS ReasonName
,Convert(BIT, CASE
WHEN TSE.[Media] NOT IN (
1001
,1002
,1003
,1004
,3002
,3004
,7002
,7004
,7006
)
THEN 1
ELSE 0
END) AS Clickable
FROM (
SELECT SessionDate
,TransactionSales.SiteNo
,Media
,MediaIndex
,Qty
,Value
,MediaGroup
,FullName as MediaName
,SortOrder
,ReasonNo
FROM TransactionSales
LEFT JOIN MediaExtended ON TransactionSales.Media = MediaExtended.MediaNo
AND TransactionSales.MediaIndex = MediaExtended.[Index]
INNER JOIN [Sessions] ON TransactionSales.[SiteNo] = [Sessions].[SiteNo] AND TransactionSales.[TermNo] = [Sessions].[TermNo] AND TransactionSales.SessionNo = [Sessions].[SessionNo] AND
[Sessions].[Type] = 0
WHERE TransactionSales.SiteNo IN (@SiteNo)
AND (
Qty <> 0
OR Value <> 0
)
AND Media <> 0
AND ExcludeFromReport <> 1
AND (
MediaNo IN (@MediaNo)
OR MediaNo IS NULL
)
AND TransactionSales.TermNo = 0
AND SessionDate BETWEEN @SessionDateFrom
AND @SessionDateTo
) TSE
LEFT JOIN CfgSites ON CfgSites.No = TSE.SiteNo
LEFT JOIN [Reason] ON ([Reason].[ReasonNo] = TSE.[ReasonNo])
GROUP BY [CfgSites].[No]
,[CfgSites].[Name]
,[Media]
,[MediaIndex]
,[MediaGroup]
,[MediaName]
,TSE.SortOrder
,TSE.[ReasonNo]
,[Reason].[Name]
UNION ALL
SELECT CfgSites.No
,CfgSites.Name
,MediaExtended.MediaNo
,0
,sum(transactionsales.qty) AS Qty
,SUM(transactionsales.value) AS Value
,MediaGroup
,ISNULL([MediaExtended].[FullName], 'Unknown Media') AS MediaName
,MediaExtended.SortOrder
,null
,null
,null
FROM MediaExtended
INNER JOIN transactionsales ON transactionsales.media = MediaExtended.TotalForMedia
INNER JOIN [Sessions] ON [TransactionSales].[SiteNo] = [Sessions].[SiteNo]
AND [TransactionSales].[TermNo] = [Sessions].[TermNo]
AND [TransactionSales].[SessionNo] = [Sessions].[SessionNo]
AND [Sessions].[Type] = 0
LEFT JOIN CfgSites ON TransactionSales.SiteNo = CfgSites.No
WHERE [MediaExtended].[TotalForMedia] > 0 AND TransactionSales.SiteNo IN (@SiteNo)
AND (
Qty <> 0
OR Value <> 0
)
AND Media <> 0
AND ExcludeFromReport <> 1
AND (
MediaNo IN (@MediaNo)
OR MediaNo IS NULL
)
AND TransactionSales.TermNo = 0
AND SessionDate BETWEEN @SessionDateFrom
AND @SessionDateTo
Group By CfgSites.No
,CfgSites.Name
,MediaNo
,MediaGroup
,FullName
,MediaExtended.SortOrder
ORDER BY [MediaGroup]
,TSE.[SortOrder]
,[MediaIndex]
OPTION (OPTIMIZE FOR UNKNOWN)
答案 1 :(得分:0)
这不是直接的答案,而是一种解决方法。您可以在处理选项中启用缓存。然后安排订阅以刷新缓存。计划报告运行的超时要宽松得多。然后当你去查看报告时,你甚至不得不等待10分钟,它只会从缓存中加载。
答案 2 :(得分:0)
WorkAround,尝试减少报告中不必要的列
答案 3 :(得分:0)
“...我们有一个报表查看器应用程序,它连接到服务器并从那里运行报告”
所以你有一些事情。
1. SSRS API Connection Timeout (http)
2. SSRS Database connection timeout (Dataset)
3. SSRS Report Processing Timeout (Report)
4. Your Report Viewer application timeout (http)
你已经声明除了#4之外你已经增加了超时值。你的申请可以超时吗?