开发者

How do I tune a query

I have a query that is running slowly. I know gen开发者_运维知识库erally 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?


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 *)


the easiest thing to do is go to management studio run this command:

SET SHOWPLAN_ALL ON

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜