简体   繁体   中英

Understanding execution plan in SQL Server

I need to understand how to read an execution plan, I was reading some documents but is not clear for me.

How can I tell if my query performs OK?

What does this mean:

This is an example of 1 of my query 1

  1. nested loops
  2. merge interval
  3. clustered index seek
  4. concatenation
  5. compute scalar
  6. sort

Quite frankly, this is down voted (see my comment). But, you will be wise to read Microsoft's Technet article on the cost-based optimizer, which covers what you are asking about.

I will say this, based on my experience, if the execution plan recommends an index then I suggest you seriously consider it as the performance gains usually materialize, even if the index makes little to no sense (ie, SQL Server is pretty good, but not perfect, at knowing what it wants). Now, if you add an index and the execution plan recommends another index, then you might want to consider looking at what columns you are returning; how you are joining; and/or your table design.

Ultimately, you are trying to get the execution plan to show clustered index seeks (best), then clustered index scans (OK), index seeks, index scans, and avoid table scans (ie, heap). This, of course, is my own opinion.

https://technet.microsoft.com/en-us/library/2007.11.sqlquery.aspx

Other light reading:

http://www.dbjournal.ro/archive/16/16_4.pdf

https://nirajrules.wordpress.com/2009/06/10/cost-based-optimization-cbo-vs-rule-based-optimization-rbo/

For a practitioners guide and discussion:

http://logicalread.com/sql-server-primary-key-vs-clustered-index-part-1-mb01/

http://logicalread.com/sql-server-primary-key-vs-clustered-index-part-2-mb01/

http://logicalread.com/sql-server-primary-key-vs-clustered-index-part-3-mb01/

Mark Homer has a great answer here:

https://meta.stackoverflow.com/questions/382341/how-to-include-an-sql-server-execution-plan-to-a-stack-overflow-question

The link to Brent Ozar's site can be extremely useful. When you grab the plan remember to SET STATISTIC XML ON before running and the same to OFF at the end of the query to get a more accurate plan.

Brent's site:

https://www.brentozar.com/pastetheplan/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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