视图运行缓慢,我必须使用 select into 临时表吗?
所以我遇到了一个严重的麻烦,因为我的最后一个查询执行时间是 8 分钟才能获取 2500 个节点。它只是其他两种视图的组合。
第一个视图是:
SELECT
RecTime, SQL AS str, ID,
ROW_NUMBER() OVER(ORDER BY RecTime,ID) AS rwnb
FROM
(SELECT
A.RecTime, X.SQL, X.ID
FROM
dbo.EventView AS A
CROSS JOIN
dbo.Incident AS X
WHERE
(PATINDEX('%' + A.Col + '%', X.SQL) > 0)) AS INC
1 秒和 1600 个节点
第二个视图是:
SELECT
D.RecTime, D.Event, D.ID, CAST(CASE WHEN X.[Value] IS NULL THEN 0 ELSE X.[Value] END AS bit) AS Value
FROM
dbo.XDependencedEvents AS D
INNER JOIN
dbo.EventView AS X ON X.Col = D.Event
AND D.RecTime BETWEEN X.RecTime AND X.ChangedDate
3 秒执行时间和 2100 个节点
,最终视图是
SELECT
X.[Rectime], X.[ID], X.[str], D.[Event], D.[Value],X.[rwnb]
FROM
[XDependencedIncidents] AS X
INNER JOIN [XEventStates] AS D ON X.[Rectime] = D.[Rectime]
AND X.[ID] = D.[ID]
8 分钟和 2500 个节点。
我什至使用 RowNumber AS rwnb 来加快视图的处理速度,但它仍然很慢。我必须对前 2 个视图使用 select into 临时表吗?或者我在这里做错了什么?
最终目的是每次“事件”发生变化时获取某些“事件”“组”的值
So I've got a serious trouble because my last query execute time is 8 minutes to get 2500 nodes. And it just combination of 2 other views.
First view is :
SELECT
RecTime, SQL AS str, ID,
ROW_NUMBER() OVER(ORDER BY RecTime,ID) AS rwnb
FROM
(SELECT
A.RecTime, X.SQL, X.ID
FROM
dbo.EventView AS A
CROSS JOIN
dbo.Incident AS X
WHERE
(PATINDEX('%' + A.Col + '%', X.SQL) > 0)) AS INC
1 second and 1600 nodes
Second view is :
SELECT
D.RecTime, D.Event, D.ID, CAST(CASE WHEN X.[Value] IS NULL THEN 0 ELSE X.[Value] END AS bit) AS Value
FROM
dbo.XDependencedEvents AS D
INNER JOIN
dbo.EventView AS X ON X.Col = D.Event
AND D.RecTime BETWEEN X.RecTime AND X.ChangedDate
3 seconds execute time and 2100 nodes
and final view is
SELECT
X.[Rectime], X.[ID], X.[str], D.[Event], D.[Value],X.[rwnb]
FROM
[XDependencedIncidents] AS X
INNER JOIN [XEventStates] AS D ON X.[Rectime] = D.[Rectime]
AND X.[ID] = D.[ID]
8 minutes and 2500 nodes.
I even use RowNumber AS rwnb to speed up working with views but it still being really slow. Must I use select into temp tables for first 2 views ? Or I making wrong something here ?
The final purpose is to getting values for some "groups" of "events" for each time when "events" changing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
如果它也很慢。检查
XEventStates 索引
。try this:
If its also slow. Check the
XEventStates Indexing
.我奇怪的解决方案是使用 RowNumber 来修改第二个和最后一个视图,例如:
您
对这种奇怪的优化方法有何看法?如果有的话,我真的想要一个更好的解决方案。
顺便说一句,是的,添加行号使得 8 分钟 -> 5秒。
My weird solution is using RowNumber like modify 2nd and last Views like :
and
What do you think about this weird method of optimization ? I really want a better solution if there some.
BTW yes, adding row number makes from 8 minutes -> 5 seconds.