SQL Server 中的查询持续时间估计

发布于 2024-07-14 10:10:57 字数 195 浏览 10 评论 0原文

我在 Oracle 10g 中看到了一个功能,可以估计长时间运行的查询的剩余时间,我想知道这在 SQL Server 中是否也可能(至少在 2008 年?)?

假设我有一个非常大的表,其中有数千万行(索引良好等),并且我需要搜索一些特定的行。 我知道这会花费很多时间,而且我对此很满意,但我想向用户展示某种进度条。

我如何展示进步?

I've seen in Oracle 10g a feature that estimates the remaining time for a long running query and I was wondering if this is possible too in SQL Server (at least in 2008?)?

Suppose I have a very large table with tens of millions of rows (well indexed etc. etc.) and I need to search for some particular rows. I know it will take a lot of time and I'm cool with that but I would like to present the user with some kind of a progress bar.

How can I show progress?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉城凉梦凉人心 2024-07-21 10:10:57

我会忘记它,只是放一个旋转的圆圈!

不过说真的,为了进一步发展 MrTelly 的想法,动态管理视图可以为您提供某些查询的平均执行时间 - 也许这可以让您有所收获。

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

编辑:
我已经看到 Adam Machanic 的 sp_whoisactive 过程完成了百分比。 也许这是另一个值得研究的地方。 SQL 2016 具有保留计划缓存信息的查询存储 - dmv 计划缓存的替代品,该缓存在重新启动时会被清除。

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.

一紙繁鸢 2024-07-21 10:10:57

相关:

当今的数据库系统很少向用户/DBA 提供以下反馈:
SQL 查询的执行已完成多少。 长久以来
运行查询时,此类反馈可能非常有用,例如
帮助决定是否应终止查询或允许运行查询
至完成。 虽然上面的要求很容易表达,
开发一个强大的查询执行进度指示器是
具有挑战性的。 在本文中,我们研究了上述问题并提出
可以构成有效进度估计基础的技术。
在 Microsoft 中对我们的技术进行实验验证的结果
SQL Server 前景广阔。

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.

只等公子 2024-07-21 10:10:57

我不知道有什么工具可以自动执行此操作,但有几种选择。 将查询分成块...

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

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

每个 sql 完成时更新进度条。

或者您可以记录每个选择所花费的时间长度,可能基于每个用户存储这些值。 然后使用该信息返回进度条长度。

这两种方法都非常笨拙,希望有人知道更好的方法。

当然,您可以尝试破译查询计划并据此做出判断,但在代码中这会很困难。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文