有哪些工具可以测试SQL语句的性能?
在对性能永无休止的追求中(以及我自己的重击经历),我了解到一些可能会降低 SQL 语句性能的事情。
强迫性子查询障碍
进行疯狂的类型转换(并将它们嵌套到遗忘中)
Group By 对上述疯狂类型转换的聚合函数
其中 fldID(从我的 500 万记录表中选择所有内容)
我通常使用 MSSQL。有哪些工具可以用来测试SQL语句的性能?这些工具是内置的并且特定于每种类型的数据库服务器吗?或者有通用工具可用吗?
In the never-ending search for performance (and my own bludgeoning experience), I've learnt a few things that could drag down the performance of a SQL statement.
Obsessive Compulsive Subqueries Disorder
Doing crazy type conversions (and nest those into oblivion)
Group By on aggregate functions of said crazy type conversions
Where fldID in (select EVERYTHING from my 5mil record table)
I typically work with MSSQL. What tools are available to test the performance of a SQL statement? Are these tools built in and specific to each type of DB server? Or are there general tools available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
SQL Profiler(内置):使用 SQL Profiler 进行监控
SQL Benchmark Pro(商业)
SQL Server 2008 具有新的 数据收集器
SQL Server 2005(及以上版本)缺少索引动态管理视图 (DMV),该索引可能非常有用(但仅适用于计划缓存中当前的查询计划):关于缺失索引功能。
还有 SQL Server Database Engine Tuning Advisor,它可以完成合理的工作(只是不要执行它建议的一切!)
SQL Profiler (built-in): Monitoring with SQL Profiler
SQL Benchmark Pro (Commercial)
SQL Server 2008 has the new Data Collector
SQL Server 2005 (onwards) has a missing indexes Dynamic Management View (DMV) which can be quite useful (but only for query plans currently in the plan cache): About the Missing Indexes Feature.
There is also the SQL Server Database Engine Tuning Advisor which does a reasonable job (just don't implement everything it suggests!)
我主要只使用 Profiler 和执行计划查看器
I mostly just use Profiler and the execution plan viewer
执行计划是调试查询性能问题时首先要查看的内容之一。执行计划将告诉您查询的每个部分大致花费了多少时间,并且可用于快速识别是否缺少索引或具有昂贵的连接或循环。
Execution Plans are one of the first things to look at when debugging query performance problems. An execution plan will tell you how much time is roughly spent in each portion of your query, and can be used to quickly identify if you are missing indexes or have expensive joins or loops.
MSSQL 有一个数据库调优顾问,通常会根据调优期间运行的常见查询为表推荐索引,但它不会为您重写查询。
在我看来,经验和实验是编写良好 SQL 查询的最佳工具。
MSSQL has a database tuning advisor that will often recommend indexes for tables based upon common queries run during the tuning period, however it wo't rewrite a query for you.
In my opinion, experience and experimentation are the best tools for writing good SQL queries.
在mysql中(也可能在其他数据库中)你可以
EXPLAIN
您的查询,看看数据库服务器对此有何看法。这通常用于决定应创建哪些索引。而且这个是内置的,因此您无需安装其他软件即可使用它。In mysql (may be in other databases too) you can
EXPLAIN
your query to see what database server thinks about it. This usually used to deside which indexes should be created. And this one is build-in, so you can use it without installing additional software.Adam Machanic 有一个名为 SqlQueryStress 的简单工具,可能有用。它被设计用于“针对单个查询运行快速性能测试,以测试想法或验证更改”。
Adam Machanic has a simple tool called SqlQueryStress that might be of use. It is designed to be used to "run a quick performance test against a single query, in order to test ideas or validate changes".