Skip to content

shannonlowder.com

Menu
  • About
  • Biml Interrogator Demo
  • Latest Posts
Menu

SQL 202-Interpreting your Execution Plan

Posted on January 19, 2011February 9, 2011 by slowder

OK, I’ve explained how you can see the execution plan for your query (either the actual or the estimated).  So now you can see your plan…Now what?  What do you want to look for?  Here’s the plan for the query I was running when I started this post.  I was looking at the IO statistics for a server.

Thick Arrows

When you’re first getting started with execution plans, there’s only a couple of items you really need to worry with.  First up, look at the thickness of the arrows.  The thicker the line, the more rows are moving from one operation to the other.  In my case, you’ll notice all the arrows are quite thin.

If your query has some really thick arrows, roll your mouse over them, and get an idea of the number of rows you’re sending between those operators.  Could you reduce the number any?  If so, your query would run faster.

Often when I have really thick lines I’ll look for JOIN criteria that may be sending too many rows.  Sometimes I can use a different ON clause, and the number of rows will decrease.  Most of the time a change in my WHERE clause will do the trick.  Remember, your goal is to retrieve as few rows as possible to answer your question.

Hash Operations

In my case, I’m doing a Hash Match.

from sys.dm_io_virtual_file_stats(NULL, NULL) vfs
inner join sys.master_files mf
 on vfs.database_id = mf.database_id
 and vfs.file_id = mf.file_id

This usually will be a JOIN or a GROUP BY.  It’s telling you you’re either missing an index, or you don’t have an index that covers the JOIN or GROUP BY in your query.  Check the indexes you have defined, and see which is the case.

Sort

Sorts aren’t always bad.  If you have an index that covers them, then you won’t see a high cost associated with your sort.  This example shows the cost of my sort is only 1% of the overall cost.  If you see the sort is a high cost of your query, you’re probably missing an index.  Remember you can call ASC and DESC in your index.  When you have an appropriate index, sorts aren’t going to be a problem.

Large Execution Plans

If you’re having to scroll a lot to see your whole plan.  There’s probably a simpler way to do what you’re trying to do.  You may want to investigate a simpler query.

Table Scans

If you see a table scan, and the cost of the table scan is significant, you may want to consider a covering index.  Chances are you’re completely missing an index.  But if you do have an index, and you still see a table scan, check to make sure you have an index that covers both the JOIN, WHERE, GROUP BY, and ORDER BY clauses as well as the SELECT clause.  You might even want to consider a filtered index (it can save you some index maintenance costs)!

This should get you started in exploring your execution plans, but it’s by no means complete.  Grant Fritchey is just the first person that comes to mind when looking for more information on execution plans.  There are others who have materials on execution plans.  Seek it out!

Mastering your understanding of execution plans can really help when you’re trying to improve your queries.

If I can help you interpret your execution plans, let me know!  I’m always willing to help!

Technology Blogs - Blog Rankings

ES77E8HYEE8W

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • A New File Interrogator
  • Using Generative AI in Data Engineering
  • Getting started with Microsoft Fabric
  • Docker-based Spark
  • Network Infrastructure Updates

Recent Comments

  1. slowder on Data Engineering for Databricks
  2. Alex Ott on Data Engineering for Databricks

Archives

  • July 2023
  • June 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • October 2018
  • August 2018
  • May 2018
  • February 2018
  • January 2018
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • June 2017
  • March 2017
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • February 2013
  • January 2013
  • August 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • November 2004
  • September 2004
  • August 2004
  • July 2004
  • April 2004
  • March 2004
  • June 2002

Categories

  • Career Development
  • Data Engineering
  • Data Science
  • Infrastructure
  • Microsoft SQL
  • Modern Data Estate
  • Personal
  • Random Technology
  • uncategorized
© 2025 shannonlowder.com | Powered by Minimalist Blog WordPress Theme