简体   繁体   English

提高SQL Server查询性能

[英]Improve SQL Server query performance

I would like to know if there is any tool which will give me the optimized SQL query for which ever query I specify. 我想知道是否有工具可以为我指定的查询提供优化的SQL查询。 So that I can improve my DB as well as query performance. 这样我就可以改善数据库以及查询性能。 I use SQL Server 2008. 我使用SQL Server 2008。

Thanks in advance. 提前致谢。

The old Rule of DBs still applies, don't try to optimize sql statements, since the DB query parser will do its own optimizations anyway, instead do right away what we all do in the end: 旧的数据库规则仍然适用,不要尝试优化sql语句,因为数据库查询解析器无论如何都会做自己的优化,而是立即做我们最后要做的事情:

Create indexes to increase performance 创建索引以提高性能

Don't get me wrong of course sql queries can be written stupidly and will therefore perform badly, but as long as you created a sensable 'normal' query, the query optimizer will do the rest together with the indexes. 别误会,当然sql查询可能很笨拙,因此性能很差,但是只要您创建了一个明智的“正常”查询,查询优化器就会与索引一起完成其余的工作。

SQL Server will even tell you if a query will clearly benefit from an index when you look at the execution plan. 当您查看执行计划时,SQL Server甚至会告诉您查询是否将从索引中明显受益。 It will even generate the DDL statement to create the index, so all you have to do is copy/paste and run it to have the index your query needs. 它甚至会生成DDL语句来创建索引,因此您要做的就是复制/粘贴并运行它以获取查询所需的索引。

您已经可以看到为您提供SQL Server Management Studio的执行计划。

您可以尝试Redgate,他们的大多数产品都有评估版: Redgate网站

SQL Server 2005 and up comes with a Query Optimizer. SQL Server 2005及更高版本带有查询优化器。 This can help, but tools can't really do too much optimization suggesting for you because they don't know what you are trying to accomplish. 这可以提供帮助,但工具实际上并不能为您提供太多优化建议,因为它们不知道您要完成什么。

You might try taking a look instead at some ways in which you can optimize your queries. 你可以尝试一些方法,使可以优化您的查询考虑看看吧。 Here are some links to get you started. 这里有一些链接可以帮助您入门。

Tips, Tricks, and Advice from the MS SQL Query Optimization Team MS SQL查询优化团队的提示,技巧和建议

SQL Server Rules for Optimizing Queries, best practices SQL Server优化查询规则,最佳做法

Statistics Used by the Query Optimizer in SQL Server 2008 SQL Server 2008中查询优化器使用的统计信息

SQL Server 7.0 / 2000 came with 'index tuning wizard' this functionality has been around for a long time. SQL Server 7.0 / 2000带有“索引调整向导”,此功能已经存在很长时间了。

I'd reccomend having a look at 'select * from sys.dm_db_missing_index_details' It tells you which indexes are 'missing', it's trivial to look in that table and then create indexes 我建议您看看“从sys.dm_db_missing_index_details中选择*”,它告诉您哪些索引“缺失”,在该表中查找然后创建索引很简单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM