如何调整查询
我有一个运行缓慢的查询。我知道通常要提高性能,限制连接,并尝试使用过程而不是直接查询。由于业务规则,我无法使用 procs。我已经尽可能减少了连接数量。
查询调优的下一步是什么?
I have a query that is running slowly. I know generally to make performance faster, limit joins, and try to use procs instead of straight queries. Due to business rules, I cannot use procs. I've already cut the number of joins as much as I can think of.
What's the next step in query tuning?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加索引可能是提高查询性能可以做的第一件事,但您没有提到它。
您是否查看过执行计划,看看是否可以通过附加索引来改进?
此外,您应该确保您的查询以这样的方式编写,以便它们可以使用有效存在的任何索引(例如,避免不可控制的构造,避免
*
)Adding indexes is probably the number one thing you can do to improve query performance and you haven't mentioned it.
Have you looked at the execution plan to see whether that could be improved with additional indexes?
Additionally you should make sure that your queries are written in such a way so they can use any indexes that are present effectively (e.g. avoid non sargable constructs, avoid
*
)最简单的方法是转到管理工作室运行此命令:
然后运行实际查询。
您将不会获得常规查询结果集。它将在结果集中为您提供执行计划(SQL Server 执行查询操作的非常详细的列表)。查看输出并尝试了解它的含义。我通常寻找“SCAN”,这是一个缓慢的部分,我尝试重写它,以便它使用索引。
the easiest thing to do is go to management studio run this command:
then run your actual query.
You will not get your regular query result set. It will give you the execution plan (a very detailed list of what SQL Server does to turn your query) in a result set. Look over the output and try to learn what it means. I generally look for "SCAN", that is a slow part, and I try rewriting it so it uses an index.