如何在不输出数据的情况下测试 Sql Server Mgmt Studio 的性能?
使用 SQL Server Management Studio。
如何测试大型选择(例如 600k 行)的性能而不让结果窗口影响我的测试? 在所有条件相同的情况下,这并不重要,因为两个查询都将输出到同一个地方。 但我想加快我的测试周期,并且我认为 SQL Server Management Studio 的输出设置妨碍了我。 我目前正在使用输出到文本,但我希望有更好的选择。
我认为这会影响我的数字,因为数据库位于我的本地机器上。
编辑:有一个关于在这里执行 WHERE 1=0 的问题(认为会发生连接但没有输出),但我测试了它并且它不起作用 - 不是查询性能的有效指标。
Using SQL Server Management Studio.
How can I test the performance of a large select (say 600k rows) without the results window impacting my test? All things being equal it doesn't really matter, since the two queries will both be outputting to the same place. But I'd like to speed up my testing cycles and I'm thinking that the output settings of SQL Server Management Studio are getting in my way. Output to text is what I'm using currently, but I'm hoping for a better alternative.
I think this is impacting my numbers because the database is on my local box.
Edit: Had a question about doing WHERE 1=0 here (thinking that the join would happen but no output), but I tested it and it didn't work -- not a valid indicator of query performance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以在查询之前执行
SET ROWCOUNT 1
。 我不确定这是否正是您想要的,但它将避免等待大量数据返回,从而为您提供准确的计算成本。但是,如果您将客户端统计信息添加到查询中,其中一个数字是服务器回复的等待时间,这将为您提供服务器计算时间,不包括通过网络传输数据所需的时间。
You could do
SET ROWCOUNT 1
before your query. I'm not sure it's exactly what you want but it will avoid having to wait for lots of data to be returned and therefore give you accurate calculation costs.However, if you add Client Statistics to your query, one of the numbers is Wait time on server replies which will give you the server calculation time not including the time it takes to transfer the data over the network.
您可以设置统计时间打开来测量时间服务器。 您可以使用 Query/包含客户端统计信息 (Shift+Alt +S) 在 SSMS 上获取有关客户端时间使用情况的详细信息。 请注意,SQL 查询不会运行,然后在完成后将结果返回给客户端,而是在返回结果时运行,甚至在通信通道已满时暂停执行。
查询完全忽略将结果数据包发送回客户端的唯一上下文是激活。 但是,在衡量性能时,还应该考虑将输出返回给客户端的时间。 您确定您自己的客户端会比 SSMS 更快吗?
You can SET STATISTICS TIME ON to get a measurement of the time on server. And you can use the Query/Include Client Statistics (Shift+Alt+S) on SSMS to get detail information about the client time usage. Note that SQL queries don't run and then return the result to the client when finished, but instead they run as they return results and even suspend execution if the communication channel is full.
The only context under which a query completely ignores sending the result packets back to the client is activation. But then the time to return the output to the client should be also considered when you measure your performance. Are you sure your own client will be any faster than SSMS?
SET ROWCOUNT 1
将在返回第一行后停止处理,这意味着除非计划碰巧有阻塞运算符,否则结果将毫无用处。举一个简单的例子
在实践中,该查询的成本在很大程度上取决于
TableX
中的行数。使用
SET ROWCOUNT 1
不会显示任何内容。 无论TableX
有 1 行还是 10 亿行,它都会在返回第一行后停止执行。我经常将 SELECT 结果分配给变量,以便能够查看逻辑读取之类的内容,而不会因 SSMS 显示结果而减慢速度。
有一个相关的连接项请求 在 SSMS 和/或 TSQL 中提供“在服务器上丢弃结果”选项
SET ROWCOUNT 1
will stop processing after the first row is returned which means unless the plan happens to have a blocking operator the results will be useless.Taking a trivial example
The cost of this query in practice will heavily depend on the number of rows in
TableX
.Using
SET ROWCOUNT 1
won't show any of that. Irrespective of whetherTableX
has 1 row or 1 billion rows it will stop executing after the first row is returned.I often assign the
SELECT
results to variables to be able to look at things like logical reads without being slowed down by SSMS displaying the results.There is a related Connect Item request Provide "Discard results at server" option in SSMS and/or TSQL
有很多更正确的答案,但我认为真正的问题是我偶然发现这个问题时问自己的问题:
我对相同的测试数据有一个查询 A 和一个查询 B。 哪个更快? 我想检查得又快又脏。 对我来说,答案是 - 临时表(此处创建临时表的开销很容易被忽略)。 这只能在 perf/testing/dev 服务器上完成!
查询 A:
查询 B
There is a lot of more correct answers of answers but I assume real question here is the one I just asked myself when I stumbled upon this question:
I have a query A and a query B on the same test data. Which is faster? And I want to check quick and dirty. For me the answer is - temp tables (overhead of creating temp table here is easy to ignore). This is to be done on perf/testing/dev server only!
Query A:
Query B
您可以做的最好的事情是检查实际查询的查询执行计划(按 Ctrl+L)。 这将为您提供可用性能的最佳估计。
The best thing you can do is to check the Query Execution Plan (press Ctrl+L) for the actual query. That will give you the best guesstimate for performance available.
我认为
WHERE 1=0
的 where 子句肯定发生在 SQL Server 端,而不是 Management Studio。 不会返回任何结果。您的数据库引擎是否与运行 Mgmt Studio 的计算机位于同一台计算机上?
您可以:
这只会移动在 Mgmt Studio 中绘制网格所花费的周期。 总体而言,也许“结果到文本”的性能会更高。 隐藏该窗格将节省 Mgmt Studio 上绘制数据的周期。 它仍然被返回到 Mgmt Studio,所以它确实没有节省很多周期。
I'd think that the where clause of
WHERE 1=0
is definitely happening on the SQL Server side, and not Management Studio. No results would be returned.Is you DB engine on the same machine that you're running the Mgmt Studio on?
You could :
That'd just move the cycles spent on drawing the grid in Mgmt Studio. Perhaps the Resuls to Text would be more performant on the whole. Hiding the pane would save the cycles on Mgmt Studio on having to draw the data. It's still being returned to the Mgmt Studio, so it really isn't saving a lot of cycles.
如果不输出结果,如何测试查询的性能? 如果测试没有告诉您有关查询将如何执行的任何信息,那么加速测试就没有意义。 你真的想知道这个查询在将其推送到产品后需要十分钟才能返回数据吗?
当然,返回 600,000 条记录需要一些时间。 它也会出现在您的用户界面中,它可能会比查询窗口中花费更长的时间,因为信息必须通过网络传输。
How can you test performance of your query if you don't output the results? Speeding up the testing is pointless if the testing doesn't tell you anything about how the query is going to perform. Do you really want to find out this dog of a query takes ten minutes to return data after you push it to prod?
And of course its going to take some time to return 600,000 records. It will in your user interface as well, it will probably take longer than in your query window because the info has to go across the network.