How do you interpret a query's explain plan?

后端 未结 11 1711
鱼传尺愫
鱼传尺愫 2020-12-02 05:12

When attempting to understand how a SQL statement is executing, it is sometimes recommended to look at the explain plan. What is the process one should go through in interpr

11条回答
  •  无人及你
    2020-12-02 05:43

    I mainly look for index or table scans. This usually tells me I'm missing an index on an important column that's in the where statement or join statement.

    From http://www.sql-server-performance.com/tips/query_execution_plan_analysis_p1.aspx:

    If you see any of the following in an execution plan, you should consider them warning signs and investigate them for potential performance problems. Each of them are less than ideal from a performance perspective.

    * Index or table scans: May indicate a need for better or  additional indexes.
    * Bookmark Lookups: Consider changing the current clustered index,
      consider using a covering index, limit
      the number of columns in the SELECT
      statement.
    * Filter: Remove any functions in the WHERE clause, don't include wiews
      in your Transact-SQL code, may need
      additional indexes.
    * Sort: Does the data really need to be sorted? Can an index be used to
      avoid sorting? Can sorting be done at
      the client more efficiently? 
    

    It is not always possible to avoid these, but the more you can avoid them, the faster query performance will be.

提交回复
热议问题