Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Execution Plans

Similar presentations


Presentation on theme: "Introduction to Execution Plans"— Presentation transcript:

1 Introduction to Execution Plans
Lance Tidwell

2 Lance Tidwell DBA, TicketCity
@Lance_LT .

3 What is an Execution Plan?
It is a map of the tables, indexes, and operations that SQL will use to execute the query.

4 How is the Execution Plan Created?
Query Optimizer: Builds the best plan it can based on the stats of the tables being used in the query.

5 How is the Execution Plan Created?
Query Optimizer: Builds the best plan it can based on the stats of the tables being used in the query.

6 How is the Execution Plan Created?
Query Optimizer: Builds the best plan it can based on the stats of the tables being used in the query.

7 How is the Execution Plan Created?
Query Optimizer: Builds the best plan it can based on the stats of the tables being used in the query.

8 How is the Execution Plan Created?
Query Optimizer: Builds the best plan it can based on the stats of the tables being used in the query.

9 When are Plans Removed from Plan Cache?
Changing structure or schema of a table being used in the plan. Updating stats that are used in the plan. Dropping/ changing index being used in plan. Plan is “aged” out of cache.

10 Common Operators Index Scan : Scans thru all the entire index touching every single page. Index Seek : Only touches the qualifying row and pages that contain those rows Table Scan : Scan entire table. Also means that you don’t have a clustered index on table Key Lookup : Retrieves info from the clustered index that is not in the non-clustered index. Which means you have non-covering index.

11 Common Operators (Join Types)
Nested Loops : Performs a search on the inner table for each row of the outer table (Cursor). Good for small amount of data. Merge Join : Requires both inputs to be sorted on join keys. Usually very fast. Can be a issue if additional sort operators are required. Hash Match : Uses a hash function to make a hash table of top set of data and then go thru bottom set using same hash function to probe hash table. Used for large set of data or when there aren’t good enough indexes in place to do one of the other joins.

12 Types of Execution Plans
Estimated Execution Plan : Is the plan the optimizer generated without any actual execution data just estimations Actual Execution Plan : Is the similar to the estimate plan excepts has some actual execution data to help you see how well the plan is performing for real data Live Query Stats ( SQL Server 2014 and above): Will show you the estimate plan with live stats as it executes. Great for visualizing and seeing the bottlenecks in longer running procs.

13 DEMO

14 Parameter Sniffing When a stored procedure is run for the first time the values of the parameters sent in are used to make the best plan for those specific values and that plan is used for subsequent calls to the procedure until that plan is removed from the plan cache. This is a great thing that is helps our your performance (most of the time).

15 Plan Warnings Implicit Conversion : When SQL has to convert your data type because they mismatch. Can cause scans to occur instead of seeks TempDB Spill : When the memory grant for a sort is bigger than expected it has to move the sort to disk in TempDB

16 DEMO

17 Cardinality Estimator
The Cardinality Estimator is what is used to look at the stats of the table and come up with the estimated number of rows for the execution plans. In SQL 2014 this got it first major upgrade since SQL 7.0. Trace Flag 9481 will disable the new Cardinality Estimator. Trace Flag 2312 will enable the new Cardinality Estimator on SQL 2012 and above. 2/ eats-bad-tsql-breakfast/

18 DEMO

19 SQL Server 2017 Adaptive Query Processing Adaptive Joins
Automatic Tuning

20 Thank You!!! silentdba@gmail.com @Lance _LT
Parameter Sniffing the Good and the Bad 20 |


Download ppt "Introduction to Execution Plans"

Similar presentations


Ads by Google