喜欢的性能调整技巧 [英] Favourite performance tuning tricks
问题描述
当您有需要性能调整的查询或存储过程时,您首先要做的是什么?
When you have a query or stored procedure that needs performance tuning, what are some of the first things you try?
推荐答案
这是我总是给某人询问关于优化的事情的handy-dandy列表。
我们主要使用Sybase,但大多数建议将全面适用。
Here is the handy-dandy list of things I always give to someone asking me about optimisation.
We mainly use Sybase, but most of the advice will apply across the board.
例如,SQL Server附带了大量的性能监视/调整位,但如果你没有这样的东西(甚至你可以)那么我会考虑以下...
SQL Server, for example, comes with a host of performance monitoring / tuning bits, but if you don't have anything like that (and maybe even if you do) then I would consider the following...
99%的问题我看到的是由于加入。解决这个问题是做一半的连接(与一些表),并将结果缓存在临时表中。然后将剩下的查询加入该临时表。
99% of problems I have seen are caused by putting too many tables in a join. The fix for this is to do half the join (with some of the tables) and cache the results in a temporary table. Then do the rest of the query joining on that temporary table.
- 在基础表上运行UPDATE STATISTICS
- 许多系统将此作为计划的每周工作执行
- 考虑每天自动执行一次或每周执行一次。
- 确保数据库中没有其他进程正在运行
$ b- 特别是DBCC
- 如果两个表达式都是完全相同的数据类型,则连接将只使用索引
- 索引仅在索引上的第一个字段在查询中匹配
- 在适当的地方使用聚集索引吗?
- 范围数据
- value1和value2之间的WHERE字段
- Joins will only use index if both expressions are exactly the same data type
- Index will only be used if the first field(s) on the index are matched in the query
- Are clustered indices used where appropriate?
- range data
- WHERE field between value1 and value2
- 一次只考虑表4。
- 这意味着在加入超过4个表格时,很有可能选择非最佳查询计划
- 你能分解加入吗?
- 预先将外键选择到临时表中
- 执行一半的连接并将结果放入临时表中
-
#temp
表的性能可能优于@table
大容量的变量(数千行)。
#temp
tables may perform much better than@table
variables with large volumes (thousands of rows).
-
- 建立每日/每小时等等
- 重建
- 将存储过程分成2
- 从proc1调用proc2
-
- 允许优化程序在proc2中选择索引if @parameter已被proc1更改
这篇关于喜欢的性能调整技巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!