Query duration estimation in SQL Server

南笙酒味 提交于 2019-11-30 21:20:15

I'd forget about it and just put a spinning circle!

Seriously though, to take MrTelly's idea further, there are dynamic management views that can give you average execution times for certain queries - maybe that can get you somewhere.

http://msdn.microsoft.com/en-us/library/ms188754.aspx

edit: I have seen percent complete in the sp_whoisactive procedure from Adam Machanic. Maybe that is another place to look into. SQL 2016 has the query store which persists plan cache information - a substitute for the dmv plan cache, which is cleared on reboot.

Related:

Today’s database systems provide little feedback to the user/DBA on how much of a SQL query’s execution has been completed. For long running queries, such feedback can be very useful, for example, to help decide whether the query should be terminated or allowed to run to completion. Although the above requirement is easy to express, developing a robust indicator of progress for query execution is challenging. In this paper, we study the above problem and present techniques that can form the basis for effective progress estimation. The results of experimentally validating our techniques in Microsoft SQL Server are promising.

I'm not aware of a tool that will do this automatically, but there are a couple of alternatives. Break your query into blocks ...

select blah from table where IdRange between (1 and 100000)

select blah from table where IdRange between (100001 and 200000)

as each sql completes so update the progress bar.

Or you could record the length of time taken for each of your selects, store those values maybe on a per user basis. Then use that information to return a progress bar length.

Both these approaches are pretty kludgy, hopefully someone knows a better approach.

Of course you could try to decipher the query plan and make a judgement based on that, but in code that would be hard.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!